Skip to content

Commit 13b9434

Browse files
committed
feat(coco): support for init subcommand
1 parent be6f143 commit 13b9434

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/bin/coco.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use std::env;
1+
use std::fs::OpenOptions;
2+
use std::{env, io::Write};
23

34
use clap::{App, Arg};
45

@@ -22,8 +23,28 @@ fn main() {
2223
.help("config file")
2324
.takes_value(true),
2425
)
26+
.subcommand(
27+
App::new("init")
28+
.version(VERSION)
29+
.author("Inherd Group")
30+
.about("A DevOps Efficiency Analysis and Auto-suggestion Tool."),
31+
)
2532
.get_matches();
2633

34+
if matches.is_present("init") {
35+
println!("creating coco.yml");
36+
match OpenOptions::new()
37+
.write(true)
38+
.create_new(true)
39+
.open("coco.yml")
40+
.map(|mut file| file.write(&serde_yaml::to_vec(&CocoConfig::default()).unwrap()))
41+
{
42+
Ok(_) => println!("success created"),
43+
Err(_) => println!("coco.yml already exists"),
44+
}
45+
std::process::exit(0);
46+
}
47+
2748
let config_file = matches.value_of("config").unwrap_or("coco.yml");
2849

2950
let cli_option = CocoCliOption::default();

0 commit comments

Comments
 (0)