1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use anyhow::Result;
use clap::{ArgAction, Parser};
use volo_build::model::DEFAULT_ENTRY_NAME;

use crate::{command::CliCommand, context::Context, idl::Idl, init::Init};

define_commands!(Subcommand { Init, Idl });

#[derive(Parser, Debug)]
#[command(
    name = "volo",
    author,
    version,
    about,
    rename_all = "kebab-case",
    arg_required_else_help = true,
    propagate_version = true
)]
pub struct RootCommand {
    #[arg(
        short = 'v',
        long = "verbose",
        help = "Turn on the verbose mode.",
        global = true,
        action = ArgAction::Count
    )]
    pub verbose: u8,

    #[arg(
        short = 'n',
        long = "entry-name",
        help = "The entry name, defaults to 'default'.",
        default_value = DEFAULT_ENTRY_NAME
    )]
    pub entry_name: String,

    #[command(subcommand)]
    subcmd: Subcommand,
}

impl RootCommand {
    pub fn run(self) -> Result<()> {
        let cx = Context {
            entry_name: self.entry_name.clone(),
        };
        self.subcmd.run(cx)
    }
}