-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmain.rs
More file actions
161 lines (150 loc) · 3.7 KB
/
main.rs
File metadata and controls
161 lines (150 loc) · 3.7 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
mod essential;
mod install;
mod general;
mod uninstall;
mod service;
mod status;
mod logs;
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, describe_service};
use crate::status::status_command;
use crate::logs::logs_command;
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),
#[command(name="status")]
Status(StatusArgs),
#[command(name="logs")]
Logs(LogsArgs),
}
#[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>,
},
#[command(name="describe")]
Describe {
service_name: String,
#[arg(long)]
namespace: Option<String>,
},
}
#[derive(Args, Debug, Clone)]
struct StatusArgs {
#[arg(long)]
output: Option<String>,
#[arg(long)]
namespace: Option<String>,
}
#[derive(Args, Debug, Clone)]
struct LogsArgs {
#[arg(long)]
service: Option<String>,
#[arg(long)]
component: Option<String>,
#[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(())
}
ServiceCommands::Describe { service_name, namespace } => {
describe_service(service_name, namespace);
Ok(())
}
}
}
Some(Commands::Status(status_args)) => {
status_command(status_args.output, status_args.namespace);
Ok(())
}
Some(Commands::Logs(logs_args)) => {
logs_command(logs_args.service, logs_args.component, logs_args.namespace);
Ok(())
}
None => {
eprintln!("CLI unknown argument. Cli arguments passed: {:?}", args.cmd);
Ok(())
}
}
}
fn main() {
let _ = args_parser();
}