aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorAshley Cui <acui@redhat.com>2022-09-14 15:28:00 -0400
committerAshley Cui <acui@redhat.com>2022-09-22 14:07:11 -0400
commitdc05d1212c41d34f23d12cf1957917f5ce022f26 (patch)
tree6d6ad6a294496ffa7632ac2fa0eaa66ee2ff8b62 /cmd
parent828fae12971c5a7b9807c8c4f8e029fe5d0ddc2f (diff)
downloadpodman-dc05d1212c41d34f23d12cf1957917f5ce022f26.tar.gz
podman-dc05d1212c41d34f23d12cf1957917f5ce022f26.tar.bz2
podman-dc05d1212c41d34f23d12cf1957917f5ce022f26.zip
Add --pretty to podman secret inspect
Pretty-print podman secret inspect output in a human-readable format Signed-off-by: Ashley Cui <acui@redhat.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/secrets/inspect.go42
1 files changed, 38 insertions, 4 deletions
diff --git a/cmd/podman/secrets/inspect.go b/cmd/podman/secrets/inspect.go
index f4c395b0f..9054fc3b0 100644
--- a/cmd/podman/secrets/inspect.go
+++ b/cmd/podman/secrets/inspect.go
@@ -25,7 +25,23 @@ var (
}
)
-var format string
+var (
+ format string
+ pretty bool
+)
+
+const (
+ prettyTemplate = `ID: {{.ID}}
+Name: {{.Spec.Name}}
+{{- if .Spec.Labels }}
+Labels:
+{{- range $k, $v := .Spec.Labels }}
+ - {{ $k }}{{if $v }}={{ $v }}{{ end }}
+{{- end }}{{ end }}
+Driver: {{.Spec.Driver.Name}}
+Created at: {{.CreatedAt}}
+Updated at: {{.UpdatedAt}}`
+)
func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
@@ -34,8 +50,11 @@ func init() {
})
flags := inspectCmd.Flags()
formatFlagName := "format"
- flags.StringVarP(&format, formatFlagName, "f", "", "Format volume output using Go template")
+ flags.StringVarP(&format, formatFlagName, "f", "", "Format inspect output using Go template")
_ = inspectCmd.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteFormat(&entities.SecretInfoReport{}))
+
+ prettyFlagName := "pretty"
+ flags.BoolVar(&pretty, prettyFlagName, false, "Print inspect output in human-readable format")
}
func inspect(cmd *cobra.Command, args []string) error {
@@ -46,7 +65,21 @@ func inspect(cmd *cobra.Command, args []string) error {
inspected = []*entities.SecretInfoReport{}
}
- if cmd.Flags().Changed("format") {
+ switch {
+ case cmd.Flags().Changed("pretty"):
+ rpt := report.New(os.Stdout, cmd.Name())
+ defer rpt.Flush()
+
+ rpt, err := rpt.Parse(report.OriginUser, prettyTemplate)
+ if err != nil {
+ return err
+ }
+
+ if err := rpt.Execute(inspected); err != nil {
+ return err
+ }
+
+ case cmd.Flags().Changed("format"):
rpt := report.New(os.Stdout, cmd.Name())
defer rpt.Flush()
@@ -58,7 +91,8 @@ func inspect(cmd *cobra.Command, args []string) error {
if err := rpt.Execute(inspected); err != nil {
return err
}
- } else {
+
+ default:
buf, err := json.MarshalIndent(inspected, "", " ")
if err != nil {
return err