Skip to content

Commit

Permalink
feat: 'init' command generate configuration file
Browse files Browse the repository at this point in the history
  • Loading branch information
attakei committed Mar 8, 2024
1 parent 1df9012 commit 53fa698
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .gazer.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
current_version = "0.0.0"

[[files]]
path = "Cargo.toml"
search = "version = \"{current_version}\""
replace = "version = \"{new_version}\""
20 changes: 17 additions & 3 deletions src/commands/init.rs
Original file line number Diff line number Diff line change
@@ -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?
Expand All @@ -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(())
Expand Down

0 comments on commit 53fa698

Please sign in to comment.