mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-30 18:17:55 +00:00
Fix raw format for other commands, add to docs! (#17730)
* Clarify when -format=raw fails Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com> * Document Vault read's new -format=raw mode Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com> * Add raw format to usage, completion Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com> * Add missing support for raw format field printing Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com> * Prohibit command execution with wrong formatter This allows us to restrict the raw formatter to only commands that understand it; otherwise, when running `vault write -format=raw`, we'd actually hit the Vault server, but hide the output from the user. By switching this to a flag-parse time check, we avoid running the rest of the command if a bad formatter was specified. Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com> Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
This commit is contained in:
@@ -322,3 +322,20 @@ func generateFlagWarnings(args []string) string {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func generateFlagErrors(f *FlagSets, opts ...ParseOptions) error {
|
||||
if Format(f.ui) == "raw" {
|
||||
canUseRaw := false
|
||||
for _, opt := range opts {
|
||||
if value, ok := opt.(ParseOptionAllowRawFormat); ok {
|
||||
canUseRaw = bool(value)
|
||||
}
|
||||
}
|
||||
|
||||
if !canUseRaw {
|
||||
return fmt.Errorf("This command does not support the -format=raw option.")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user