Skip to content

Commit de22ab3

Browse files
authored
Merge pull request #136 from auths-dev/dev-initCleanupRegistryOutput
refactor: clean registry print statements from init
2 parents 5771311 + 4fbbf97 commit de22ab3

3 files changed

Lines changed: 42 additions & 27 deletions

File tree

crates/auths-cli/src/commands/init/display.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,25 @@ pub(crate) fn display_developer_result(
88
registered: Option<&str>,
99
) {
1010
out.newline();
11-
out.print_heading("You are on the Web of Trust!");
11+
if registered.is_some() {
12+
out.print_heading("You are on the Web of Trust!");
13+
} else {
14+
out.print_heading("Your identity is ready!");
15+
}
1216
out.newline();
1317
out.println(&format!(" Identity: {}", out.info(&result.identity_did)));
1418
out.println(&format!(" Key alias: {}", out.info(&result.key_alias)));
1519
if let Some(registry) = registered {
1620
out.println(&format!(" Registry: {}", out.info(registry)));
21+
let did_prefix = result
22+
.identity_did
23+
.strip_prefix("did:keri:")
24+
.unwrap_or(&result.identity_did);
25+
out.println(&format!(
26+
" Profile: {}",
27+
out.info(&format!("https://auths.dev/registry/identity/{did_prefix}"))
28+
));
1729
}
18-
let did_prefix = result
19-
.identity_did
20-
.strip_prefix("did:keri:")
21-
.unwrap_or(&result.identity_did);
22-
out.println(&format!(
23-
" Profile: {}",
24-
out.info(&format!("https://auths.dev/registry/identity/{did_prefix}"))
25-
));
2630
out.newline();
2731
out.print_success("Your next commit will be signed with Auths!");
2832
out.println(" Run `auths status` to check your identity");

crates/auths-cli/src/commands/init/mod.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::config::CliConfig;
3030
use crate::factories::storage::build_auths_context;
3131
use crate::ux::format::Output;
3232

33-
use super::signers::{SignersSyncArgs, handle_sync};
33+
use super::signers::sync_signers;
3434
use display::{
3535
display_agent_dry_run, display_agent_result, display_ci_result, display_developer_result,
3636
};
@@ -278,10 +278,15 @@ fn run_developer_setup(
278278
{
279279
let root = PathBuf::from(String::from_utf8_lossy(&output.stdout).trim());
280280
let repo_signers = root.join(".auths").join("allowed_signers");
281-
let _ = handle_sync(&SignersSyncArgs {
282-
repo: "~/.auths".into(),
283-
output_file: Some(repo_signers),
284-
});
281+
if let Ok(auths_repo) = get_auths_repo_path()
282+
&& let Ok((path, report)) = sync_signers(&auths_repo, &repo_signers)
283+
{
284+
out.println(&format!(
285+
" Wrote {} allowed signer(s) to {}",
286+
report.added,
287+
path.display()
288+
));
289+
}
285290
}
286291

287292
// REGISTRATION & DISPLAY

crates/auths-cli/src/commands/signers.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use anyhow::{Context, Result};
44
use auths_sdk::workflows::allowed_signers::{
5-
AllowedSigners, AllowedSignersError, EmailAddress, SignerPrincipal, SignerSource,
5+
AllowedSigners, AllowedSignersError, EmailAddress, SignerPrincipal, SignerSource, SyncReport,
66
};
77
use auths_storage::git::RegistryAttestationStorage;
88
use auths_verifier::core::Ed25519PublicKey;
@@ -208,26 +208,32 @@ fn handle_remove(args: &SignersRemoveArgs) -> Result<()> {
208208
Ok(())
209209
}
210210

211+
/// Core sync logic — no printing. Reused by init and `auths signers sync`.
212+
pub(crate) fn sync_signers(
213+
repo: &std::path::Path,
214+
output_file: &std::path::Path,
215+
) -> Result<(PathBuf, SyncReport)> {
216+
let storage = RegistryAttestationStorage::new(repo);
217+
let mut signers = AllowedSigners::load(output_file, &FileAllowedSignersStore)
218+
.with_context(|| format!("Failed to load {}", output_file.display()))?;
219+
let report = signers
220+
.sync(&storage)
221+
.context("Failed to sync attestations")?;
222+
signers
223+
.save(&FileAllowedSignersStore)
224+
.with_context(|| format!("Failed to write {}", output_file.display()))?;
225+
Ok((output_file.to_path_buf(), report))
226+
}
227+
211228
pub(crate) fn handle_sync(args: &SignersSyncArgs) -> Result<()> {
212229
let repo_path = expand_tilde(&args.repo)?;
213-
let storage = RegistryAttestationStorage::new(&repo_path);
214-
215230
let path = if let Some(ref output) = args.output_file {
216231
expand_tilde(output).map_err(|e| anyhow::anyhow!("{}", e))?
217232
} else {
218233
resolve_signers_path()?
219234
};
220235

221-
let mut signers = AllowedSigners::load(&path, &FileAllowedSignersStore)
222-
.with_context(|| format!("Failed to load {}", path.display()))?;
223-
224-
let report = signers
225-
.sync(&storage)
226-
.context("Failed to sync attestations")?;
227-
228-
signers
229-
.save(&FileAllowedSignersStore)
230-
.with_context(|| format!("Failed to write {}", path.display()))?;
236+
let (path, report) = sync_signers(&repo_path, &path)?;
231237

232238
println!(
233239
"Synced: {} added, {} removed, {} manual preserved",

0 commit comments

Comments
 (0)