Skip to content

Commit

Permalink
sorcery suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
aaravm committed Aug 12, 2024
1 parent 768b4cf commit 786a855
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ use std::io::Read;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
run_cli(Command::new("cli")).await
}
async fn run_cli(cmd: Command<'_>) -> Result<(), Box<dyn Error>> {
let cmd = cmd
let cmd = Command::new("cli")
.bin_name("cli")
.version("1.0")
.about("CLI to manage tasks")
Expand Down Expand Up @@ -125,7 +122,8 @@ async fn run_cli(cmd: Command<'_>) -> Result<(), Box<dyn Error>> {
task_file.to_string()
},
};
let testask: TesTask = serde_json::from_str(&task_json).expect("JSON was not well-formatted");
let testask: TesTask = serde_json::from_str(&task_json)
.map_err(|e| format!("Failed to parse JSON: {}", e))?;
let mut config = load_configuration();
if config.base_path == "localhost" {
let funnel_url = ensure_funnel_running().await;
Expand All @@ -146,23 +144,24 @@ async fn run_cli(cmd: Command<'_>) -> Result<(), Box<dyn Error>> {
let params = sub.value_of("params").unwrap().to_string();

// Split the params string into key-value pairs and collect into a HashMap for easier access
let params_map: HashMap<&str, &str> = params.split(',')
let params_map: HashMap<String, String> = params
.split(',')
.filter_map(|s| {
let mut parts = s.trim().splitn(2, ':');
parts.next().and_then(|key| parts.next().map(|value| (key.trim(), value.trim())))
Some((parts.next()?.to_string(), parts.next()?.to_string()))
})
.collect();
println!("parameters are: {:?}",params_map);

// Now, construct ListTasksParams from the parsed values
let parameters = ListTasksParams {
name_prefix: params_map.get("name_prefix").and_then(|&s| if s == "None" { None } else { Some(s.to_string()) }),
state: params_map.get("state").and_then(|&s| if s == "None" { None } else { Some(serde_json::from_str(s).expect("Invalid state")) }),
name_prefix: params_map.get("name_prefix").and_then(|s| if s == "None" { None } else { Some(s.to_string()) }),
state: params_map.get("state").and_then(|s| if s == "None" { None } else { Some(serde_json::from_str(s).expect("Invalid state")) }),
tag_key: None, // Example does not cover parsing Vec<String>
tag_value: None, // Example does not cover parsing Vec<String>
page_size: params_map.get("page_size").and_then(|&s| if s == "None" { None } else { Some(s.parse().expect("Invalid page_size")) }),
page_token: params_map.get("page_token").and_then(|&s| if s == "None" { None } else { Some(s.to_string()) }),
view: params_map.get("view").and_then(|&s| if s == "None" { None } else { Some(s.to_string()) }),
page_size: params_map.get("page_size").and_then(|s| if s == "None" { None } else { Some(s.parse().expect("Invalid page_size")) }),
page_token: params_map.get("page_token").and_then(|s| if s == "None" { None } else { Some(s.to_string()) }),
view: params_map.get("view").and_then(|s| if s == "None" { None } else { Some(s.to_string()) }),
};
println!("parameters are: {:?}",parameters);
let mut config = load_configuration();
Expand Down Expand Up @@ -244,7 +243,10 @@ async fn run_cli(cmd: Command<'_>) -> Result<(), Box<dyn Error>> {
}
}

_ => {println!("TODO");}
_ => {
eprintln!("Error: Unrecognized command or option");
std::process::exit(1);
}
}
Ok(())
}
Expand Down

0 comments on commit 786a855

Please sign in to comment.