diff --git a/cli/src/output/mod.rs b/cli/src/output/mod.rs index 96daff6..c080a96 100644 --- a/cli/src/output/mod.rs +++ b/cli/src/output/mod.rs @@ -10,6 +10,7 @@ pub enum Format { JSON, TOML, CSV, + SSH, } impl Format { @@ -20,7 +21,8 @@ impl Format { writeln!(w, "") } Format::TOML => write!(w, "{}", toml::to_string_pretty(&output.keys).unwrap()), - Format::CSV => as_csv(w, &output), + Format::CSV => as_csv(w, output), + Format::SSH => authorized_keys(w, output), } } } @@ -31,6 +33,7 @@ impl std::fmt::Display for Format { Format::JSON => f.write_str("json"), Format::TOML => f.write_str("toml"), Format::CSV => f.write_str("csv"), + Format::SSH => f.write_str("ssh"), } } } @@ -41,6 +44,7 @@ impl<'a> From<&'a str> for Format { "json" => Format::JSON, "toml" => Format::TOML, "csv" => Format::CSV, + "ssh" => Format::SSH, _ => unreachable!(), } } @@ -61,3 +65,14 @@ fn as_csv(w: &mut W, output: &Output) -> io::Result<()> { Ok(()) } + +fn authorized_keys(w: &mut W, output: &Output) -> io::Result<()> { + for (name, keys) in &output.keys { + for key in keys { + let commented = ssh_key::PublicKey::new(key.key_data().clone(), name); + writeln!(w, "{}", commented.to_string())?; + } + } + + Ok(()) +} diff --git a/docs/fuk.1.scd b/docs/fuk.1.scd index d9998fb..c3958cd 100644 --- a/docs/fuk.1.scd +++ b/docs/fuk.1.scd @@ -8,7 +8,7 @@ fuk - Fetch User Keys *fuk* -h++ *fuk* --help++ -*fuk* [--format (json|toml|csv)] _config.toml_ +*fuk* [--format (json|toml|csv|ssh)] _config.toml_ # DESCRIPTION @@ -74,7 +74,7 @@ algorithm and key, but the comment *will* be ignored when comparing for equality. If comments for duplicated keys are different, then there is no guarantee about comment content. -Possible formats - JSON, TOML, CSV. +Possible formats - JSON, TOML, CSV, SSH authorized_keys. Example output: