From e6610de9b6ec591d6ba70e9c427a5c916651f058 Mon Sep 17 00:00:00 2001 From: Ayrton Chilibeck Date: Fri, 12 Jan 2024 22:16:50 -0700 Subject: [PATCH] Added the thread option for the cli --- src/grade.rs | 2 +- src/main.rs | 19 ++++++++++++++++--- src/run.rs | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/grade.rs b/src/grade.rs index c8c7f39..d035277 100644 --- a/src/grade.rs +++ b/src/grade.rs @@ -2,6 +2,6 @@ use std::path::Path; use crate::util; -pub fn grade(verbosity: u8, config: util::config::Config, grade_config: Option<&Path>) { +pub fn grade(verbosity: u8, config: util::config::Config, grade_config: Option<&Path>, threads: u8) { println!("Grading!"); } diff --git a/src/main.rs b/src/main.rs index 8ec0d7b..d3e298f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,6 +13,7 @@ fn main() { // parse the verbosity and eliminate the Option<> let verbosity = get_verbosity(cli.verbosity); + let threads = get_threads(cli.threads); let config = util::config::parse_config(cli.config_file); //parse the config file @@ -20,8 +21,8 @@ fn main() { match &cli.command { Command::Validate => validate::validate(verbosity, config), - Command::Run => run::run(verbosity, config), - Command::Grade => grade::grade(verbosity, config, cli.grading_conf.as_deref()), + Command::Run => run::run(verbosity, config, threads), + Command::Grade => grade::grade(verbosity, config, cli.grading_conf.as_deref(), threads), } } @@ -33,7 +34,9 @@ struct Cli { #[arg(short, long, action = clap::ArgAction::Count)] verbosity: Option, - //TODO implement a thread count variable for the runner + /// Set the number of threads (only valid in run and grade mode) + #[arg(short, long)] + threads: Option, /// Set the config file #[arg(short, long, value_name = "CONFIG")] @@ -76,3 +79,13 @@ fn get_verbosity(verb: Option) -> u8 { return verbosity; } + +fn get_threads(threads: Option) -> u8 { + let thr: u8; + match threads { + Some(x) => thr = x, + None => thr = 1, + } + + return thr; +} diff --git a/src/run.rs b/src/run.rs index a2d7891..863ba14 100644 --- a/src/run.rs +++ b/src/run.rs @@ -1,6 +1,6 @@ use crate::util; -pub fn run(verbosity: u8, config: util::config::Config) { +pub fn run(verbosity: u8, config: util::config::Config, threads: u8) { println!("Running!"); } -- 2.40.1