Stop vctx format scan at --; limit raw to vault read
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful

This commit is contained in:
2026-10-23 22:00:31 +11:00
parent 5a64b10b25
commit 718a3a9063
3 changed files with 8 additions and 3 deletions
+1 -1
View File
@@ -48,7 +48,7 @@ Without `--format`, `vctx` sets `VAULT_FORMAT` from the vault command:
It is left alone when `VAULT_FORMAT` is already set in the environment or the
vault args include `-format` or `-field`. `--format` (`table`, `json`, `yaml`,
`pretty`, `raw`) always sets it.
`pretty`; `raw` for `vault read` only) always sets it.
## Flags
+6 -2
View File
@@ -68,7 +68,7 @@ func newRootCmd() *cobra.Command {
})
root.Flags().StringVar(&format, "format", "", "VAULT_FORMAT for this call (default: picked from the vault command)")
_ = root.RegisterFlagCompletionFunc("format", cobra.FixedCompletions(
[]string{"table", "json", "yaml", "pretty", "raw"}, cobra.ShellCompDirectiveNoFileComp))
[]string{"table", "json", "yaml", "pretty"}, cobra.ShellCompDirectiveNoFileComp))
root.AddCommand(&cobra.Command{
Use: "version",
@@ -166,7 +166,11 @@ func autoFormat(args, baseEnv []string) string {
}
}
var pos []string
for _, a := range args {
for i, a := range args {
if a == "--" {
pos = append(pos, args[i+1:]...)
break
}
name, _, _ := strings.Cut(strings.TrimLeft(a, "-"), "=")
switch {
case !strings.HasPrefix(a, "-"):
+1
View File
@@ -214,6 +214,7 @@ func TestAutoFormat(t *testing.T) {
{[]string{"kv", "get", "-format=json", "kv/foo"}, nil, ""},
{[]string{"read", "--format", "json", "aws/creds/role"}, nil, ""},
{[]string{"kv", "get", "-field=password", "kv/foo"}, nil, ""},
{[]string{"kv", "get", "--", "-format=json"}, nil, "yaml"},
{[]string{"kv", "get", "kv/foo"}, []string{"VAULT_FORMAT=json"}, ""},
{[]string{"kv", "get", "kv/foo"}, []string{"VAULT_FORMAT="}, "yaml"},
}