Skip to content

Commit

Permalink
cli/namespace: add detailed flag to namespace list (#20243) (#20251)
Browse files Browse the repository at this point in the history
* cli/namespace: add detailed flag to namespace list

* changelog

Co-authored-by: Jason O'Donnell <2160810+jasonodonnell@users.noreply.github.com>
  • Loading branch information
1 parent 6f95541 commit 89bb6c1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
4 changes: 4 additions & 0 deletions changelog/20243.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:improvement
cli/namespace: Add detailed flag to output additional namespace information
such as namespace IDs and custom metadata.
```
17 changes: 16 additions & 1 deletion command/namespace_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,18 @@ Usage: vault namespace list [options]
}

func (c *NamespaceListCommand) Flags() *FlagSets {
return c.flagSet(FlagSetHTTP | FlagSetOutputFormat)
set := c.flagSet(FlagSetHTTP | FlagSetOutputFormat)

f := set.NewFlagSet("Command Options")

f.BoolVar(&BoolVar{
Name: "detailed",
Target: &c.flagDetailed,
Default: false,
Usage: "Print detailed information such as namespace ID.",
})

return set
}

func (c *NamespaceListCommand) AutocompleteArgs() complete.Predictor {
Expand Down Expand Up @@ -101,5 +112,9 @@ func (c *NamespaceListCommand) Run(args []string) int {
return 2
}

if c.flagDetailed && Format(c.UI) != "table" {
return OutputData(c.UI, secret.Data["key_info"])
}

return OutputList(c.UI, secret)
}
8 changes: 7 additions & 1 deletion website/content/docs/commands/namespace.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ List all namespaces:
$ vault namespace list
```

Create a namespace at the path `ns1/`:
List all namespaces with additional details such as namespace ID and custom metadata:

```shell-session
$ vault namespace list -detailed
```

Create a namespace at the path `ns1/` with no custom metadata:

```shell-session
$ vault namespace create ns1/
Expand Down

0 comments on commit 89bb6c1

Please sign in to comment.