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
use structopt::StructOpt;
use support_common::error::BridgerError;
use crate::command::types::Opt;
use crate::external::execute::ExternalExecutor;
mod cli;
mod command;
mod config;
mod external;
mod initialize;
fn main() -> color_eyre::Result<()> {
initialize::init()?;
let ret: Result<Opt, structopt::clap::Error> = Opt::from_args_safe();
match ret {
Ok(opt) => cli::execute(opt)?,
Err(e) => {
if structopt::clap::ErrorKind::UnknownArgument == e.kind {
let args_orig: Vec<String> = std::env::args().collect();
let sub_command = &args_orig[1..2][0];
let sub_args = &args_orig[2..];
tracing::debug!(
target: "bridger",
"Found subcommand ({}) and args: {}",
sub_command,
sub_args.join(" ")
);
let executor = ExternalExecutor::new(sub_command.clone(), sub_args.to_vec());
if let Err(ez) = executor.execute() {
if let Some(BridgerError::UnsupportExternal(_msg)) = ez.downcast_ref() {
e.exit();
}
return Err(ez);
}
return Ok(());
}
e.exit();
}
}
Ok(())
}