Skip to content

Commit

Permalink
fix long help output from docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
Esgrove committed Nov 14, 2024
1 parent 1a6d75d commit 30394ad
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
32 changes: 25 additions & 7 deletions rust/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
Expand All @@ -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<String>,
},

/// 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
Expand All @@ -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<String>,
Expand Down
8 changes: 4 additions & 4 deletions rust/src/value.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -109,15 +109,15 @@ 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}");
std::io::stdout().flush()?;
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()
Expand All @@ -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())?;
Expand Down

0 comments on commit 30394ad

Please sign in to comment.