Skip to content

Commit

Permalink
Merge pull request #24 from davidkurilla/23-feat-add-project-manageme…
Browse files Browse the repository at this point in the history
…nt-features-to-citrus-core-library

[FEAT] Add `init` feature to 'citrus-cli'
  • Loading branch information
davidkurilla authored Jun 3, 2024
2 parents 95f4ab2 + 4cae1e5 commit 9e3d3a5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/citrus-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "citrus-cli"
version = "0.1.7"
version = "0.1.8"
edition.workspace = true
rust-version.workspace = true
license.workspace = true
Expand Down
7 changes: 7 additions & 0 deletions crates/citrus-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ fn main() {
.required(false)
.index(1))
)
.subcommand(
SubCommand::with_name("init")
.about("Initializes new citrus project")
)
.get_matches();

match matches.subcommand() {
Expand Down Expand Up @@ -85,6 +89,9 @@ fn main() {
let table_name = sub_m.value_of("table-name").unwrap();
citrus_migrations::run_migration("citrus-config.toml".into(), table_name.to_string());
}
Some("init") => {
citrus_core::init();
}
_ => {
println!("Welcome to citrus!");
}
Expand Down
2 changes: 1 addition & 1 deletion crates/citrus-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "citrus-core"
version = "0.1.0"
version = "0.1.1"
edition.workspace = true
rust-version.workspace = true
license.workspace = true
Expand Down
22 changes: 22 additions & 0 deletions crates/citrus-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,28 @@ fn get_config_file() -> Result<String, &'static str> {
}
}

// Init
pub fn init() {

let file_data = "[config]\n
task_directory = \".citrus\"";

let _config_file = match File::open("citrus-config.toml") {
Ok(_file) => {
println!("'citrus-config.toml' file found. Project already initialized.");
return;
}
Err(_) => {
let mut file = File::create("citrus-config.toml").expect("Cannot create 'citrus-config.toml'");
file.write_all(file_data.as_bytes()).expect("Cannot write to 'citrus-config.toml'");
let _dir = std::fs::create_dir(".citrus");
file
}
};

println!("Project successfully initialized!");
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 9e3d3a5

Please sign in to comment.