Skip to content

Commit 8f6a924

Browse files
author
LorenzoTettamanti
committed
[Code refactoring]: Updated return type for arg_parser function (prev: Result<(),Error> now: ())
1 parent 3d99b3f commit 8f6a924

1 file changed

Lines changed: 6 additions & 25 deletions

File tree

cli/src/main.rs

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::result::Result::Ok;
1616
use std::string;
1717
use tracing::debug;
1818

19-
use crate::essential::{get_config_directory, get_startup_config_dir, info, read_configs, update_cli};
19+
use crate::essential::{info, read_configs, update_cli};
2020
use crate::install::{InstallArgs, InstallCommands, install_cortexflow, install_simple_example};
2121
use crate::logs::{LogsArgs, logs_command};
2222
use crate::monitoring::{MonitorArgs, MonitorCommands, list_features, monitor_identity_events};
@@ -65,99 +65,83 @@ struct SetArgs {
6565
val: String,
6666
}
6767

68-
async fn args_parser() -> Result<(), Error> {
68+
async fn args_parser(){
6969
let args = Cli::parse();
7070
let env = "kubernetes".to_string();
7171
let general_data = GeneralData::new(env);
7272
debug!("Arguments {:?}", args.cmd);
7373
match args.cmd {
7474
Some(Commands::SetEnv(env)) => {
7575
general_data.set_env(env.val);
76-
Ok(())
7776
}
7877
Some(Commands::GetEnv) => {
7978
general_data.get_env_output();
80-
Ok(())
8179
}
8280
Some(Commands::Install(installation_args)) => match installation_args.install_cmd {
8381
InstallCommands::All => {
8482
install_cortexflow().await;
85-
Ok(())
8683
}
8784
InstallCommands::TestPods => {
8885
install_simple_example();
89-
Ok(())
9086
}
9187
},
9288
Some(Commands::Uninstall) => {
9389
uninstall();
94-
Ok(())
9590
}
9691
Some(Commands::Update) => {
9792
update_cli();
98-
Ok(())
9993
}
10094
Some(Commands::Info) => {
10195
info(general_data);
102-
Ok(())
10396
}
10497
Some(Commands::Service(service_args)) => match service_args.service_cmd {
10598
ServiceCommands::List { namespace } => {
10699
Some(list_services(namespace));
107-
Ok(())
108100
}
109101
ServiceCommands::Describe {
110102
service_name,
111103
namespace,
112104
} => {
113105
describe_service(service_name, &namespace);
114-
Ok(())
115106
}
116107
},
117108
Some(Commands::Status(status_args)) => {
118109
status_command(status_args.output, status_args.namespace);
119-
Ok(())
120110
}
121111
Some(Commands::Logs(logs_args)) => {
122112
logs_command(logs_args.service, logs_args.component, logs_args.namespace);
123-
Ok(())
124113
}
125114
Some(Commands::Monitor(monitor_args)) => match monitor_args.monitor_cmd {
126115
MonitorCommands::List => {
127116
let _ = list_features().await;
128-
Ok(())
129117
}
130118
MonitorCommands::Connections => {
131119
let _ = monitor_identity_events().await;
132-
Ok(())
133120
}
134121
},
135122
Some(Commands::Policies(policies_args)) => {
136123
match policies_args.policy_cmd {
137124
PoliciesCommands::CheckBlocklist => {
138125
let _ = check_blocklist().await;
139-
Ok(())
140126
}
141127
PoliciesCommands::CreateBlocklist => {
142128
// pass the ip as a monitoring flag
143129
match policies_args.flags {
144130
None => {
145131
println!("{}", "Insert at least one ip to create a blocklist".red());
146-
Ok(())
147132
}
148-
Some(exclude_flag) => {
149-
println!("inserted ip: {} ", exclude_flag);
133+
Some(ip) => {
134+
println!("inserted ip: {} ", ip);
150135
//insert the ip in the blocklist
151-
match create_blocklist(&exclude_flag).await {
136+
match create_blocklist(&ip).await {
152137
Ok(_) => {
153138
//update the config metadata
154-
let _ = update_config_metadata(&exclude_flag, "add").await;
139+
let _ = update_config_metadata(&ip, "add").await;
155140
}
156141
Err(e) => {
157142
println!("{}", e);
158143
}
159144
}
160-
Ok(())
161145
}
162146
}
163147
}
@@ -167,7 +151,6 @@ async fn args_parser() -> Result<(), Error> {
167151
"{}",
168152
"Insert at least one ip to remove from the blocklist".red()
169153
);
170-
Ok(())
171154
}
172155
Some(ip) => {
173156
println!("Inserted ip: {}", ip);
@@ -179,14 +162,12 @@ async fn args_parser() -> Result<(), Error> {
179162
println!("{}", e);
180163
}
181164
}
182-
Ok(())
183165
}
184166
},
185167
}
186168
}
187169
None => {
188170
eprintln!("CLI unknown argument. Cli arguments passed: {:?}", args.cmd);
189-
Ok(())
190171
}
191172
}
192173
}

0 commit comments

Comments
 (0)