Add podman system events alias to podman events

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
Daniel J Walsh
2022-11-09 15:45:01 -05:00
parent ae9a2d26df
commit bc77c034f8
8 changed files with 34 additions and 8 deletions

View File

@ -16,13 +16,13 @@ import (
)
var (
eventsDescription = `Monitor podman events.
eventsDescription = `Monitor podman system events.
By default, streaming mode is used, printing new events as they occur. Previous events can be listed via --since and --until.`
eventsCommand = &cobra.Command{
Use: "events [options]",
Args: validate.NoArgs,
Short: "Show podman events",
Short: "Show podman system events",
Long: eventsDescription,
RunE: eventsCmd,
ValidArgsFunction: completion.AutocompleteNone,
@ -31,6 +31,16 @@ var (
podman events --format {{.Image}}
podman events --since 1h30s`,
}
systemEventsCommand = &cobra.Command{
Args: eventsCommand.Args,
Use: eventsCommand.Use,
Short: eventsCommand.Short,
Long: eventsCommand.Long,
RunE: eventsCommand.RunE,
ValidArgsFunction: eventsCommand.ValidArgsFunction,
Example: `podman system events`,
}
)
var (
@ -40,30 +50,39 @@ var (
)
func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
Command: systemEventsCommand,
Parent: systemCmd,
})
eventsFlags(systemEventsCommand)
registry.Commands = append(registry.Commands, registry.CliCommand{
Command: eventsCommand,
})
flags := eventsCommand.Flags()
eventsFlags(eventsCommand)
}
func eventsFlags(cmd *cobra.Command) {
flags := cmd.Flags()
filterFlagName := "filter"
flags.StringArrayVarP(&eventOptions.Filter, filterFlagName, "f", []string{}, "filter output")
_ = eventsCommand.RegisterFlagCompletionFunc(filterFlagName, common.AutocompleteEventFilter)
_ = cmd.RegisterFlagCompletionFunc(filterFlagName, common.AutocompleteEventFilter)
formatFlagName := "format"
flags.StringVar(&eventFormat, formatFlagName, "", "format the output using a Go template")
_ = eventsCommand.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteFormat(&events.Event{}))
_ = cmd.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteFormat(&events.Event{}))
flags.BoolVar(&eventOptions.Stream, "stream", true, "stream new events; for testing only")
sinceFlagName := "since"
flags.StringVar(&eventOptions.Since, sinceFlagName, "", "show all events created since timestamp")
_ = eventsCommand.RegisterFlagCompletionFunc(sinceFlagName, completion.AutocompleteNone)
_ = cmd.RegisterFlagCompletionFunc(sinceFlagName, completion.AutocompleteNone)
flags.BoolVar(&noTrunc, "no-trunc", true, "do not truncate the output")
untilFlagName := "until"
flags.StringVar(&eventOptions.Until, untilFlagName, "", "show all events until timestamp")
_ = eventsCommand.RegisterFlagCompletionFunc(untilFlagName, completion.AutocompleteNone)
_ = cmd.RegisterFlagCompletionFunc(untilFlagName, completion.AutocompleteNone)
_ = flags.MarkHidden("stream")
}