changed init api
This commit is contained in:
parent
cb9a9a6316
commit
5ac086b67b
2 changed files with 25 additions and 18 deletions
|
@ -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<String>,
|
||||
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<Self> {
|
||||
|
@ -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))
|
||||
|
|
20
src/main.rs
20
src/main.rs
|
@ -36,7 +36,7 @@ pub enum Commands {
|
|||
files: Vec<String>,
|
||||
},
|
||||
|
||||
/// 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<String>,
|
||||
},
|
||||
|
||||
/// 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<Vec<String>>,
|
||||
|
@ -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<String> {
|
|||
"-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!();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue