Skip to content
Snippets Groups Projects
Commit 1237a5ca authored by Blinningjr's avatar Blinningjr
Browse files

Fixed the cli

parent 1ff58465
No related branches found
No related tags found
No related merge requests found
...@@ -18,13 +18,17 @@ struct Opt { ...@@ -18,13 +18,17 @@ struct Opt {
#[structopt(short, long)] #[structopt(short, long)]
approx: bool, approx: bool,
/// Input file, example input if not present /// Output in json format
#[structopt(parse(from_os_str))] #[structopt(short, long)]
input: Option<PathBuf>, json: bool,
/// Path to the input json file
#[structopt(short, long)]
in_file: Option<PathBuf>,
/// Output file, stdout if not present /// Path to the output file
#[structopt(parse(from_os_str))] #[structopt(short, long)]
output: Option<PathBuf>, out_file: Option<PathBuf>,
} }
...@@ -33,7 +37,7 @@ fn main() { ...@@ -33,7 +37,7 @@ fn main() {
let opt = Opt::from_args(); let opt = Opt::from_args();
//println!("{:?}", opt); //println!("{:?}", opt);
let tasks: Tasks = match opt.input { let tasks: Tasks = match opt.in_file {
Some(file) => load_tasks(file), Some(file) => load_tasks(file),
None => create_tasks(), None => create_tasks(),
}; };
...@@ -41,14 +45,29 @@ fn main() { ...@@ -41,14 +45,29 @@ fn main() {
let (ip, tr) = pre_analysis(&tasks); let (ip, tr) = pre_analysis(&tasks);
let analysis = analyse(&tasks, &ip, &tr, opt.approx); let analysis = analyse(&tasks, &ip, &tr, opt.approx);
match opt.output { let output: String = match opt.json {
true => serde_json::to_string(&analysis).unwrap(),
false => format_analysis(&analysis, &tasks, &ip, &tr),
};
match opt.out_file {
Some(file) => { Some(file) => {
write_to_file(serde_json::to_string(&analysis).unwrap(), file); match write_to_file(output, file) {
}, // TODO: Implement so that the analysis can be saved to txt. Ok(_) => (),
None => { Err(err) => panic!(err),
println!("{}", format_analysis(&analysis, &tasks, &ip, &tr)); };
}, },
None => println!("{}", output),
}; };
// match opt.output {
// Some(file) => {
// write_to_file(serde_json::to_string(&analysis).unwrap(), file);
// }, // TODO: Implement so that the analysis can be saved to txt.
// None => {
// println!("{}", format_analysis(&analysis, &tasks, &ip, &tr));
// },
// };
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment