img_tool/cmd/
cli.rs

1use clap::Parser;
2use enum_dispatch::enum_dispatch;
3
4use crate::config::CliConfig;
5
6use super::{Cvt, Completion};
7
8#[enum_dispatch(SubCommand)]
9pub trait Cmd {
10    fn apply(&self);
11    fn call(&self, config: &CliConfig);
12}
13
14#[derive(clap::Parser, Debug)]
15#[enum_dispatch]
16pub enum SubCommand {
17    /// cvt
18    // #[clap(name = "cvt", bin_name = "cvt")]
19    Cvt(Cvt),
20
21    // #[clap(name = "Completion", bin_name = "Completion")]
22    Completion(Completion),
23}
24
25/// A fast and simple Node.js manager.
26#[derive(clap::Parser, Debug)]
27#[clap(name = "rmo.exe", version = env!("CARGO_PKG_VERSION"), )]
28pub struct Cli {
29    #[clap(flatten)]
30    pub config: CliConfig,
31    #[clap(subcommand)]
32    pub subcmd: SubCommand,
33}
34
35pub fn start() {
36    let cli = Cli::parse();
37
38    // std::env::set_var("__RMO_CWD__", cli.config.cwd.clone());
39    let cmd: SubCommand = cli.subcmd;
40
41    cmd.call(&cli.config);
42}