From 5ac086b67b9d56d4fbf1fe42434168a46e9a9fb3 Mon Sep 17 00:00:00 2001 From: JOLIMAITRE Matthieu Date: Fri, 30 Sep 2022 00:16:11 +0200 Subject: [PATCH] changed init api --- src/config.rs | 23 +++++++++++------------ src/main.rs | 20 ++++++++++++++------ 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/config.rs b/src/config.rs index 6ce4396..7ac1deb 100644 --- a/src/config.rs +++ b/src/config.rs @@ -10,22 +10,22 @@ use crate::utils::{log_success, Apply}; #[derive(Debug, Serialize, Deserialize)] pub struct Config { - name: String, + identifier: String, main_file: String, test_file: String, includes: Vec, - fascist_mode: bool, + strict_mode: bool, } impl Config { const CONFIG_FILE_NAME: &'static str = "pi.ron"; - pub fn new(name: String) -> Self { + pub fn new(identifier: String) -> Self { Self { - name, + identifier, main_file: "main.c".into(), test_file: "test.c".into(), includes: vec![], - fascist_mode: false, + strict_mode: false, } } @@ -47,8 +47,8 @@ impl Config { Self::try_get(&path).or_else(|| path.parent().and_then(Self::get)) } - pub fn name(&self) -> &str { - &self.name + pub fn identifier(&self) -> &str { + &self.identifier } pub fn main_file(&self) -> &str { @@ -63,8 +63,8 @@ impl Config { &self.includes } - pub fn fascist_mode(&self) -> bool { - self.fascist_mode + pub fn strict_mode(&self) -> bool { + self.strict_mode } fn try_get(path: &Path) -> Option { @@ -75,13 +75,12 @@ impl Config { } } -pub fn create(path: String) { +pub fn create(path: String, identifier: String) { let absolute = fs::canonicalize(&path).unwrap(); if !absolute.is_dir() { panic!("not a directory"); } - let name = absolute.file_name().unwrap(); - let config = Config::new(name.to_str().unwrap().to_string()); + let config = Config::new(identifier); config.write(absolute.clone()); let path = absolute .apply(|p| p.push(Config::CONFIG_FILE_NAME)) diff --git a/src/main.rs b/src/main.rs index ec5f54b..b68e073 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,7 +36,7 @@ pub enum Commands { files: Vec, }, - /// Runs tests contained within a particular test file or the default test file + /// Runs tests contained within a particular test file or the default test file. test { /// Wether to capture standard output or not. #[clap(short, long)] @@ -50,7 +50,7 @@ pub enum Commands { tests: Vec, }, - /// Watches changes to the project included files and runs a command on changes + /// Watches changes to the project included files and runs a command on changes. watch { #[clap(short)] files: Option>, @@ -58,8 +58,14 @@ pub enum Commands { command: String, }, - /// Initializes a project directory configuration, useful for custom flags, includes and custop push messages - init { path: String }, + /// Initializes a project directory configuration, useful for custom flags, includes and custop push messages. + init { + /// Path to the folder containing the project. + path: String, + + /// Identifier for the automated tests. + identifier: String, + }, /// Pushes changes to the git server with a custom tag. push, @@ -80,7 +86,7 @@ fn compilation_args() -> Vec { "-Wextra".to_string(), "-std=c99".to_string(), ]; - if Config::get_current().fascist_mode() { + if Config::get_current().strict_mode() { args.push("-Werror".to_string()); } args @@ -122,7 +128,9 @@ fn main() { watch::main(files, command); } - Commands::init { path } => config::create(path), + Commands::init { path, identifier } => { + config::create(path, identifier); + } Commands::push => { todo!();