use std::{io::Write, path::Path};
use sokf_core::InitOptions;
use crate::{cli::InitArgs, output};
pub fn init(repo_root: Option<&Path>, args: InitArgs) -> sokf_core::Result<u8> {
let (cwd, root) = output::root(repo_root)?;
let opts = InitOptions {
dir: args.dir,
cwd,
name: args.name,
scope: args.scope,
description: args.description,
};
let result = sokf_core::init(&root, &opts)?;
let mut buf = Vec::new();
if args.json {
buf = output::json_line(&result)?;
} else {
for path in &result.created {
writeln!(buf, "created {path}").map_err(output::stdout_err)?;
}
for path in &result.updated {
writeln!(buf, "updated {path}").map_err(output::stdout_err)?;
}
}
output::write_stdout(&buf)?;
Ok(output::EXIT_OK)
}