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)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
name: String,
|
identifier: String,
|
||||||
main_file: String,
|
main_file: String,
|
||||||
test_file: String,
|
test_file: String,
|
||||||
includes: Vec<String>,
|
includes: Vec<String>,
|
||||||
fascist_mode: bool,
|
strict_mode: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
const CONFIG_FILE_NAME: &'static str = "pi.ron";
|
const CONFIG_FILE_NAME: &'static str = "pi.ron";
|
||||||
pub fn new(name: String) -> Self {
|
pub fn new(identifier: String) -> Self {
|
||||||
Self {
|
Self {
|
||||||
name,
|
identifier,
|
||||||
main_file: "main.c".into(),
|
main_file: "main.c".into(),
|
||||||
test_file: "test.c".into(),
|
test_file: "test.c".into(),
|
||||||
includes: vec![],
|
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))
|
Self::try_get(&path).or_else(|| path.parent().and_then(Self::get))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name(&self) -> &str {
|
pub fn identifier(&self) -> &str {
|
||||||
&self.name
|
&self.identifier
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main_file(&self) -> &str {
|
pub fn main_file(&self) -> &str {
|
||||||
|
@ -63,8 +63,8 @@ impl Config {
|
||||||
&self.includes
|
&self.includes
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fascist_mode(&self) -> bool {
|
pub fn strict_mode(&self) -> bool {
|
||||||
self.fascist_mode
|
self.strict_mode
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_get(path: &Path) -> Option<Self> {
|
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();
|
let absolute = fs::canonicalize(&path).unwrap();
|
||||||
if !absolute.is_dir() {
|
if !absolute.is_dir() {
|
||||||
panic!("not a directory");
|
panic!("not a directory");
|
||||||
}
|
}
|
||||||
let name = absolute.file_name().unwrap();
|
let config = Config::new(identifier);
|
||||||
let config = Config::new(name.to_str().unwrap().to_string());
|
|
||||||
config.write(absolute.clone());
|
config.write(absolute.clone());
|
||||||
let path = absolute
|
let path = absolute
|
||||||
.apply(|p| p.push(Config::CONFIG_FILE_NAME))
|
.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>,
|
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 {
|
test {
|
||||||
/// Wether to capture standard output or not.
|
/// Wether to capture standard output or not.
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
|
@ -50,7 +50,7 @@ pub enum Commands {
|
||||||
tests: Vec<String>,
|
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 {
|
watch {
|
||||||
#[clap(short)]
|
#[clap(short)]
|
||||||
files: Option<Vec<String>>,
|
files: Option<Vec<String>>,
|
||||||
|
@ -58,8 +58,14 @@ pub enum Commands {
|
||||||
command: String,
|
command: String,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Initializes a project directory configuration, useful for custom flags, includes and custop push messages
|
/// Initializes a project directory configuration, useful for custom flags, includes and custop push messages.
|
||||||
init { path: String },
|
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.
|
/// Pushes changes to the git server with a custom tag.
|
||||||
push,
|
push,
|
||||||
|
@ -80,7 +86,7 @@ fn compilation_args() -> Vec<String> {
|
||||||
"-Wextra".to_string(),
|
"-Wextra".to_string(),
|
||||||
"-std=c99".to_string(),
|
"-std=c99".to_string(),
|
||||||
];
|
];
|
||||||
if Config::get_current().fascist_mode() {
|
if Config::get_current().strict_mode() {
|
||||||
args.push("-Werror".to_string());
|
args.push("-Werror".to_string());
|
||||||
}
|
}
|
||||||
args
|
args
|
||||||
|
@ -122,7 +128,9 @@ fn main() {
|
||||||
watch::main(files, command);
|
watch::main(files, command);
|
||||||
}
|
}
|
||||||
|
|
||||||
Commands::init { path } => config::create(path),
|
Commands::init { path, identifier } => {
|
||||||
|
config::create(path, identifier);
|
||||||
|
}
|
||||||
|
|
||||||
Commands::push => {
|
Commands::push => {
|
||||||
todo!();
|
todo!();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue