spalm/
cli.rs

1mod cmd_error;
2mod cmd_handler;
3mod cmd_result;
4mod commands;
5
6pub use self::cmd_error::*;
7pub use self::cmd_handler::*;
8pub use self::cmd_result::*;
9
10use std::path::PathBuf;
11use structopt::StructOpt;
12
13use crate::cli::commands::InitCommand;
14
15#[derive(StructOpt)]
16#[structopt(
17    name = "spalm",
18    version = "0.1.0",
19    about = "Specification Project of E5R Application Lifecycle Management"
20)]
21pub struct SpalmCli {
22    #[structopt(short, long, parse(from_os_str))]
23    pub path: Option<PathBuf>,
24
25    #[structopt(subcommand)]
26    pub cmd: SpalmCmd,
27}
28
29#[derive(StructOpt)]
30pub enum SpalmCmd {
31    Init {
32        #[structopt(short, long)]
33        with_git: bool,
34    },
35}
36
37impl SpalmCmd {
38    pub fn resolve(&self) -> Box<dyn CmdHandler> {
39        match self {
40            SpalmCmd::Init { with_git } => Box::new(InitCommand::new(*with_git)),
41        }
42    }
43}
44
45impl SpalmCli {
46    pub fn run(&self) -> CmdResult {
47        self.cmd.resolve().exec(match &self.path {
48            Some(p) => p.clone(),
49            None => PathBuf::from("."),
50        })
51    }
52}