1use anyhow::*;
2use std::io::Write;
3use std::{env, path};
4
5use crate::{config, repo};
6
7pub fn init<W: Write>(
8 config_path: &path::Path,
9 umbrella: &repo::Repo,
10 stdout: &mut W,
11) -> Result<()> {
12 let mut wok_config: config::Config = Default::default();
13
14 for repo in umbrella.subrepos.iter() {
15 let repo_path = repo.work_dir.strip_prefix(&umbrella.work_dir)?;
16
17 wok_config.add_repo(repo_path, &repo.head);
18 }
19
20 wok_config.save(config_path)?;
21 writeln!(
22 stdout,
23 "Created config at `{}`",
24 config_path
25 .strip_prefix(env::current_dir()?)
26 .unwrap_or(config_path)
27 .display()
28 )?;
29 Ok(())
30}