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 {
#[structopt(short, long)]
approx: bool,
/// Input file, example input if not present
#[structopt(parse(from_os_str))]
input: Option<PathBuf>,
/// Output file, stdout if not present
#[structopt(parse(from_os_str))]
output: Option<PathBuf>,
/// Output in json format
#[structopt(short, long)]
json: bool,
/// Path to the input json file
#[structopt(short, long)]
in_file: Option<PathBuf>,
/// Path to the output file
#[structopt(short, long)]
out_file: Option<PathBuf>,
}
......@@ -33,7 +37,7 @@ fn main() {
let opt = Opt::from_args();
//println!("{:?}", opt);
let tasks: Tasks = match opt.input {
let tasks: Tasks = match opt.in_file {
Some(file) => load_tasks(file),
None => create_tasks(),
};
......@@ -41,14 +45,29 @@ fn main() {
let (ip, tr) = pre_analysis(&tasks);
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) => {
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));
match write_to_file(output, file) {
Ok(_) => (),
Err(err) => panic!(err),
};
},
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