diff --git a/.gazer.toml b/.gazer.toml new file mode 100644 index 0000000..0c2e59b --- /dev/null +++ b/.gazer.toml @@ -0,0 +1,6 @@ +current_version = "0.0.0" + +[[files]] +path = "Cargo.toml" +search = "version = \"{current_version}\"" +replace = "version = \"{new_version}\"" diff --git a/src/commands/init.rs b/src/commands/init.rs index c4908fc..9329b02 100644 --- a/src/commands/init.rs +++ b/src/commands/init.rs @@ -1,6 +1,16 @@ -use std::{env::current_dir, path::Path, result::Result}; +use std::{env::current_dir, fs::File, path::Path, result::Result}; + +use std::io::prelude::*; const DEFAULT_CONFIG_FILE: &'static str = ".gazer.toml"; +const DEFAULT_CONFIG_VALUE: &'static str = r#" +current_version = "0.0.0" + +[[files]] +path = "Cargo.toml" +search = "version = \"{current_version}\"" +replace = "version = \"{new_version}\"" +"#; pub fn run() -> Result<(), &'static str> { // TODO: Right way? @@ -11,13 +21,17 @@ pub fn run() -> Result<(), &'static str> { { // TODO: Right way? let target = target.as_os_str().to_str().expect("Failure"); - println!("{target}"); + println!("Config file is {target}"); } if target.exists() { - println!("Config file is already exists."); + println!("Already exists."); } else { + println!("Creating file."); // Generate config file. + let mut out = File::create(target).expect("File-creating is failed"); + let conf = DEFAULT_CONFIG_VALUE.as_bytes(); + let _ = out.write(conf); } Ok(())