Skip to content

Commit 1df9012

Browse files
committed
feat: Init 'init' command
- For creating configuration file (.gazer.toml)
1 parent d42e67c commit 1df9012

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

src/commands.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
pub mod init;
12
pub mod version;

src/commands/init.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use std::{env::current_dir, path::Path, result::Result};
2+
3+
const DEFAULT_CONFIG_FILE: &'static str = ".gazer.toml";
4+
5+
pub fn run() -> Result<(), &'static str> {
6+
// TODO: Right way?
7+
let target = current_dir()
8+
.expect("Failed current directory")
9+
.join(Path::new(DEFAULT_CONFIG_FILE));
10+
11+
{
12+
// TODO: Right way?
13+
let target = target.as_os_str().to_str().expect("Failure");
14+
println!("{target}");
15+
}
16+
17+
if target.exists() {
18+
println!("Config file is already exists.");
19+
} else {
20+
// Generate config file.
21+
}
22+
23+
Ok(())
24+
}

src/main.rs

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ struct Cli {
1515
enum Commands {
1616
/// Display version information
1717
Version {},
18+
/// Create configuration file.
19+
Init {},
1820
}
1921

2022
fn main() {
@@ -23,6 +25,9 @@ fn main() {
2325
Some(Commands::Version {}) => {
2426
commands::version::run();
2527
}
28+
Some(Commands::Init {}) => {
29+
commands::init::run().expect("Command is failed");
30+
}
2631
None => {}
2732
}
2833
}

0 commit comments

Comments
 (0)