From 30394ad79a26ca24d3a35240ba092edef4942e25 Mon Sep 17 00:00:00 2001 From: Akseli Lukkarila Date: Thu, 14 Nov 2024 23:51:37 +0200 Subject: [PATCH] fix long help output from docstrings --- rust/src/args.rs | 32 +++++++++++++++++++++++++------- rust/src/value.rs | 8 ++++---- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/rust/src/args.rs b/rust/src/args.rs index beea6b06..6ab615e3 100644 --- a/rust/src/args.rs +++ b/rust/src/args.rs @@ -186,7 +186,12 @@ enum Command { /// - `vault -i "vault-name"` /// - `vault --vault-stack "vault-name" --init"` /// - `VAULT_STACK="vault-name" vault i` - #[command(short_flag('i'), long_flag("init"), visible_alias("i"))] + #[command( + short_flag('i'), + long_flag("init"), + visible_alias("i"), + verbatim_doc_comment + )] Init { /// Vault stack name name: Option, @@ -195,19 +200,27 @@ enum Command { /// Update the vault CloudFormation stack. /// /// The CloudFormation stack declares all resources needed by the vault. + /// /// Usage examples: /// - `vault update` - /// - `vault update \"vault-name\"` - /// - `vault -u \"vault-name\"` - /// - `vault --vault-stack \"vault-name\" --update` - /// - `VAULT_STACK=\"vault-name\" vault u` - #[command(short_flag('u'), long_flag("update"), visible_alias("u"))] + /// - `vault update "vault-name"` + /// - `vault -u "vault-name"` + /// - `vault --vault-stack "vault-name" --update` + /// - `VAULT_STACK="vault-name" vault u` + #[command( + short_flag('u'), + long_flag("update"), + visible_alias("u"), + verbatim_doc_comment + )] Update { /// Optional vault stack name name: Option, }, /// Output secret value for given key + /// + /// Note that for binary secret data, the raw bytes will be outputted as is. #[command(short_flag('l'), long_flag("lookup"), visible_alias("l"))] Lookup { /// Key name to lookup @@ -229,7 +242,12 @@ enum Command { /// - Store from a file with filename as key: `vault store --file "path/to/file.txt"` /// - Store from stdin: `echo "some data" | vault store "key" --value -` /// - Store from stdin: `cat file.zip | vault store "key" --file -` - #[command(short_flag('s'), long_flag("store"), visible_alias("s"))] + #[command( + short_flag('s'), + long_flag("store"), + visible_alias("s"), + verbatim_doc_comment + )] Store { /// Key name to use for stored value key: Option, diff --git a/rust/src/value.rs b/rust/src/value.rs index 66d0169e..706200be 100644 --- a/rust/src/value.rs +++ b/rust/src/value.rs @@ -1,6 +1,6 @@ +use std::fmt; use std::io::{stdin, BufWriter, Read, Write}; use std::path::Path; -use std::{fmt, io}; use base64::Engine; @@ -109,7 +109,7 @@ impl Value { /// /// String data is printed. /// Binary data is outputted raw. - pub fn output_to_stdout(&self) -> io::Result<()> { + pub fn output_to_stdout(&self) -> std::io::Result<()> { match self { Self::Utf8(ref string) => { print!("{string}"); @@ -117,7 +117,7 @@ impl Value { Ok(()) } Self::Binary(ref bytes) => { - let stdout = io::stdout(); + let stdout = std::io::stdout(); let mut handle = stdout.lock(); handle.write_all(bytes)?; handle.flush() @@ -126,7 +126,7 @@ impl Value { } /// Outputs the data to the specified file path. - pub fn output_to_file(&self, path: &Path) -> io::Result<()> { + pub fn output_to_file(&self, path: &Path) -> std::io::Result<()> { let file = std::fs::File::create(path)?; let mut writer = BufWriter::new(file); writer.write_all(self.as_bytes())?;