-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmain.rs
More file actions
117 lines (108 loc) · 2.54 KB
/
main.rs
File metadata and controls
117 lines (108 loc) · 2.54 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
mod essential;
mod install;
mod general;
mod uninstall;
mod service;
use clap::{ Error, Parser, Subcommand, Args };
use clap::command;
use tracing::debug;
use crate::essential::{ info, update_cli };
use crate::install::install_cortexflow;
use crate::uninstall::uninstall;
use crate::service::list_services;
use crate::general::GeneralData;
#[derive(Parser, Debug)]
#[command(
author = GeneralData::AUTHOR,
version = GeneralData::VERSION,
about = None,
long_about = None
)]
struct Cli {
//name: String,
#[clap(subcommand)]
cmd: Option<Commands>,
env: String,
}
#[derive(Subcommand, Debug, Clone)]
enum Commands {
/* list of available commands */
#[command(name="set-env")]
SetEnv(SetArgs),
#[command(name="get-env")]
GetEnv,
#[command(name="install")]
Install,
#[command(name="uninstall")]
Uninstall,
#[command(name="update")]
Update,
#[command(name="info")]
Info,
#[command(name="service")]
Service(ServiceArgs),
}
#[derive(Args, Debug, Clone)]
struct SetArgs {
val: String,
}
#[derive(Args, Debug, Clone)]
struct ServiceArgs {
#[command(subcommand)]
service_cmd: ServiceCommands,
}
#[derive(Subcommand, Debug, Clone)]
enum ServiceCommands {
#[command(name="list")]
List {
#[arg(long)]
namespace: Option<String>,
},
}
fn args_parser() -> Result<(), Error> {
let args = Cli::parse();
let env = args.env;
let general_data = GeneralData::new(env);
debug!("Arguments {:?}", args.cmd);
match args.cmd {
Some(Commands::SetEnv(env)) => {
general_data.set_env(env.val);
Ok(())
}
Some(Commands::GetEnv) => {
general_data.get_env_output();
Ok(())
}
Some(Commands::Install) => {
install_cortexflow();
Ok(())
}
Some(Commands::Uninstall)=>{
uninstall();
Ok(())
}
Some(Commands::Update) => {
update_cli();
Ok(())
}
Some(Commands::Info) => {
info(general_data);
Ok(())
}
Some(Commands::Service(service_args)) => {
match service_args.service_cmd {
ServiceCommands::List { namespace } => {
list_services(namespace);
Ok(())
}
}
}
None => {
eprintln!("CLI unknown argument. Cli arguments passed: {:?}", args.cmd);
Ok(())
}
}
}
fn main() {
let _ = args_parser();
}