MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / run

Method run

atomic-cli/src/commands/vault/init.rs:27–59  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

25
26impl Command for Init {
27 fn run(&self) -> CliResult<()> {
28 let root = find_repository_root()?;
29 let mut repo = Repository::open(&root).map_err(|e| CliError::InvalidRepository {
30 reason: e.to_string(),
31 })?;
32
33 if repo.has_vault().unwrap_or(false) {
34 print_info("Vault is already initialized");
35 return Ok(());
36 }
37
38 repo.init_vault().map_err(CliError::Repository)?;
39 print_info(&format!(
40 "Initialized vault at {}",
41 repo.vault_dir().display()
42 ));
43
44 // Add all vault files to tracking
45 let vault_dir = repo.vault_dir();
46 if vault_dir.exists() {
47 add_vault_files_recursive(&repo, &vault_dir)?;
48 }
49
50 // Record vault files as their own change
51 let header = atomic_core::change::ChangeHeader::new("Initialize vault");
52 match repo.record(header, atomic_repository::RecordOptions::default()) {
53 Ok(_) => print_success("Recorded vault defaults"),
54 Err(atomic_repository::RecordError::NothingToRecord) => {}
55 Err(e) => log::warn!("Failed to record vault files: {}", e),
56 }
57
58 Ok(())
59 }
60}
61
62fn add_vault_files_recursive(repo: &Repository, dir: &std::path::Path) -> CliResult<()> {

Callers

nothing calls this directly

Calls 9

find_repository_rootFunction · 0.85
print_infoFunction · 0.85
print_successFunction · 0.85
vault_dirMethod · 0.80
has_vaultMethod · 0.45
init_vaultMethod · 0.45
existsMethod · 0.45
recordMethod · 0.45

Tested by

no test coverage detected