|
| 1 | +// Copyright (C) 2022 Jingli Chen (Wine93), NetEase Inc. |
| 2 | + |
| 3 | +use structopt::{clap::AppSettings, StructOpt}; |
| 4 | +use crate::app::OBM; |
| 5 | +use crate::error::Result; |
| 6 | +use crate::command::list::{ListCmd, ListOptions}; |
| 7 | +use crate::command::run::{RunCmd, RunOptions}; |
| 8 | +use crate::command::enter::{EnterCmd, EnterOptions}; |
| 9 | +use crate::command::remove::{RemoveCmd, RemoveOptions}; |
| 10 | + |
| 11 | +#[derive(Debug, StructOpt)] |
| 12 | +#[structopt( |
| 13 | +name = "obm", |
| 14 | +about = "OpenCurve Project Build Manager", |
| 15 | +setting(AppSettings::ColoredHelp), |
| 16 | +setting(AppSettings::NextLineHelp), |
| 17 | +setting(AppSettings::UnifiedHelpMessage) |
| 18 | +)] |
| 19 | +pub(crate) enum Command { |
| 20 | + #[structopt(name = "run")] |
| 21 | + RunOptions(RunOptions), |
| 22 | + |
| 23 | + #[structopt(name = "ls")] |
| 24 | + ListOptions(ListOptions), |
| 25 | + |
| 26 | + #[structopt(name = "cd")] |
| 27 | + EnterOptions(EnterOptions), |
| 28 | + |
| 29 | + #[structopt(name = "rm")] |
| 30 | + RemoveOptions(RemoveOptions), |
| 31 | +} |
| 32 | + |
| 33 | +pub(crate) struct Cli { |
| 34 | + obm: OBM, |
| 35 | +} |
| 36 | + |
| 37 | +impl Cli { |
| 38 | + pub fn new(obm: OBM) -> Self { |
| 39 | + Self{ obm } |
| 40 | + } |
| 41 | + |
| 42 | + pub fn execute(self) -> Result<()> { |
| 43 | + let args = Command::from_args(); |
| 44 | + |
| 45 | + match args { |
| 46 | + Command::RunOptions(options) => { |
| 47 | + RunCmd::new(self.obm, options).run() |
| 48 | + }, |
| 49 | + Command::ListOptions(options) => { |
| 50 | + ListCmd::new(self.obm, options).run() |
| 51 | + }, |
| 52 | + Command::EnterOptions(options) => { |
| 53 | + EnterCmd::new(self.obm, options).run() |
| 54 | + }, |
| 55 | + Command::RemoveOptions(options) => { |
| 56 | + RemoveCmd::new(self.obm, options).run() |
| 57 | + }, |
| 58 | + _ => Ok(()), |
| 59 | + } |
| 60 | + } |
| 61 | +} |
0 commit comments