volo_cli/
model.rs

1use anyhow::Result;
2use clap::{ArgAction, Parser};
3use volo_build::model::DEFAULT_ENTRY_NAME;
4
5use crate::{
6    command::CliCommand, context::Context, http::Http, idl::Idl, init::Init, migrate::Migrate,
7    repo::Repo,
8};
9
10define_commands!(Subcommand {
11    Init,
12    Repo,
13    Idl,
14    Migrate,
15    Http
16});
17
18#[derive(Parser, Debug)]
19#[command(
20    name = "volo",
21    author,
22    version,
23    about,
24    rename_all = "kebab-case",
25    arg_required_else_help = true,
26    propagate_version = true
27)]
28pub struct RootCommand {
29    #[arg(
30        short = 'v',
31        long = "verbose",
32        help = "Turn on the verbose mode.",
33        global = true,
34        action = ArgAction::Count
35    )]
36    pub verbose: u8,
37
38    #[arg(
39        short = 'n',
40        long = "entry-name",
41        help = "The entry name, defaults to 'default'.",
42        default_value = DEFAULT_ENTRY_NAME
43    )]
44    pub entry_name: String,
45
46    #[command(subcommand)]
47    subcmd: Subcommand,
48}
49
50impl RootCommand {
51    pub fn run(self) -> Result<()> {
52        let cx = Context {
53            entry_name: self.entry_name.clone(),
54        };
55        self.subcmd.run(cx)
56    }
57}