mirror of
https://github.com/containers/podman.git
synced 2025-06-22 18:08:11 +08:00
more shell completion improvements
* podman image ls --filter * podman network ls --filter * podman volume ls --filter * podman network connect/disconnect * podman events --filter Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
This commit is contained in:
@ -464,6 +464,18 @@ func AutocompleteCpCommand(cmd *cobra.Command, args []string, toComplete string)
|
|||||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AutocompleteNetworkConnectCmd - Autocomplete podman network connect/disconnect command args.
|
||||||
|
func AutocompleteNetworkConnectCmd(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
if len(args) == 0 {
|
||||||
|
return getNetworks(cmd, toComplete)
|
||||||
|
}
|
||||||
|
if len(args) == 1 {
|
||||||
|
return getContainers(cmd, toComplete, completeDefault)
|
||||||
|
}
|
||||||
|
// don't complete more than 2 args
|
||||||
|
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||||
|
}
|
||||||
|
|
||||||
// AutocompleteSystemConnections - Autocomplete system connections.
|
// AutocompleteSystemConnections - Autocomplete system connections.
|
||||||
func AutocompleteSystemConnections(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
func AutocompleteSystemConnections(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
if !validCurrentCmdLine(cmd, args, toComplete) {
|
if !validCurrentCmdLine(cmd, args, toComplete) {
|
||||||
@ -695,8 +707,22 @@ func AutocompleteJSONFormat(cmd *cobra.Command, args []string, toComplete string
|
|||||||
// AutocompleteEventFilter - Autocomplete event filter flag options.
|
// AutocompleteEventFilter - Autocomplete event filter flag options.
|
||||||
// -> "container=", "event=", "image=", "pod=", "volume=", "type="
|
// -> "container=", "event=", "image=", "pod=", "volume=", "type="
|
||||||
func AutocompleteEventFilter(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
func AutocompleteEventFilter(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
filters := []string{"container=", "event=", "image=", "pod=", "volume=", "type="}
|
eventTypes := func(_ string) ([]string, cobra.ShellCompDirective) {
|
||||||
return filters, cobra.ShellCompDirectiveNoSpace
|
return []string{"attach", "checkpoint", "cleanup", "commit", "create", "exec",
|
||||||
|
"export", "import", "init", "kill", "mount", "pause", "prune", "remove",
|
||||||
|
"restart", "restore", "start", "stop", "sync", "unmount", "unpause",
|
||||||
|
"pull", "push", "save", "tag", "untag", "refresh", "renumber",
|
||||||
|
}, cobra.ShellCompDirectiveNoFileComp
|
||||||
|
}
|
||||||
|
kv := keyValueCompletion{
|
||||||
|
"container=": func(s string) ([]string, cobra.ShellCompDirective) { return getContainers(cmd, s, completeDefault) },
|
||||||
|
"image=": func(s string) ([]string, cobra.ShellCompDirective) { return getImages(cmd, s) },
|
||||||
|
"pod=": func(s string) ([]string, cobra.ShellCompDirective) { return getPods(cmd, s, completeDefault) },
|
||||||
|
"volume=": func(s string) ([]string, cobra.ShellCompDirective) { return getVolumes(cmd, s) },
|
||||||
|
"event=": eventTypes,
|
||||||
|
"type=": eventTypes,
|
||||||
|
}
|
||||||
|
return completeKeyValues(toComplete, kv)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AutocompleteSystemdRestartOptions - Autocomplete systemd restart options.
|
// AutocompleteSystemdRestartOptions - Autocomplete systemd restart options.
|
||||||
@ -846,3 +872,47 @@ func AutocompletePodPsFilters(cmd *cobra.Command, args []string, toComplete stri
|
|||||||
}
|
}
|
||||||
return completeKeyValues(toComplete, kv)
|
return completeKeyValues(toComplete, kv)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AutocompleteImageFilters - Autocomplete image ls --filter options.
|
||||||
|
func AutocompleteImageFilters(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
getBool := func(_ string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
return []string{"true", "false"}, cobra.ShellCompDirectiveNoFileComp
|
||||||
|
}
|
||||||
|
getImg := func(s string) ([]string, cobra.ShellCompDirective) { return getImages(cmd, s) }
|
||||||
|
kv := keyValueCompletion{
|
||||||
|
"before=": getImg,
|
||||||
|
"since=": getImg,
|
||||||
|
"label=": nil,
|
||||||
|
"reference=": nil,
|
||||||
|
"dangling=": getBool,
|
||||||
|
"readonly=": getBool,
|
||||||
|
}
|
||||||
|
return completeKeyValues(toComplete, kv)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AutocompleteNetworkFilters - Autocomplete network ls --filter options.
|
||||||
|
func AutocompleteNetworkFilters(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
kv := keyValueCompletion{
|
||||||
|
"name=": func(s string) ([]string, cobra.ShellCompDirective) { return getNetworks(cmd, s) },
|
||||||
|
"plugin=": nil,
|
||||||
|
}
|
||||||
|
return completeKeyValues(toComplete, kv)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AutocompleteVolumeFilters - Autocomplete volume ls --filter options.
|
||||||
|
func AutocompleteVolumeFilters(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
local := func(_ string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
return []string{"local"}, cobra.ShellCompDirectiveNoFileComp
|
||||||
|
}
|
||||||
|
kv := keyValueCompletion{
|
||||||
|
"name=": func(s string) ([]string, cobra.ShellCompDirective) { return getVolumes(cmd, s) },
|
||||||
|
"driver=": local,
|
||||||
|
"scope=": local,
|
||||||
|
"label=": nil,
|
||||||
|
"opt=": nil,
|
||||||
|
"dangling=": func(_ string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
return []string{"true", "false"}, cobra.ShellCompDirectiveNoFileComp
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return completeKeyValues(toComplete, kv)
|
||||||
|
}
|
||||||
|
@ -79,8 +79,7 @@ func imageListFlagSet(cmd *cobra.Command) {
|
|||||||
|
|
||||||
filterFlagName := "filter"
|
filterFlagName := "filter"
|
||||||
flags.StringSliceVarP(&listOptions.Filter, filterFlagName, "f", []string{}, "Filter output based on conditions provided (default [])")
|
flags.StringSliceVarP(&listOptions.Filter, filterFlagName, "f", []string{}, "Filter output based on conditions provided (default [])")
|
||||||
// TODO: add completion function for filters
|
_ = cmd.RegisterFlagCompletionFunc(filterFlagName, common.AutocompleteImageFilters)
|
||||||
_ = cmd.RegisterFlagCompletionFunc(filterFlagName, completion.AutocompleteNone)
|
|
||||||
|
|
||||||
formatFlagName := "format"
|
formatFlagName := "format"
|
||||||
flags.StringVar(&listFlag.format, formatFlagName, "", "Change the output format to JSON or a Go template")
|
flags.StringVar(&listFlag.format, formatFlagName, "", "Change the output format to JSON or a Go template")
|
||||||
|
@ -17,7 +17,7 @@ var (
|
|||||||
RunE: networkConnect,
|
RunE: networkConnect,
|
||||||
Example: `podman network connect web secondary`,
|
Example: `podman network connect web secondary`,
|
||||||
Args: cobra.ExactArgs(2),
|
Args: cobra.ExactArgs(2),
|
||||||
ValidArgsFunction: common.AutocompleteNetworks,
|
ValidArgsFunction: common.AutocompleteNetworkConnectCmd,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ var (
|
|||||||
RunE: networkDisconnect,
|
RunE: networkDisconnect,
|
||||||
Example: `podman network disconnect web secondary`,
|
Example: `podman network disconnect web secondary`,
|
||||||
Args: cobra.ExactArgs(2),
|
Args: cobra.ExactArgs(2),
|
||||||
ValidArgsFunction: common.AutocompleteNetworks,
|
ValidArgsFunction: common.AutocompleteNetworkConnectCmd,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ func networkListFlags(flags *pflag.FlagSet) {
|
|||||||
|
|
||||||
filterFlagName := "filter"
|
filterFlagName := "filter"
|
||||||
flags.StringVarP(&networkListOptions.Filter, filterFlagName, "", "", "Provide filter values (e.g. 'name=podman')")
|
flags.StringVarP(&networkListOptions.Filter, filterFlagName, "", "", "Provide filter values (e.g. 'name=podman')")
|
||||||
_ = networklistCommand.RegisterFlagCompletionFunc(filterFlagName, completion.AutocompleteNone)
|
_ = networklistCommand.RegisterFlagCompletionFunc(filterFlagName, common.AutocompleteNetworkFilters)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ func init() {
|
|||||||
|
|
||||||
filterFlagName := "filter"
|
filterFlagName := "filter"
|
||||||
flags.StringSliceVarP(&cliOpts.Filter, filterFlagName, "f", []string{}, "Filter volume output")
|
flags.StringSliceVarP(&cliOpts.Filter, filterFlagName, "f", []string{}, "Filter volume output")
|
||||||
_ = lsCommand.RegisterFlagCompletionFunc(filterFlagName, completion.AutocompleteNone)
|
_ = lsCommand.RegisterFlagCompletionFunc(filterFlagName, common.AutocompleteVolumeFilters)
|
||||||
|
|
||||||
formatFlagName := "format"
|
formatFlagName := "format"
|
||||||
flags.StringVar(&cliOpts.Format, formatFlagName, "{{.Driver}}\t{{.Name}}\n", "Format volume output using Go template")
|
flags.StringVar(&cliOpts.Format, formatFlagName, "{{.Driver}}\t{{.Name}}\n", "Format volume output using Go template")
|
||||||
|
Reference in New Issue
Block a user