From d1490adfd2822a7611af0957eb03879d7d0e245f Mon Sep 17 00:00:00 2001 From: Blinningjr <nicke.l@telia.com> Date: Sun, 3 Jan 2021 12:19:48 +0100 Subject: [PATCH] Implemented cli skeleton --- srp_analysis/Cargo.toml | 1 + srp_analysis/src/main.rs | 51 +++++++++++++++++++++++++++++++++------- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/srp_analysis/Cargo.toml b/srp_analysis/Cargo.toml index cb6789f..2ffa944 100644 --- a/srp_analysis/Cargo.toml +++ b/srp_analysis/Cargo.toml @@ -7,3 +7,4 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +structopt = { version = "0.3"} diff --git a/srp_analysis/src/main.rs b/srp_analysis/src/main.rs index fd2ddac..d303ec2 100644 --- a/srp_analysis/src/main.rs +++ b/srp_analysis/src/main.rs @@ -4,19 +4,54 @@ mod srp_analyser; use common::*; use srp_analyser::*; +use std::path::PathBuf; +use structopt::StructOpt; + + +#[derive(Debug, StructOpt)] +#[structopt(name = "srp_analysis", about = "Preforms srp analysis.")] +struct Opt { + /// Approximate preemptions + #[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>, +} -fn main() { - let tasks: Tasks = create_tasks(); - println!("tasks {:?}", &tasks); - println!("tot_util {}", total_load_factor(&tasks)); +fn main() { + let opt = Opt::from_args(); + println!("{:?}", opt); + + let tasks: Tasks = match opt.input { + Some(_file) => create_tasks(), // TODO: Implement so that the tasks can be read from file. + None => create_tasks(), + }; + let (ip, tr) = pre_analysis(&tasks); - println!("ip: {:?}", ip); - println!("tr: {:?}", tr); + let analysis = analyse(&tasks, &ip, &tr, opt.approx); + + match opt.output { + Some(_file) => (), // TODO: Implement so that the analysis can be saved to file. + None => { + println!("tasks {:?}", &tasks); + println!("tot_util {}", total_load_factor(&tasks)); + + println!("ip: {:?}", ip); + println!("tr: {:?}", tr); - let analysis = analyse(&tasks, &ip, &tr, true); - println!("Analysis {:#?}", analysis); + println!("Analysis {:#?}", analysis); + + // TODO: Implement a nicer print out to stdout. + }, + }; } -- GitLab