From fc1f4e7f1b80b7da4ed9fb93cd65b0085fef7a68 Mon Sep 17 00:00:00 2001 From: Quinn Wilton Date: Tue, 12 Mar 2024 11:46:32 -0700 Subject: [PATCH] feat: log the creation of the key file in `init` --- homestar-runtime/src/cli/init.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/homestar-runtime/src/cli/init.rs b/homestar-runtime/src/cli/init.rs index 3a19672d..bd04f720 100644 --- a/homestar-runtime/src/cli/init.rs +++ b/homestar-runtime/src/cli/init.rs @@ -246,7 +246,7 @@ fn handle_key( key_type: KeyType, output_path: PathBuf, no_input: bool, - _writer: &mut Box, + writer: &mut Box, ) -> Result { let config = match key_arg { None => { @@ -289,7 +289,7 @@ fn handle_key( .map_err(|e| miette!(e))? .into(); - generate_key_file(&path, &key_type)?; + generate_key_file(&path, &key_type, writer)?; PubkeyConfig::Existing(ExistingKeyPath::new(key_type, path)) } @@ -304,7 +304,7 @@ fn handle_key( } }); - generate_key_file(&path, &key_type)?; + generate_key_file(&path, &key_type, writer)?; PubkeyConfig::Existing(ExistingKeyPath::new(key_type, path)) } @@ -329,7 +329,11 @@ fn handle_key( Ok(config) } -fn generate_key_file(path: &PathBuf, key_type: &KeyType) -> Result<()> { +fn generate_key_file( + path: &PathBuf, + key_type: &KeyType, + writer: &mut Box, +) -> Result<()> { if let Some(parent) = path.parent() { std::fs::create_dir_all(parent).expect("to create parent directory"); } @@ -354,9 +358,13 @@ fn generate_key_file(path: &PathBuf, key_type: &KeyType) -> Result<()> { file.write_all(key.as_bytes()) .expect("to write to key file"); + + writeln!(writer, "Writing key file to {:?}", path).expect("to write"); } // file did exist, do nothing and use existing key - Err(err) if err.kind() == std::io::ErrorKind::AlreadyExists => {} + Err(err) if err.kind() == std::io::ErrorKind::AlreadyExists => { + writeln!(writer, "Using existing key file {:?}", path).expect("to write"); + } err => { err.expect("to open key file"); }