From a3975e806e4a480a9cd9770ff06d4f23dc526595 Mon Sep 17 00:00:00 2001 From: Luap99 Date: Sun, 31 May 2020 17:35:59 +0200 Subject: [PATCH] Add shell completion with cobra Allow automatic generation for shell completion scripts with the internal cobra functions (requires v1.0.0) This should replace the handwritten completion scripts and even adds support for fish and powershell(if needed?) We can now create the scripts with - podman completion bash - podman completion zsh - podman completion fish - podman completion powershell to test the completion run: source <(podman completion bash) I added the main completion for all commands but this still could be improved with better custom completion functions. see: cmd/podman/completion/completion.go Flag completion is for now only added to some commands just to show how to implement this on flags This is still WIP Closes #6440 Signed-off-by: Paul Holzinger --- cmd/podman/auto-update.go | 10 +- cmd/podman/common/const.go | 9 + cmd/podman/completion/bash.go | 64 +++ cmd/podman/completion/completion.go | 368 ++++++++++++++++++ cmd/podman/completion/fish.go | 61 +++ cmd/podman/completion/powershell.go | 59 +++ cmd/podman/completion/zsh.go | 64 +++ cmd/podman/containers/attach.go | 29 +- cmd/podman/containers/checkpoint.go | 8 +- cmd/podman/containers/cleanup.go | 8 +- cmd/podman/containers/commit.go | 57 ++- cmd/podman/containers/cp.go | 27 +- cmd/podman/containers/create.go | 23 +- cmd/podman/containers/diff.go | 12 +- cmd/podman/containers/exec.go | 3 + cmd/podman/containers/exists.go | 2 + cmd/podman/containers/export.go | 12 +- cmd/podman/containers/init.go | 13 +- cmd/podman/containers/inspect.go | 10 +- cmd/podman/containers/kill.go | 11 +- cmd/podman/containers/list.go | 14 +- cmd/podman/containers/logs.go | 15 +- cmd/podman/containers/mount.go | 11 +- cmd/podman/containers/pause.go | 19 +- cmd/podman/containers/port.go | 15 +- cmd/podman/containers/prune.go | 16 +- cmd/podman/containers/ps.go | 12 +- cmd/podman/containers/restart.go | 11 +- cmd/podman/containers/restore.go | 13 +- cmd/podman/containers/rm.go | 15 +- cmd/podman/containers/run.go | 23 +- cmd/podman/containers/runlabel.go | 34 +- cmd/podman/containers/start.go | 19 +- cmd/podman/containers/stats.go | 23 +- cmd/podman/containers/stop.go | 15 +- cmd/podman/containers/top.go | 21 +- cmd/podman/containers/unmount.go | 15 +- cmd/podman/containers/unpause.go | 19 +- cmd/podman/containers/wait.go | 23 +- cmd/podman/diff.go | 14 +- cmd/podman/generate/kube.go | 12 +- cmd/podman/generate/systemd.go | 18 +- cmd/podman/healthcheck/run.go | 14 +- cmd/podman/images/build.go | 23 +- cmd/podman/images/diff.go | 12 +- cmd/podman/images/exists.go | 12 +- cmd/podman/images/history.go | 27 +- cmd/podman/images/images.go | 1 + cmd/podman/images/import.go | 21 +- cmd/podman/images/inspect.go | 10 +- cmd/podman/images/list.go | 14 +- cmd/podman/images/load.go | 23 +- cmd/podman/images/prune.go | 14 +- cmd/podman/images/pull.go | 23 +- cmd/podman/images/push.go | 19 +- cmd/podman/images/rm.go | 10 +- cmd/podman/images/rmi.go | 13 +- cmd/podman/images/save.go | 2 + cmd/podman/images/search.go | 25 +- cmd/podman/images/sign.go | 12 +- cmd/podman/images/tag.go | 23 +- cmd/podman/images/tree.go | 14 +- cmd/podman/images/trust_set.go | 14 +- cmd/podman/images/trust_show.go | 12 +- cmd/podman/images/untag.go | 23 +- cmd/podman/inspect.go | 12 +- cmd/podman/login.go | 12 +- cmd/podman/logout.go | 12 +- cmd/podman/main.go | 1 + cmd/podman/manifest/add.go | 3 + cmd/podman/manifest/annotate.go | 15 +- cmd/podman/manifest/create.go | 3 + cmd/podman/manifest/inspect.go | 15 +- cmd/podman/manifest/push.go | 15 +- cmd/podman/manifest/remove.go | 15 +- cmd/podman/networks/create.go | 12 +- cmd/podman/networks/inspect.go | 14 +- cmd/podman/networks/list.go | 14 +- cmd/podman/networks/rm.go | 14 +- cmd/podman/play/kube.go | 12 +- cmd/podman/pods/create.go | 12 +- cmd/podman/pods/exists.go | 12 +- cmd/podman/pods/inspect.go | 12 +- cmd/podman/pods/kill.go | 2 + cmd/podman/pods/pause.go | 2 + cmd/podman/pods/prune.go | 12 +- cmd/podman/pods/ps.go | 14 +- cmd/podman/pods/restart.go | 2 + cmd/podman/pods/rm.go | 2 + cmd/podman/pods/start.go | 2 + cmd/podman/pods/stats.go | 10 +- cmd/podman/pods/stop.go | 2 + cmd/podman/pods/top.go | 12 +- cmd/podman/pods/unpause.go | 4 + cmd/podman/system/df.go | 12 +- cmd/podman/system/events.go | 12 +- cmd/podman/system/info.go | 14 +- cmd/podman/system/migrate.go | 12 +- cmd/podman/system/prune.go | 14 +- cmd/podman/system/renumber.go | 12 +- cmd/podman/system/reset.go | 12 +- cmd/podman/system/service.go | 14 +- cmd/podman/system/unshare.go | 3 + cmd/podman/system/varlink.go | 12 +- cmd/podman/system/version.go | 10 +- cmd/podman/volumes/create.go | 10 +- cmd/podman/volumes/inspect.go | 10 +- cmd/podman/volumes/list.go | 14 +- cmd/podman/volumes/prune.go | 12 +- cmd/podman/volumes/rm.go | 12 +- .../markdown/podman-completion-bash.1.md | 24 ++ .../markdown/podman-completion-fish.1.md | 24 ++ .../podman-completion-powershell.1.md | 22 ++ .../markdown/podman-completion-zsh.1.md | 24 ++ docs/source/markdown/podman-completion.1.md | 44 +++ pkg/domain/entities/completion.go | 7 + pkg/systemd/generate/systemdgen.go | 4 +- 117 files changed, 1627 insertions(+), 564 deletions(-) create mode 100644 cmd/podman/common/const.go create mode 100644 cmd/podman/completion/bash.go create mode 100644 cmd/podman/completion/completion.go create mode 100644 cmd/podman/completion/fish.go create mode 100644 cmd/podman/completion/powershell.go create mode 100644 cmd/podman/completion/zsh.go create mode 100644 docs/source/markdown/podman-completion-bash.1.md create mode 100644 docs/source/markdown/podman-completion-fish.1.md create mode 100644 docs/source/markdown/podman-completion-powershell.1.md create mode 100644 docs/source/markdown/podman-completion-zsh.1.md create mode 100644 docs/source/markdown/podman-completion.1.md create mode 100644 pkg/domain/entities/completion.go diff --git a/cmd/podman/auto-update.go b/cmd/podman/auto-update.go index 11433bc25fe8..7a7d9b624bee 100644 --- a/cmd/podman/auto-update.go +++ b/cmd/podman/auto-update.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/containers/common/pkg/auth" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/errorhandling" @@ -18,10 +19,11 @@ var ( Auto-update policies are specified with the "io.containers.autoupdate" label. Note that this command is experimental. Please refer to the podman-auto-update(1) man page for details.` autoUpdateCommand = &cobra.Command{ - Use: "auto-update [flags]", - Short: "Auto update containers according to their auto-update policy", - Long: autoUpdateDescription, - RunE: autoUpdate, + Use: "auto-update [flags]", + Short: "Auto update containers according to their auto-update policy", + Long: autoUpdateDescription, + RunE: autoUpdate, + ValidArgsFunction: completion.AutocompleteNone, Example: `podman auto-update podman auto-update --authfile ~/authfile.json`, } diff --git a/cmd/podman/common/const.go b/cmd/podman/common/const.go new file mode 100644 index 000000000000..cc5dda9a2d29 --- /dev/null +++ b/cmd/podman/common/const.go @@ -0,0 +1,9 @@ +package common + +var ( + // ChangeCmds is the list of valid Changes commands to passed to the Commit call + ChangeCmds = []string{"CMD", "ENTRYPOINT", "ENV", "EXPOSE", "LABEL", "ONBUILD", "STOPSIGNAL", "USER", "VOLUME", "WORKDIR"} + + // Image format + ImageFormat = []string{"oci", "docker"} +) diff --git a/cmd/podman/completion/bash.go b/cmd/podman/completion/bash.go new file mode 100644 index 000000000000..e3dc3b964a00 --- /dev/null +++ b/cmd/podman/completion/bash.go @@ -0,0 +1,64 @@ +package completion + +import ( + "os" + + "github.com/containers/libpod/cmd/podman/registry" + "github.com/containers/libpod/pkg/domain/entities" + "github.com/pkg/errors" + "github.com/spf13/cobra" +) + +const ( + bashAutoCompletionDescription = `Creates bash completion and writes to stdout + +To load in your current session run +source <(podman completion bash) + +To make it available in all your bash session, add this to your ~/.bashrc file: +echo 'source <(podman completion bash)' >>~/.bashrc + +As an alternative, if 'bash-completion' is installed on your system, you can add it in: +/etc/bash_completion.d/{your_file_name}` +) + +var ( + bashCmd = &cobra.Command{ + Use: "bash", + Short: "Creates bash completion", + Long: bashAutoCompletionDescription, + RunE: bashCompletion, + ValidArgsFunction: AutocompleteNone, + Example: "podman completion bash", + } +) + +func init() { + registry.Commands = append(registry.Commands, registry.CliCommand{ + Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, + Command: bashCmd, + Parent: completionCmd, + }) + flags := bashCmd.Flags() + flags.StringVarP(&completionOptions.File, "file", "f", "", "Output the completion to file rather then stdout") +} + +//Generate the bash completion with the internal cobra function. +func bashCompletion(cmd *cobra.Command, args []string) error { + if len(args) > 0 { + return errors.Errorf("`%s` takes no arguments", cmd.CommandPath()) + } + + var err error + if completionOptions.File == "" { + err = completionCmd.Root().GenBashCompletion(os.Stdout) + } else { + err = completionCmd.Root().GenBashCompletionFile(completionOptions.File) + } + + if err != nil { + return err + } + + return nil +} diff --git a/cmd/podman/completion/completion.go b/cmd/podman/completion/completion.go new file mode 100644 index 000000000000..f2b787b5b6e8 --- /dev/null +++ b/cmd/podman/completion/completion.go @@ -0,0 +1,368 @@ +package completion + +import ( + "context" + "strings" + + "github.com/containers/libpod/cmd/podman/common" + "github.com/containers/libpod/cmd/podman/registry" + "github.com/containers/libpod/cmd/podman/validate" + "github.com/containers/libpod/pkg/domain/entities" + "github.com/containers/libpod/pkg/registries" + systemd "github.com/containers/libpod/pkg/systemd/generate" + "github.com/spf13/cobra" +) + +var ( + completionOptions = entities.CompletionOptions{} + completionCmd = &cobra.Command{ + Use: "completion", + Short: "Generate shell autocompletions", + Args: cobra.ExactArgs(1), + Long: "Generate shell autocompletions for bash/zsh/fish/powershell\nThis uses the internal cobra functions", + TraverseChildren: true, + RunE: validate.SubCommandExists, + //dont show command to user + Hidden: true, + } +) + +func init() { + registry.Commands = append(registry.Commands, registry.CliCommand{ + Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, + Command: completionCmd, + }) +} + +//Get containers with status. +func getContainers(status string) ([]string, cobra.ShellCompDirective) { + var suggestions []string + + listOpts := entities.ContainerListOptions{ + Filters: make(map[string][]string), + } + listOpts.All = true + + if status != "all" { + listOpts.Filters = map[string][]string{"status": {status}} + } + + containers, err := registry.ContainerEngine().ContainerList(registry.GetContext(), listOpts) + if err != nil { + return nil, cobra.ShellCompDirectiveError + } + + for _, container := range containers { + //include name in suggestions + //if ids should be also completed + //suggestions = append(suggestions, container.Names[0], container.ID[0:12]) + suggestions = append(suggestions, container.Names...) + } + + return suggestions, cobra.ShellCompDirectiveNoFileComp +} + +//Get pods with status. +func getPods(status string) ([]string, cobra.ShellCompDirective) { + var suggestions []string + + listOpts := entities.PodPSOptions{ + Filters: make(map[string][]string), + } + + if status != "all" { + listOpts.Filters = map[string][]string{"status": {status}} + } + + pods, err := registry.ContainerEngine().PodPs(registry.GetContext(), listOpts) + if err != nil { + return nil, cobra.ShellCompDirectiveError + } + + for _, pod := range pods { + //include name in suggestions + //if ids should be also completed + //suggestions = append(suggestions, pod.Name, pod.Id[0:12]) + suggestions = append(suggestions, pod.Name) + } + + return suggestions, cobra.ShellCompDirectiveNoFileComp +} + +//Get all volumes. +func getVolumes() ([]string, cobra.ShellCompDirective) { + var suggestions []string + + lsOpts := entities.VolumeListOptions{} + + volumes, err := registry.ContainerEngine().VolumeList(context.Background(), lsOpts) + if err != nil { + return nil, cobra.ShellCompDirectiveError + } + + for _, volume := range volumes { + suggestions = append(suggestions, volume.Name) + } + + return suggestions, cobra.ShellCompDirectiveNoFileComp +} + +//Get all images. +func getImages(toComplete string) ([]string, cobra.ShellCompDirective) { + var suggestions []string + + listOptions := entities.ImageListOptions{} + + images, err := registry.ImageEngine().List(registry.GetContext(), listOptions) + if err != nil { + return nil, cobra.ShellCompDirectiveError + } + + for _, image := range images { + for _, repo := range image.RepoTags { + if toComplete == "" { + //suggest only full repo path if no input is given + suggestions = append(suggestions, repo) + } else { + //suggested "registry.fedoraproject.org/f29/httpd:latest" as + // - "registry.fedoraproject.org/f29/httpd:latest" + // - "registry.fedoraproject.org/f29/httpd" + // - "f29/httpd:latest" + // - "f29/httpd" + // - "httpd:latest" + // - "httpd" + paths := strings.Split(repo, "/") + for i := range paths { + sugesstionWithTag := strings.Join(paths[i:], "/") + sugesstionWithoutTag := strings.SplitN(sugesstionWithTag, ":", 2)[0] + suggestions = append(suggestions, sugesstionWithTag, sugesstionWithoutTag) + } + } + } + } + + return suggestions, cobra.ShellCompDirectiveNoFileComp +} + +//Get all registries. +func getRegistries() ([]string, cobra.ShellCompDirective) { + regs, err := registries.GetRegistries() + if err != nil { + return nil, cobra.ShellCompDirectiveError + } + + return regs, cobra.ShellCompDirectiveNoFileComp +} + +//Get all networks. +func getNetworks() ([]string, cobra.ShellCompDirective) { + var suggestions []string + + networkListOptions := entities.NetworkListOptions{} + + networks, err := registry.ContainerEngine().NetworkList(registry.Context(), networkListOptions) + if err != nil { + return nil, cobra.ShellCompDirectiveError + } + + for _, network := range networks { + suggestions = append(suggestions, network.Name) + } + + return suggestions, cobra.ShellCompDirectiveNoFileComp +} + +/* Autocomplete Functions for cobra ValidArgsFunction */ + +//Block the default shell path completion, +//no path completion. +func AutocompleteNone(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return nil, cobra.ShellCompDirectiveNoFileComp +} + +//Use the default shell completion, +//allows path completion. +func AutocompleteDefault(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return nil, cobra.ShellCompDirectiveDefault +} + +//Autocomplete all container names. +func AutocompleteContainers(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return getContainers("all") +} + +//Autocomplete only created container names. +func AutocompleteContainersCreated(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return getContainers("created") +} + +//Autocomplete only exited container names. +func AutocompleteContainersExited(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return getContainers("exited") +} + +//Autocomplete only paused container names. +func AutocompleteContainersPaused(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return getContainers("paused") +} + +//Autocomplete only running container names. +func AutocompleteContainersRunning(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return getContainers("running") +} + +//Autocomplete only unknown container names. +/*func AutocompleteContainersUnknown(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return getContainers("unknown") +}*/ + +//Autocomplete only created and exited container names. +func AutocompleteContainersStartable(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + containersCreated, _ := getContainers("created") + containersExited, _ := getContainers("exited") + + switch { + case containersCreated != nil && containersExited != nil: + //combine both + return append(containersCreated, containersExited...), cobra.ShellCompDirectiveNoFileComp + + case containersCreated != nil: + return containersExited, cobra.ShellCompDirectiveNoFileComp + + case containersExited != nil: + return containersCreated, cobra.ShellCompDirectiveNoFileComp + + default: + return nil, cobra.ShellCompDirectiveError + } +} + +//Autocomplete all pod names. +func AutocompletePods(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return getPods("all") +} + +//Autocomplete only created pod names. +/*func AutocompletePodsCreated(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return getPods("created") +}*/ + +//Autocomplete only exited pod names. +/*func AutocompletePodsExited(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return getPods("exited") +}*/ + +//Autocomplete only running pod names. +func AutocompletePodsRunning(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return getPods("running") +} + +//Autocomplete only dead pod names. +/*func AutocompletePodsDead(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return getPods("dead") +}*/ + +//Autocomplete only created and exited pod names. +/*func AutocompletePodsStartable(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + podsCreated, _ := getPods("created") + podsExited, _ := getPods("exited") + + switch { + case podsCreated != nil && podsExited != nil: + //combine both + return append(podsCreated, podsExited...), cobra.ShellCompDirectiveNoFileComp + + case podsCreated != nil: + return podsExited, cobra.ShellCompDirectiveNoFileComp + + case podsExited != nil: + return podsCreated, cobra.ShellCompDirectiveNoFileComp + + default: + return nil, cobra.ShellCompDirectiveError + } +}*/ + +//Autocomplete container names and pod names. +func AutocompleteContainersAndPods(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + containers, _ := getContainers("all") + pods, _ := getPods("all") + + switch { + case containers != nil && pods != nil: + //combine both + return append(containers, pods...), cobra.ShellCompDirectiveNoFileComp + + case containers != nil: + return pods, cobra.ShellCompDirectiveNoFileComp + + case pods != nil: + return containers, cobra.ShellCompDirectiveNoFileComp + + default: + return nil, cobra.ShellCompDirectiveError + } +} + +//Autocomplete container names and pod names. +func AutocompleteContainersAndImages(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + containers, _ := getContainers("all") + images, _ := getImages(toComplete) + + switch { + case containers != nil && images != nil: + //combine both + return append(containers, images...), cobra.ShellCompDirectiveNoFileComp + + case containers != nil: + return images, cobra.ShellCompDirectiveNoFileComp + + case images != nil: + return containers, cobra.ShellCompDirectiveNoFileComp + + default: + return nil, cobra.ShellCompDirectiveError + } +} + +//Autocomplete volumes. +func AutocompleteVolumes(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return getVolumes() +} + +//Autocomplete images. +func AutocompleteImages(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return getImages(toComplete) +} + +//Autocomplete registries. +func AutocompleteRegistries(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return getRegistries() +} + +//Autocomplete networks. +func AutocompleteNetworks(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return getNetworks() +} + +/* Flags */ + +//Autocomplete systemd restart options. +func AutocompleteSystemdRestartOptions(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return systemd.RestartPolicies, cobra.ShellCompDirectiveNoFileComp +} + +//Autocomplete detach-keys options. +func AutocompleteDetachKeys(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return []string{"ctrl-"}, cobra.ShellCompDirectiveNoSpace +} + +//Autocomplete change instructions options for commit and import. +func AutocompleteChangeInstructions(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return common.ChangeCmds, cobra.ShellCompDirectiveNoSpace +} + +//Autocomplete image format options. +func AutocompleteImageFormat(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return common.ImageFormat, cobra.ShellCompDirectiveNoFileComp +} diff --git a/cmd/podman/completion/fish.go b/cmd/podman/completion/fish.go new file mode 100644 index 000000000000..51f234f0365f --- /dev/null +++ b/cmd/podman/completion/fish.go @@ -0,0 +1,61 @@ +package completion + +import ( + "os" + + "github.com/containers/libpod/cmd/podman/registry" + "github.com/containers/libpod/pkg/domain/entities" + "github.com/pkg/errors" + "github.com/spf13/cobra" +) + +const ( + fishAutoCompletionDescription = `Creates fish completion and writes to stdout + +To load in your current session run +podman completion fish | source + +As an alternative, if 'bash-completion' is installed on your system, you can add it in: +~/.config/fish/completions/podman.fish` +) + +var ( + fishCmd = &cobra.Command{ + Use: "fish", + Short: "Creates fish completion", + Long: fishAutoCompletionDescription, + RunE: fishCompletion, + ValidArgsFunction: AutocompleteNone, + Example: "podman completion fish", + } +) + +func init() { + registry.Commands = append(registry.Commands, registry.CliCommand{ + Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, + Command: fishCmd, + Parent: completionCmd, + }) + flags := fishCmd.Flags() + flags.StringVarP(&completionOptions.File, "file", "f", "", "Output the completion to file rather then stdout") +} + +//Generate the fish completion with the internal cobra function. +func fishCompletion(cmd *cobra.Command, args []string) error { + if len(args) > 0 { + return errors.Errorf("`%s` takes no arguments", cmd.CommandPath()) + } + + var err error + if completionOptions.File == "" { + err = completionCmd.Root().GenFishCompletion(os.Stdout, true) + } else { + err = completionCmd.Root().GenFishCompletionFile(completionOptions.File, true) + } + + if err != nil { + return err + } + + return nil +} diff --git a/cmd/podman/completion/powershell.go b/cmd/podman/completion/powershell.go new file mode 100644 index 000000000000..0925a4a50dc8 --- /dev/null +++ b/cmd/podman/completion/powershell.go @@ -0,0 +1,59 @@ +package completion + +import ( + "os" + + "github.com/containers/libpod/cmd/podman/registry" + "github.com/containers/libpod/pkg/domain/entities" + "github.com/pkg/errors" + "github.com/spf13/cobra" +) + +const ( + //TODO + powershellAutoCompletionDescription = `Creates powershell completion and writes to stdout + +How to load +TODO` +) + +var ( + powershellCmd = &cobra.Command{ + Use: "powershell", + Short: "Creates powershell completion", + Long: powershellAutoCompletionDescription, + RunE: powershellCompletion, + ValidArgsFunction: AutocompleteNone, + Example: "podman completion powershell", + } +) + +func init() { + registry.Commands = append(registry.Commands, registry.CliCommand{ + Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, + Command: powershellCmd, + Parent: completionCmd, + }) + flags := powershellCmd.Flags() + flags.StringVarP(&completionOptions.File, "file", "f", "", "Output the completion to file rather then stdout") +} + +//Generate the powershell completion with the internal cobra function. +func powershellCompletion(cmd *cobra.Command, args []string) error { + if len(args) > 0 { + return errors.Errorf("`%s` takes no arguments", cmd.CommandPath()) + } + + var err error + if completionOptions.File == "" { + err = completionCmd.Root().GenPowerShellCompletion(os.Stdout) + } else { + err = completionCmd.Root().GenPowerShellCompletionFile(completionOptions.File) + } + + if err != nil { + return err + } + + return nil +} diff --git a/cmd/podman/completion/zsh.go b/cmd/podman/completion/zsh.go new file mode 100644 index 000000000000..74d24a86143f --- /dev/null +++ b/cmd/podman/completion/zsh.go @@ -0,0 +1,64 @@ +package completion + +import ( + "os" + + "github.com/containers/libpod/cmd/podman/registry" + "github.com/containers/libpod/pkg/domain/entities" + "github.com/pkg/errors" + "github.com/spf13/cobra" +) + +const ( + zshAutoCompletionDescription = `Creates zsh completion and writes to stdout + +To load in your current session run +unset -f _podman;rm -f ~/.zcompdump; +source <(podman completion zsh) +compinit + +To make it available in all your zsh session, run this: +podman completion zsh -f "${fpath[1]}/_podman" +compinit` +) + +var ( + zshCmd = &cobra.Command{ + Use: "zsh", + Short: "Creates zsh completion", + Long: zshAutoCompletionDescription, + RunE: zshCompletion, + ValidArgsFunction: AutocompleteNone, + Example: "podman completion zsh", + } +) + +func init() { + registry.Commands = append(registry.Commands, registry.CliCommand{ + Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, + Command: zshCmd, + Parent: completionCmd, + }) + flags := zshCmd.Flags() + flags.StringVarP(&completionOptions.File, "file", "f", "", "Output the completion to file rather then stdout") +} + +//Generate the zsh completion with the internal cobra function. +func zshCompletion(cmd *cobra.Command, args []string) error { + if len(args) > 0 { + return errors.Errorf("`%s` takes no arguments", cmd.CommandPath()) + } + + var err error + if completionOptions.File == "" { + err = completionCmd.Root().GenZshCompletion(os.Stdout) + } else { + err = completionCmd.Root().GenZshCompletionFile(completionOptions.File) + } + + if err != nil { + return err + } + + return nil +} diff --git a/cmd/podman/containers/attach.go b/cmd/podman/containers/attach.go index 9f29d1664c37..7eecf57bcdc6 100644 --- a/cmd/podman/containers/attach.go +++ b/cmd/podman/containers/attach.go @@ -3,6 +3,7 @@ package containers import ( "os" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/validate" "github.com/containers/libpod/pkg/domain/entities" @@ -14,22 +15,24 @@ import ( var ( attachDescription = "The podman attach command allows you to attach to a running container using the container's ID or name, either to view its ongoing output or to control it interactively." attachCommand = &cobra.Command{ - Use: "attach [flags] CONTAINER", - Short: "Attach to a running container", - Long: attachDescription, - RunE: attach, - Args: validate.IdOrLatestArgs, + Use: "attach [flags] CONTAINER", + Short: "Attach to a running container", + Long: attachDescription, + RunE: attach, + Args: validate.IdOrLatestArgs, + ValidArgsFunction: completion.AutocompleteContainersRunning, Example: `podman attach ctrID podman attach 1234 podman attach --no-stdin foobar`, } containerAttachCommand = &cobra.Command{ - Use: attachCommand.Use, - Short: attachCommand.Short, - Long: attachCommand.Long, - RunE: attachCommand.RunE, - Args: validate.IdOrLatestArgs, + Use: attachCommand.Use, + Short: attachCommand.Short, + Long: attachCommand.Long, + RunE: attachCommand.RunE, + Args: validate.IdOrLatestArgs, + ValidArgsFunction: attachCommand.ValidArgsFunction, Example: `podman container attach ctrID podman container attach 1234 podman container attach --no-stdin foobar`, @@ -41,7 +44,11 @@ var ( ) func attachFlags(flags *pflag.FlagSet) { - flags.StringVar(&attachOpts.DetachKeys, "detach-keys", containerConfig.DetachKeys(), "Select the key sequence for detaching a container. Format is a single character `[a-Z]` or a comma separated sequence of `ctrl-`, where `` is one of: `a-z`, `@`, `^`, `[`, `\\`, `]`, `^` or `_`") + detachKeysFlagName := "detach-keys" + flags.StringVar(&attachOpts.DetachKeys, detachKeysFlagName, containerConfig.DetachKeys(), "Select the key sequence for detaching a container. Format is a single character `[a-Z]` or a comma separated sequence of `ctrl-`, where `` is one of: `a-z`, `@`, `^`, `[`, `\\`, `]`, `^` or `_`") + _ = attachCommand.RegisterFlagCompletionFunc(detachKeysFlagName, completion.AutocompleteDetachKeys) + _ = containerAttachCommand.RegisterFlagCompletionFunc(detachKeysFlagName, completion.AutocompleteDetachKeys) + flags.BoolVar(&attachOpts.NoStdin, "no-stdin", false, "Do not attach STDIN. The default is false") flags.BoolVar(&attachOpts.SigProxy, "sig-proxy", true, "Proxy received signals to the process") flags.BoolVarP(&attachOpts.Latest, "latest", "l", false, "Act on the latest container podman is aware of") diff --git a/cmd/podman/containers/checkpoint.go b/cmd/podman/containers/checkpoint.go index c4723af21c86..33b5429e9942 100644 --- a/cmd/podman/containers/checkpoint.go +++ b/cmd/podman/containers/checkpoint.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/parse" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/utils" @@ -27,6 +28,7 @@ var ( Args: func(cmd *cobra.Command, args []string) error { return parse.CheckAllLatestAndCIDFile(cmd, args, false, false) }, + ValidArgsFunction: completion.AutocompleteContainersRunning, Example: `podman container checkpoint --keep ctrID podman container checkpoint --all podman container checkpoint --leave-running --latest`, @@ -49,7 +51,11 @@ func init() { flags.BoolVar(&checkpointOptions.TCPEstablished, "tcp-established", false, "Checkpoint a container with established TCP connections") flags.BoolVarP(&checkpointOptions.All, "all", "a", false, "Checkpoint all running containers") flags.BoolVarP(&checkpointOptions.Latest, "latest", "l", false, "Act on the latest container podman is aware of") - flags.StringVarP(&checkpointOptions.Export, "export", "e", "", "Export the checkpoint image to a tar.gz") + + exportFlagName := "export" + flags.StringVarP(&checkpointOptions.Export, exportFlagName, "e", "", "Export the checkpoint image to a tar.gz") + _ = checkpointCommand.RegisterFlagCompletionFunc(exportFlagName, completion.AutocompleteDefault) + flags.BoolVar(&checkpointOptions.IgnoreRootFS, "ignore-rootfs", false, "Do not include root file-system changes when exporting") if registry.IsRemote() { _ = flags.MarkHidden("latest") diff --git a/cmd/podman/containers/cleanup.go b/cmd/podman/containers/cleanup.go index 619031208a47..34b71de812a4 100644 --- a/cmd/podman/containers/cleanup.go +++ b/cmd/podman/containers/cleanup.go @@ -3,6 +3,7 @@ package containers import ( "fmt" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/parse" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/utils" @@ -26,6 +27,7 @@ var ( Args: func(cmd *cobra.Command, args []string) error { return parse.CheckAllLatestAndCIDFile(cmd, args, false, false) }, + ValidArgsFunction: completion.AutocompleteContainersExited, Example: `podman container cleanup --latest podman container cleanup ctrID1 ctrID2 ctrID3 podman container cleanup --all`, @@ -45,7 +47,11 @@ func init() { flags := cleanupCommand.Flags() flags.BoolVarP(&cleanupOptions.All, "all", "a", false, "Cleans up all containers") flags.BoolVarP(&cleanupOptions.Latest, "latest", "l", false, "Act on the latest container podman is aware of") - flags.StringVar(&cleanupOptions.Exec, "exec", "", "Clean up the given exec session instead of the container") + + execFlagName := "exec" + flags.StringVar(&cleanupOptions.Exec, execFlagName, "", "Clean up the given exec session instead of the container") + _ = cleanupCommand.RegisterFlagCompletionFunc(execFlagName, completion.AutocompleteNone) + flags.BoolVar(&cleanupOptions.Remove, "rm", false, "After cleanup, remove the container entirely") flags.BoolVar(&cleanupOptions.RemoveImage, "rmi", false, "After cleanup, remove the image entirely") diff --git a/cmd/podman/containers/commit.go b/cmd/podman/containers/commit.go index b3c3d762600b..0dd46d33f340 100644 --- a/cmd/podman/containers/commit.go +++ b/cmd/podman/containers/commit.go @@ -7,6 +7,8 @@ import ( "os" "strings" + "github.com/containers/libpod/cmd/podman/common" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/pkg/errors" @@ -18,11 +20,12 @@ var ( commitDescription = `Create an image from a container's changes. Optionally tag the image created, set the author with the --author flag, set the commit message with the --message flag, and make changes to the instructions with the --change flag.` commitCommand = &cobra.Command{ - Use: "commit [flags] CONTAINER [IMAGE]", - Short: "Create new image based on the changed container", - Long: commitDescription, - RunE: commit, - Args: cobra.MinimumNArgs(1), + Use: "commit [flags] CONTAINER [IMAGE]", + Short: "Create new image based on the changed container", + Long: commitDescription, + RunE: commit, + Args: cobra.MinimumNArgs(1), + ValidArgsFunction: completion.AutocompleteContainers, Example: `podman commit -q --message "committing container to image" reverent_golick image-committed podman commit -q --author "firstName lastName" reverent_golick image-committed podman commit -q --pause=false containerID image-committed @@ -30,19 +33,17 @@ var ( } containerCommitCommand = &cobra.Command{ - Args: cobra.MinimumNArgs(1), - Use: commitCommand.Use, - Short: commitCommand.Short, - Long: commitCommand.Long, - RunE: commitCommand.RunE, + Args: cobra.MinimumNArgs(1), + Use: commitCommand.Use, + Short: commitCommand.Short, + Long: commitCommand.Long, + RunE: commitCommand.RunE, + ValidArgsFunction: commitCommand.ValidArgsFunction, Example: `podman container commit -q --message "committing container to image" reverent_golick image-committed podman container commit -q --author "firstName lastName" reverent_golick image-committed podman container commit -q --pause=false containerID image-committed podman container commit containerID`, } - - // ChangeCmds is the list of valid Changes commands to passed to the Commit call - ChangeCmds = []string{"CMD", "ENTRYPOINT", "ENV", "EXPOSE", "LABEL", "ONBUILD", "STOPSIGNAL", "USER", "VOLUME", "WORKDIR"} ) var ( @@ -53,11 +54,31 @@ var ( ) func commitFlags(flags *pflag.FlagSet) { - flags.StringArrayVarP(&commitOptions.Changes, "change", "c", []string{}, "Apply the following possible instructions to the created image (default []): "+strings.Join(ChangeCmds, " | ")) - flags.StringVarP(&commitOptions.Format, "format", "f", "oci", "`Format` of the image manifest and metadata") - flags.StringVarP(&iidFile, "iidfile", "", "", "`file` to write the image ID to") - flags.StringVarP(&commitOptions.Message, "message", "m", "", "Set commit message for imported image") - flags.StringVarP(&commitOptions.Author, "author", "a", "", "Set the author for the image committed") + changeFlagName := "change" + flags.StringArrayVarP(&commitOptions.Changes, changeFlagName, "c", []string{}, "Apply the following possible instructions to the created image (default []): "+strings.Join(common.ChangeCmds, " | ")) + _ = commitCommand.RegisterFlagCompletionFunc(changeFlagName, completion.AutocompleteChangeInstructions) + _ = containerCommitCommand.RegisterFlagCompletionFunc(changeFlagName, completion.AutocompleteChangeInstructions) + + formatFlagName := "format" + flags.StringVarP(&commitOptions.Format, formatFlagName, "f", "oci", "`Format` of the image manifest and metadata") + _ = commitCommand.RegisterFlagCompletionFunc(formatFlagName, completion.AutocompleteImageFormat) + _ = containerCommitCommand.RegisterFlagCompletionFunc(formatFlagName, completion.AutocompleteImageFormat) + + iidFileFlagName := "iidfile" + flags.StringVarP(&iidFile, iidFileFlagName, "", "", "`file` to write the image ID to") + _ = commitCommand.RegisterFlagCompletionFunc(iidFileFlagName, completion.AutocompleteDefault) + _ = containerCommitCommand.RegisterFlagCompletionFunc(iidFileFlagName, completion.AutocompleteDefault) + + messageFlagName := "message" + flags.StringVarP(&commitOptions.Message, messageFlagName, "m", "", "Set commit message for imported image") + _ = commitCommand.RegisterFlagCompletionFunc(messageFlagName, completion.AutocompleteNone) + _ = containerCommitCommand.RegisterFlagCompletionFunc(messageFlagName, completion.AutocompleteNone) + + authorFlagName := "author" + flags.StringVarP(&commitOptions.Author, authorFlagName, "a", "", "Set the author for the image committed") + _ = commitCommand.RegisterFlagCompletionFunc(authorFlagName, completion.AutocompleteNone) + _ = containerCommitCommand.RegisterFlagCompletionFunc(authorFlagName, completion.AutocompleteNone) + flags.BoolVarP(&commitOptions.Pause, "pause", "p", false, "Pause container during commit") flags.BoolVarP(&commitOptions.Quiet, "quiet", "q", false, "Suppress output") flags.BoolVar(&commitOptions.IncludeVolumes, "include-volumes", false, "Include container volumes as image volumes") diff --git a/cmd/podman/containers/cp.go b/cmd/podman/containers/cp.go index ac70376210dc..bdaca847d892 100644 --- a/cmd/podman/containers/cp.go +++ b/cmd/podman/containers/cp.go @@ -1,6 +1,7 @@ package containers import ( + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/cgroups" "github.com/containers/libpod/pkg/domain/entities" @@ -16,21 +17,23 @@ var ( You can copy from the container's file system to the local machine or the reverse, from the local filesystem to the container. If "-" is specified for either the SRC_PATH or DEST_PATH, you can also stream a tar archive from STDIN or to STDOUT. The CONTAINER can be a running or stopped container. The SRC_PATH or DEST_PATH can be a file or directory. ` cpCommand = &cobra.Command{ - Use: "cp [flags] SRC_PATH DEST_PATH", - Short: "Copy files/folders between a container and the local filesystem", - Long: cpDescription, - Args: cobra.ExactArgs(2), - RunE: cp, - Example: "podman cp [CONTAINER:]SRC_PATH [CONTAINER:]DEST_PATH", + Use: "cp [flags] SRC_PATH DEST_PATH", + Short: "Copy files/folders between a container and the local filesystem", + Long: cpDescription, + Args: cobra.ExactArgs(2), + RunE: cp, + ValidArgsFunction: completion.AutocompleteDefault, + Example: "podman cp [CONTAINER:]SRC_PATH [CONTAINER:]DEST_PATH", } containerCpCommand = &cobra.Command{ - Use: cpCommand.Use, - Short: cpCommand.Short, - Long: cpCommand.Long, - Args: cpCommand.Args, - RunE: cpCommand.RunE, - Example: "podman container cp [CONTAINER:]SRC_PATH [CONTAINER:]DEST_PATH", + Use: cpCommand.Use, + Short: cpCommand.Short, + Long: cpCommand.Long, + Args: cpCommand.Args, + RunE: cpCommand.RunE, + ValidArgsFunction: cpCommand.ValidArgsFunction, + Example: "podman container cp [CONTAINER:]SRC_PATH [CONTAINER:]DEST_PATH", } ) diff --git a/cmd/podman/containers/create.go b/cmd/podman/containers/create.go index c8007bc2f12f..4f92cf3d1ce8 100644 --- a/cmd/podman/containers/create.go +++ b/cmd/podman/containers/create.go @@ -10,6 +10,7 @@ import ( "github.com/containers/common/pkg/config" "github.com/containers/libpod/cmd/podman/common" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/errorhandling" @@ -26,22 +27,24 @@ var ( The container ID is then printed to stdout. You can then start it at any time with the podman start command. The container will be created with the initial state 'created'.` createCommand = &cobra.Command{ - Use: "create [flags] IMAGE [COMMAND [ARG...]]", - Short: "Create but do not start a container", - Long: createDescription, - RunE: create, - Args: cobra.MinimumNArgs(1), + Use: "create [flags] IMAGE [COMMAND [ARG...]]", + Short: "Create but do not start a container", + Long: createDescription, + RunE: create, + Args: cobra.MinimumNArgs(1), + ValidArgsFunction: completion.AutocompleteImages, Example: `podman create alpine ls podman create --annotation HELLO=WORLD alpine ls podman create -t -i --name myctr alpine ls`, } containerCreateCommand = &cobra.Command{ - Args: cobra.MinimumNArgs(1), - Use: createCommand.Use, - Short: createCommand.Short, - Long: createCommand.Long, - RunE: createCommand.RunE, + Args: cobra.MinimumNArgs(1), + Use: createCommand.Use, + Short: createCommand.Short, + Long: createCommand.Long, + RunE: createCommand.RunE, + ValidArgsFunction: createCommand.ValidArgsFunction, Example: `podman container create alpine ls podman container create --annotation HELLO=WORLD alpine ls podman container create -t -i --name myctr alpine ls`, diff --git a/cmd/podman/containers/diff.go b/cmd/podman/containers/diff.go index 59b7880109de..442019542447 100644 --- a/cmd/podman/containers/diff.go +++ b/cmd/podman/containers/diff.go @@ -1,6 +1,7 @@ package containers import ( + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/report" "github.com/containers/libpod/cmd/podman/validate" @@ -12,11 +13,12 @@ import ( var ( // podman container _diff_ diffCmd = &cobra.Command{ - Use: "diff [flags] CONTAINER", - Args: validate.IdOrLatestArgs, - Short: "Inspect changes on container's file systems", - Long: `Displays changes on a container filesystem. The container will be compared to its parent layer.`, - RunE: diff, + Use: "diff [flags] CONTAINER", + Args: validate.IdOrLatestArgs, + Short: "Inspect changes on container's file systems", + Long: `Displays changes on a container filesystem. The container will be compared to its parent layer.`, + RunE: diff, + ValidArgsFunction: completion.AutocompleteContainers, Example: `podman container diff myCtr podman container diff -l --format json myCtr`, } diff --git a/cmd/podman/containers/exec.go b/cmd/podman/containers/exec.go index 7554d6a936a9..ef2c9ac64239 100644 --- a/cmd/podman/containers/exec.go +++ b/cmd/podman/containers/exec.go @@ -5,6 +5,7 @@ import ( "fmt" "os" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/libpod/define" "github.com/containers/libpod/pkg/domain/entities" @@ -23,6 +24,7 @@ var ( Long: execDescription, RunE: exec, DisableFlagsInUseLine: true, + ValidArgsFunction: completion.AutocompleteContainersRunning, Example: `podman exec -it ctrID ls podman exec -it -w /tmp myCtr pwd podman exec --user root ctrID ls`, @@ -34,6 +36,7 @@ var ( Long: execCommand.Long, RunE: execCommand.RunE, DisableFlagsInUseLine: true, + ValidArgsFunction: execCommand.ValidArgsFunction, Example: `podman container exec -it ctrID ls podman container exec -it -w /tmp myCtr pwd podman container exec --user root ctrID ls`, diff --git a/cmd/podman/containers/exists.go b/cmd/podman/containers/exists.go index 81ba8a282f05..afb92cba18ef 100644 --- a/cmd/podman/containers/exists.go +++ b/cmd/podman/containers/exists.go @@ -3,6 +3,7 @@ package containers import ( "context" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/spf13/cobra" @@ -20,6 +21,7 @@ var ( RunE: exists, Args: cobra.ExactArgs(1), DisableFlagsInUseLine: true, + ValidArgsFunction: completion.AutocompleteContainers, } ) diff --git a/cmd/podman/containers/export.go b/cmd/podman/containers/export.go index bbb6a6bc9593..12f79a551ad9 100644 --- a/cmd/podman/containers/export.go +++ b/cmd/podman/containers/export.go @@ -4,6 +4,7 @@ import ( "context" "os" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/parse" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" @@ -18,11 +19,12 @@ var ( " and saves it on the local machine." exportCommand = &cobra.Command{ - Use: "export [flags] CONTAINER", - Short: "Export container's filesystem contents as a tar archive", - Long: exportDescription, - RunE: export, - Args: cobra.ExactArgs(1), + Use: "export [flags] CONTAINER", + Short: "Export container's filesystem contents as a tar archive", + Long: exportDescription, + RunE: export, + Args: cobra.ExactArgs(1), + ValidArgsFunction: completion.AutocompleteContainers, Example: `podman export ctrID > myCtr.tar podman export --output="myCtr.tar" ctrID`, } diff --git a/cmd/podman/containers/init.go b/cmd/podman/containers/init.go index 417f170c39c1..5009d8bcc79e 100644 --- a/cmd/podman/containers/init.go +++ b/cmd/podman/containers/init.go @@ -3,6 +3,7 @@ package containers import ( "fmt" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/parse" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/utils" @@ -22,17 +23,19 @@ var ( Args: func(cmd *cobra.Command, args []string) error { return parse.CheckAllLatestAndCIDFile(cmd, args, false, false) }, + ValidArgsFunction: completion.AutocompleteContainersCreated, //only complete created containers Example: `podman init --latest podman init 3c45ef19d893 podman init test1`, } containerInitCommand = &cobra.Command{ - Use: initCommand.Use, - Short: initCommand.Short, - Long: initCommand.Long, - RunE: initCommand.RunE, - Args: initCommand.Args, + Use: initCommand.Use, + Short: initCommand.Short, + Long: initCommand.Long, + RunE: initCommand.RunE, + Args: initCommand.Args, + ValidArgsFunction: initCommand.ValidArgsFunction, Example: `podman container init --latest podman container init 3c45ef19d893 podman container init test1`, diff --git a/cmd/podman/containers/inspect.go b/cmd/podman/containers/inspect.go index 4549a4ef641f..2005fc731a0d 100644 --- a/cmd/podman/containers/inspect.go +++ b/cmd/podman/containers/inspect.go @@ -1,6 +1,7 @@ package containers import ( + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/inspect" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" @@ -10,10 +11,11 @@ import ( var ( // podman container _inspect_ inspectCmd = &cobra.Command{ - Use: "inspect [flags] CONTAINER", - Short: "Display the configuration of a container", - Long: `Displays the low-level information on a container identified by name or ID.`, - RunE: inspectExec, + Use: "inspect [flags] CONTAINER", + Short: "Display the configuration of a container", + Long: `Displays the low-level information on a container identified by name or ID.`, + RunE: inspectExec, + ValidArgsFunction: completion.AutocompleteContainers, Example: `podman container inspect myCtr podman container inspect -l --format '{{.Id}} {{.Config.Labels}}'`, } diff --git a/cmd/podman/containers/kill.go b/cmd/podman/containers/kill.go index ef85aad7df9d..a4908bf97e3b 100644 --- a/cmd/podman/containers/kill.go +++ b/cmd/podman/containers/kill.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/parse" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/utils" @@ -24,6 +25,7 @@ var ( Args: func(cmd *cobra.Command, args []string) error { return parse.CheckAllLatestAndCIDFile(cmd, args, false, false) }, + ValidArgsFunction: completion.AutocompleteContainers, Example: `podman kill mywebserver podman kill 860a4b23 podman kill --signal TERM ctrID`, @@ -33,10 +35,11 @@ var ( Args: func(cmd *cobra.Command, args []string) error { return parse.CheckAllLatestAndCIDFile(cmd, args, false, false) }, - Use: killCommand.Use, - Short: killCommand.Short, - Long: killCommand.Long, - RunE: killCommand.RunE, + Use: killCommand.Use, + Short: killCommand.Short, + Long: killCommand.Long, + RunE: killCommand.RunE, + ValidArgsFunction: killCommand.ValidArgsFunction, Example: `podman container kill mywebserver podman container kill 860a4b23 podman container kill --signal TERM ctrID`, diff --git a/cmd/podman/containers/list.go b/cmd/podman/containers/list.go index c200a49aa170..4d8b52d443c6 100644 --- a/cmd/podman/containers/list.go +++ b/cmd/podman/containers/list.go @@ -1,6 +1,7 @@ package containers import ( + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/validate" "github.com/containers/libpod/pkg/domain/entities" @@ -10,12 +11,13 @@ import ( var ( // podman container _list_ listCmd = &cobra.Command{ - Use: "list", - Aliases: []string{"ls"}, - Args: validate.NoArgs, - Short: "List containers", - Long: "Prints out information about the containers", - RunE: ps, + Use: "list", + Aliases: []string{"ls"}, + Args: validate.NoArgs, + Short: "List containers", + Long: "Prints out information about the containers", + RunE: ps, + ValidArgsFunction: completion.AutocompleteNone, Example: `podman container list -a podman container list -a --format "{{.ID}} {{.Image}} {{.Labels}} {{.Mounts}}" podman container list --size --sort names`, diff --git a/cmd/podman/containers/logs.go b/cmd/podman/containers/logs.go index de5234044471..5a68c00a63ec 100644 --- a/cmd/podman/containers/logs.go +++ b/cmd/podman/containers/logs.go @@ -3,6 +3,7 @@ package containers import ( "os" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/util" @@ -40,7 +41,8 @@ var ( } return nil }, - RunE: logs, + RunE: logs, + ValidArgsFunction: completion.AutocompleteContainers, Example: `podman logs ctrID podman logs --names ctrID1 ctrID2 podman logs --tail 2 mywebserver @@ -49,11 +51,12 @@ var ( } containerLogsCommand = &cobra.Command{ - Use: logsCommand.Use, - Short: logsCommand.Short, - Long: logsCommand.Long, - Args: logsCommand.Args, - RunE: logsCommand.RunE, + Use: logsCommand.Use, + Short: logsCommand.Short, + Long: logsCommand.Long, + Args: logsCommand.Args, + RunE: logsCommand.RunE, + ValidArgsFunction: logsCommand.ValidArgsFunction, Example: `podman container logs ctrID podman container logs --names ctrID1 ctrID2 podman container logs --tail 2 mywebserver diff --git a/cmd/podman/containers/mount.go b/cmd/podman/containers/mount.go index af4d52caaa1a..9fc52b3f6253 100644 --- a/cmd/podman/containers/mount.go +++ b/cmd/podman/containers/mount.go @@ -6,6 +6,7 @@ import ( "text/tabwriter" "text/template" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/parse" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/utils" @@ -30,13 +31,15 @@ var ( Args: func(cmd *cobra.Command, args []string) error { return parse.CheckAllLatestAndCIDFile(cmd, args, true, false) }, + ValidArgsFunction: completion.AutocompleteContainers, } containerMountCommmand = &cobra.Command{ - Use: mountCommand.Use, - Short: mountCommand.Short, - Long: mountCommand.Long, - RunE: mountCommand.RunE, + Use: mountCommand.Use, + Short: mountCommand.Short, + Long: mountCommand.Long, + RunE: mountCommand.RunE, + ValidArgsFunction: mountCommand.ValidArgsFunction, } ) diff --git a/cmd/podman/containers/pause.go b/cmd/podman/containers/pause.go index b932c4539fcc..e563c44fe06e 100644 --- a/cmd/podman/containers/pause.go +++ b/cmd/podman/containers/pause.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/pkg/domain/entities" @@ -16,20 +17,22 @@ import ( var ( pauseDescription = `Pauses one or more running containers. The container name or ID can be used.` pauseCommand = &cobra.Command{ - Use: "pause [flags] CONTAINER [CONTAINER...]", - Short: "Pause all the processes in one or more containers", - Long: pauseDescription, - RunE: pause, + Use: "pause [flags] CONTAINER [CONTAINER...]", + Short: "Pause all the processes in one or more containers", + Long: pauseDescription, + RunE: pause, + ValidArgsFunction: completion.AutocompleteContainersRunning, Example: `podman pause mywebserver podman pause 860a4b23 podman pause -a`, } containerPauseCommand = &cobra.Command{ - Use: pauseCommand.Use, - Short: pauseCommand.Short, - Long: pauseCommand.Long, - RunE: pauseCommand.RunE, + Use: pauseCommand.Use, + Short: pauseCommand.Short, + Long: pauseCommand.Long, + RunE: pauseCommand.RunE, + ValidArgsFunction: pauseCommand.ValidArgsFunction, Example: `podman container pause mywebserver podman container pause 860a4b23 podman container pause -a`, diff --git a/cmd/podman/containers/port.go b/cmd/podman/containers/port.go index d058a6aaf7f7..71111a920b32 100644 --- a/cmd/podman/containers/port.go +++ b/cmd/podman/containers/port.go @@ -5,6 +5,7 @@ import ( "strconv" "strings" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/parse" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" @@ -25,19 +26,19 @@ var ( Args: func(cmd *cobra.Command, args []string) error { return parse.CheckAllLatestAndCIDFile(cmd, args, true, false) }, + ValidArgsFunction: completion.AutocompleteContainers, Example: `podman port --all podman port ctrID 80/tcp podman port --latest 80`, } containerPortCommand = &cobra.Command{ - Use: "port [flags] CONTAINER [PORT]", - Short: portCommand.Short, - Long: portDescription, - RunE: portCommand.RunE, - Args: func(cmd *cobra.Command, args []string) error { - return parse.CheckAllLatestAndCIDFile(cmd, args, true, false) - }, + Use: "port [flags] CONTAINER [PORT]", + Short: portCommand.Short, + Long: portDescription, + RunE: portCommand.RunE, + Args: portCommand.Args, + ValidArgsFunction: portCommand.ValidArgsFunction, Example: `podman container port --all podman container port --latest 80`, } diff --git a/cmd/podman/containers/prune.go b/cmd/podman/containers/prune.go index 38168a6e4615..2f4cb05d4143 100644 --- a/cmd/podman/containers/prune.go +++ b/cmd/podman/containers/prune.go @@ -8,6 +8,7 @@ import ( "os" "strings" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/pkg/domain/entities" @@ -20,11 +21,12 @@ var ( Removes all non running containers`) pruneCommand = &cobra.Command{ - Use: "prune [flags]", - Short: "Remove all non running containers", - Long: pruneDescription, - RunE: prune, - Example: `podman container prune`, + Use: "prune [flags]", + Short: "Remove all non running containers", + Long: pruneDescription, + RunE: prune, + ValidArgsFunction: completion.AutocompleteNone, + Example: `podman container prune`, } force bool filter = []string{} @@ -38,7 +40,9 @@ func init() { }) flags := pruneCommand.Flags() flags.BoolVarP(&force, "force", "f", false, "Do not prompt for confirmation. The default is false") - flags.StringArrayVar(&filter, "filter", []string{}, "Provide filter values (e.g. 'label==')") + filterFlagName := "filter" + flags.StringArrayVar(&filter, filterFlagName, []string{}, "Provide filter values (e.g. 'label==')") + _ = pruneCommand.RegisterFlagCompletionFunc(filterFlagName, completion.AutocompleteNone) } func prune(cmd *cobra.Command, args []string) error { diff --git a/cmd/podman/containers/ps.go b/cmd/podman/containers/ps.go index 4d12d2534acd..5aa99c3e0948 100644 --- a/cmd/podman/containers/ps.go +++ b/cmd/podman/containers/ps.go @@ -12,6 +12,7 @@ import ( tm "github.com/buger/goterm" "github.com/containers/buildah/pkg/formats" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/validate" "github.com/containers/libpod/pkg/domain/entities" @@ -25,11 +26,12 @@ import ( var ( psDescription = "Prints out information about the containers" psCommand = &cobra.Command{ - Use: "ps", - Args: validate.NoArgs, - Short: "List containers", - Long: psDescription, - RunE: ps, + Use: "ps", + Args: validate.NoArgs, + Short: "List containers", + Long: psDescription, + RunE: ps, + ValidArgsFunction: completion.AutocompleteNone, Example: `podman ps -a podman ps -a --format "{{.ID}} {{.Image}} {{.Labels}} {{.Mounts}}" podman ps --size --sort names`, diff --git a/cmd/podman/containers/restart.go b/cmd/podman/containers/restart.go index 1a9d7f6c7fa8..c1cbae1ba1b6 100644 --- a/cmd/podman/containers/restart.go +++ b/cmd/podman/containers/restart.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/parse" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/utils" @@ -27,16 +28,18 @@ var ( Args: func(cmd *cobra.Command, args []string) error { return parse.CheckAllLatestAndCIDFile(cmd, args, false, false) }, + ValidArgsFunction: completion.AutocompleteContainers, Example: `podman restart ctrID podman restart --latest podman restart ctrID1 ctrID2`, } containerRestartCommand = &cobra.Command{ - Use: restartCommand.Use, - Short: restartCommand.Short, - Long: restartCommand.Long, - RunE: restartCommand.RunE, + Use: restartCommand.Use, + Short: restartCommand.Short, + Long: restartCommand.Long, + RunE: restartCommand.RunE, + ValidArgsFunction: restartCommand.ValidArgsFunction, Example: `podman container restart ctrID podman container restart --latest podman container restart ctrID1 ctrID2`, diff --git a/cmd/podman/containers/restore.go b/cmd/podman/containers/restore.go index 3bc17206a38e..a258878a81e6 100644 --- a/cmd/podman/containers/restore.go +++ b/cmd/podman/containers/restore.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/parse" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/utils" @@ -27,6 +28,7 @@ var ( Args: func(cmd *cobra.Command, args []string) error { return parse.CheckAllLatestAndCIDFile(cmd, args, true, false) }, + ValidArgsFunction: completion.AutocompleteContainers, Example: `podman container restore ctrID podman container restore --latest podman container restore --all`, @@ -48,8 +50,15 @@ func init() { flags.BoolVarP(&restoreOptions.Keep, "keep", "k", false, "Keep all temporary checkpoint files") flags.BoolVarP(&restoreOptions.Latest, "latest", "l", false, "Act on the latest container podman is aware of") flags.BoolVar(&restoreOptions.TCPEstablished, "tcp-established", false, "Restore a container with established TCP connections") - flags.StringVarP(&restoreOptions.Import, "import", "i", "", "Restore from exported checkpoint archive (tar.gz)") - flags.StringVarP(&restoreOptions.Name, "name", "n", "", "Specify new name for container restored from exported checkpoint (only works with --import)") + + importFlagName := "import" + flags.StringVarP(&restoreOptions.Import, importFlagName, "i", "", "Restore from exported checkpoint archive (tar.gz)") + _ = restoreCommand.RegisterFlagCompletionFunc(importFlagName, completion.AutocompleteDefault) + + nameFlagName := "name" + flags.StringVarP(&restoreOptions.Name, nameFlagName, "n", "", "Specify new name for container restored from exported checkpoint (only works with --import)") + _ = restoreCommand.RegisterFlagCompletionFunc(nameFlagName, completion.AutocompleteNone) + flags.BoolVar(&restoreOptions.IgnoreRootFS, "ignore-rootfs", false, "Do not apply root file-system changes when importing from exported checkpoint") flags.BoolVar(&restoreOptions.IgnoreStaticIP, "ignore-static-ip", false, "Ignore IP address set via --static-ip") flags.BoolVar(&restoreOptions.IgnoreStaticMAC, "ignore-static-mac", false, "Ignore MAC address set via --mac-address") diff --git a/cmd/podman/containers/rm.go b/cmd/podman/containers/rm.go index b25473a8d3d9..b483a21cb043 100644 --- a/cmd/podman/containers/rm.go +++ b/cmd/podman/containers/rm.go @@ -5,6 +5,7 @@ import ( "fmt" "strings" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/parse" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/utils" @@ -28,6 +29,7 @@ var ( Args: func(cmd *cobra.Command, args []string) error { return parse.CheckAllLatestAndCIDFile(cmd, args, false, true) }, + ValidArgsFunction: completion.AutocompleteContainers, Example: `podman rm imageID podman rm mywebserver myflaskserver 860a4b23 podman rm --force --all @@ -35,13 +37,12 @@ var ( } containerRmCommand = &cobra.Command{ - Use: rmCommand.Use, - Short: rmCommand.Short, - Long: rmCommand.Long, - RunE: rmCommand.RunE, - Args: func(cmd *cobra.Command, args []string) error { - return parse.CheckAllLatestAndCIDFile(cmd, args, false, true) - }, + Use: rmCommand.Use, + Short: rmCommand.Short, + Long: rmCommand.Long, + RunE: rmCommand.RunE, + Args: rmCommand.Args, + ValidArgsFunction: rmCommand.ValidArgsFunction, Example: `podman container rm imageID podman container rm mywebserver myflaskserver 860a4b23 podman container rm --force --all diff --git a/cmd/podman/containers/run.go b/cmd/podman/containers/run.go index 890c6e827423..167595b4dd77 100644 --- a/cmd/podman/containers/run.go +++ b/cmd/podman/containers/run.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/containers/libpod/cmd/podman/common" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/libpod/define" "github.com/containers/libpod/pkg/domain/entities" @@ -20,22 +21,24 @@ import ( var ( runDescription = "Runs a command in a new container from the given image" runCommand = &cobra.Command{ - Args: cobra.MinimumNArgs(1), - Use: "run [flags] IMAGE [COMMAND [ARG...]]", - Short: "Run a command in a new container", - Long: runDescription, - RunE: run, + Args: cobra.MinimumNArgs(1), + Use: "run [flags] IMAGE [COMMAND [ARG...]]", + Short: "Run a command in a new container", + Long: runDescription, + RunE: run, + ValidArgsFunction: completion.AutocompleteImages, Example: `podman run imageID ls -alF /etc podman run --network=host imageID dnf -y install java podman run --volume /var/hostdir:/var/ctrdir -i -t fedora /bin/bash`, } containerRunCommand = &cobra.Command{ - Args: cobra.MinimumNArgs(1), - Use: runCommand.Use, - Short: runCommand.Short, - Long: runCommand.Long, - RunE: runCommand.RunE, + Args: cobra.MinimumNArgs(1), + Use: runCommand.Use, + Short: runCommand.Short, + Long: runCommand.Long, + RunE: runCommand.RunE, + ValidArgsFunction: runCommand.ValidArgsFunction, Example: `podman container run imageID ls -alF /etc podman container run --network=host imageID dnf -y install java podman container run --volume /var/hostdir:/var/ctrdir -i -t fedora /bin/bash`, diff --git a/cmd/podman/containers/runlabel.go b/cmd/podman/containers/runlabel.go index 8d1c48ad2b5c..e26b7fac61ff 100644 --- a/cmd/podman/containers/runlabel.go +++ b/cmd/podman/containers/runlabel.go @@ -6,6 +6,7 @@ import ( "github.com/containers/common/pkg/auth" "github.com/containers/image/v5/types" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/pkg/errors" @@ -24,11 +25,12 @@ var ( runlabelOptions = runlabelOptionsWrapper{} runlabelDescription = "Executes a command as described by a container image label." runlabelCommand = &cobra.Command{ - Use: "runlabel [flags] LABEL IMAGE [ARG...]", - Short: "Execute the command described by an image label", - Long: runlabelDescription, - RunE: runlabel, - Args: cobra.MinimumNArgs(2), + Use: "runlabel [flags] LABEL IMAGE [ARG...]", + Short: "Execute the command described by an image label", + Long: runlabelDescription, + RunE: runlabel, + Args: cobra.MinimumNArgs(2), + ValidArgsFunction: completion.AutocompleteImages, Example: `podman container runlabel run imageID podman container runlabel --pull install imageID arg1 arg2 podman container runlabel --display run myImage`, @@ -43,11 +45,25 @@ func init() { }) flags := runlabelCommand.Flags() - flags.StringVar(&runlabelOptions.Authfile, "authfile", auth.GetDefaultAuthFile(), "Path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override") - flags.StringVar(&runlabelOptions.CertDir, "cert-dir", "", "`Pathname` of a directory containing TLS certificates and keys") - flags.StringVar(&runlabelOptions.Credentials, "creds", "", "`Credentials` (USERNAME:PASSWORD) to use for authenticating to a registry") + + authfileflagName := "authfile" + flags.StringVar(&runlabelOptions.Authfile, authfileflagName, auth.GetDefaultAuthFile(), "Path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override") + _ = runlabelCommand.RegisterFlagCompletionFunc(authfileflagName, completion.AutocompleteDefault) + + certDirFlagName := "cert-dir" + flags.StringVar(&runlabelOptions.CertDir, certDirFlagName, "", "`Pathname` of a directory containing TLS certificates and keys") + _ = runlabelCommand.RegisterFlagCompletionFunc(certDirFlagName, completion.AutocompleteDefault) + + credsFlagName := "creds" + flags.StringVar(&runlabelOptions.Credentials, credsFlagName, "", "`Credentials` (USERNAME:PASSWORD) to use for authenticating to a registry") + _ = runlabelCommand.RegisterFlagCompletionFunc(credsFlagName, completion.AutocompleteNone) + flags.BoolVar(&runlabelOptions.Display, "display", false, "Preview the command that the label would run") - flags.StringVarP(&runlabelOptions.Name, "name", "n", "", "Assign a name to the container") + + nameFlagName := "name" + flags.StringVarP(&runlabelOptions.Name, nameFlagName, "n", "", "Assign a name to the container") + _ = runlabelCommand.RegisterFlagCompletionFunc(nameFlagName, completion.AutocompleteNone) + flags.StringVar(&runlabelOptions.Optional1, "opt1", "", "Optional parameter to pass for install") flags.StringVar(&runlabelOptions.Optional2, "opt2", "", "Optional parameter to pass for install") flags.StringVar(&runlabelOptions.Optional3, "opt3", "", "Optional parameter to pass for install") diff --git a/cmd/podman/containers/start.go b/cmd/podman/containers/start.go index 751fec65f209..b9f6bd224108 100644 --- a/cmd/podman/containers/start.go +++ b/cmd/podman/containers/start.go @@ -4,6 +4,7 @@ import ( "fmt" "os" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/libpod/define" @@ -16,20 +17,22 @@ import ( var ( startDescription = `Starts one or more containers. The container name or ID can be used.` startCommand = &cobra.Command{ - Use: "start [flags] CONTAINER [CONTAINER...]", - Short: "Start one or more containers", - Long: startDescription, - RunE: start, + Use: "start [flags] CONTAINER [CONTAINER...]", + Short: "Start one or more containers", + Long: startDescription, + RunE: start, + ValidArgsFunction: completion.AutocompleteContainersStartable, Example: `podman start --latest podman start 860a4b231279 5421ab43b45 podman start --interactive --attach imageID`, } containerStartCommand = &cobra.Command{ - Use: startCommand.Use, - Short: startCommand.Short, - Long: startCommand.Long, - RunE: startCommand.RunE, + Use: startCommand.Use, + Short: startCommand.Short, + Long: startCommand.Long, + RunE: startCommand.RunE, + ValidArgsFunction: startCommand.ValidArgsFunction, Example: `podman container start --latest podman container start 860a4b231279 5421ab43b45 podman container start --interactive --attach imageID`, diff --git a/cmd/podman/containers/stats.go b/cmd/podman/containers/stats.go index c61b161e465b..a947bb237138 100644 --- a/cmd/podman/containers/stats.go +++ b/cmd/podman/containers/stats.go @@ -9,6 +9,7 @@ import ( "text/template" tm "github.com/buger/goterm" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/libpod/define" "github.com/containers/libpod/pkg/cgroups" @@ -25,22 +26,24 @@ import ( var ( statsDescription = "Display percentage of CPU, memory, network I/O, block I/O and PIDs for one or more containers." statsCommand = &cobra.Command{ - Use: "stats [flags] [CONTAINER...]", - Short: "Display a live stream of container resource usage statistics", - Long: statsDescription, - RunE: stats, - Args: checkStatOptions, + Use: "stats [flags] [CONTAINER...]", + Short: "Display a live stream of container resource usage statistics", + Long: statsDescription, + RunE: stats, + Args: checkStatOptions, + ValidArgsFunction: completion.AutocompleteContainersRunning, Example: `podman stats --all --no-stream podman stats ctrID podman stats --no-stream --format "table {{.ID}} {{.Name}} {{.MemUsage}}" ctrID`, } containerStatsCommand = &cobra.Command{ - Use: statsCommand.Use, - Short: statsCommand.Short, - Long: statsCommand.Long, - RunE: statsCommand.RunE, - Args: checkStatOptions, + Use: statsCommand.Use, + Short: statsCommand.Short, + Long: statsCommand.Long, + RunE: statsCommand.RunE, + Args: checkStatOptions, + ValidArgsFunction: statsCommand.ValidArgsFunction, Example: `podman container stats --all --no-stream podman container stats ctrID podman container stats --no-stream --format "table {{.ID}} {{.Name}} {{.MemUsage}}" ctrID`, diff --git a/cmd/podman/containers/stop.go b/cmd/podman/containers/stop.go index 22c4879611c4..0001eb807e79 100644 --- a/cmd/podman/containers/stop.go +++ b/cmd/podman/containers/stop.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/parse" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/utils" @@ -24,19 +25,19 @@ var ( Args: func(cmd *cobra.Command, args []string) error { return parse.CheckAllLatestAndCIDFile(cmd, args, false, true) }, + ValidArgsFunction: completion.AutocompleteContainersRunning, Example: `podman stop ctrID podman stop --latest podman stop --time 2 mywebserver 6e534f14da9d`, } containerStopCommand = &cobra.Command{ - Use: stopCommand.Use, - Short: stopCommand.Short, - Long: stopCommand.Long, - RunE: stopCommand.RunE, - Args: func(cmd *cobra.Command, args []string) error { - return parse.CheckAllLatestAndCIDFile(cmd, args, false, true) - }, + Use: stopCommand.Use, + Short: stopCommand.Short, + Long: stopCommand.Long, + RunE: stopCommand.RunE, + Args: stopCommand.Args, + ValidArgsFunction: stopCommand.ValidArgsFunction, Example: `podman container stop ctrID podman container stop --latest podman container stop --time 2 mywebserver 6e534f14da9d`, diff --git a/cmd/podman/containers/top.go b/cmd/podman/containers/top.go index d2b11ec77c92..c50fbd5f3588 100644 --- a/cmd/podman/containers/top.go +++ b/cmd/podman/containers/top.go @@ -7,6 +7,7 @@ import ( "strings" "text/tabwriter" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/util" @@ -25,11 +26,12 @@ var ( topOptions = entities.TopOptions{} topCommand = &cobra.Command{ - Use: "top [flags] CONTAINER [FORMAT-DESCRIPTORS|ARGS]", - Short: "Display the running processes of a container", - Long: topDescription, - RunE: top, - Args: cobra.ArbitraryArgs, + Use: "top [flags] CONTAINER [FORMAT-DESCRIPTORS|ARGS]", + Short: "Display the running processes of a container", + Long: topDescription, + RunE: top, + Args: cobra.ArbitraryArgs, + ValidArgsFunction: completion.AutocompleteContainersRunning, Example: `podman top ctrID podman top --latest podman top ctrID pid seccomp args %C @@ -37,10 +39,11 @@ podman top ctrID -eo user,pid,comm`, } containerTopCommand = &cobra.Command{ - Use: topCommand.Use, - Short: topCommand.Short, - Long: topCommand.Long, - RunE: topCommand.RunE, + Use: topCommand.Use, + Short: topCommand.Short, + Long: topCommand.Long, + RunE: topCommand.RunE, + ValidArgsFunction: topCommand.ValidArgsFunction, Example: `podman container top ctrID podman container top --latest podman container top ctrID pid seccomp args %C diff --git a/cmd/podman/containers/unmount.go b/cmd/podman/containers/unmount.go index c8e551e28b2f..22b272dbedae 100644 --- a/cmd/podman/containers/unmount.go +++ b/cmd/podman/containers/unmount.go @@ -3,6 +3,7 @@ package containers import ( "fmt" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/parse" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/utils" @@ -27,19 +28,19 @@ var ( Args: func(cmd *cobra.Command, args []string) error { return parse.CheckAllLatestAndCIDFile(cmd, args, false, false) }, + ValidArgsFunction: completion.AutocompleteContainers, Example: `podman umount ctrID podman umount ctrID1 ctrID2 ctrID3 podman umount --all`, } containerUnmountCommand = &cobra.Command{ - Use: umountCommand.Use, - Short: umountCommand.Short, - Long: umountCommand.Long, - RunE: umountCommand.RunE, - Args: func(cmd *cobra.Command, args []string) error { - return parse.CheckAllLatestAndCIDFile(cmd, args, false, false) - }, + Use: umountCommand.Use, + Short: umountCommand.Short, + Long: umountCommand.Long, + RunE: umountCommand.RunE, + Args: umountCommand.Args, + ValidArgsFunction: umountCommand.ValidArgsFunction, Example: `podman container umount ctrID podman container umount ctrID1 ctrID2 ctrID3 podman container umount --all`, diff --git a/cmd/podman/containers/unpause.go b/cmd/podman/containers/unpause.go index 7ea8e13c1f7a..64244432a234 100644 --- a/cmd/podman/containers/unpause.go +++ b/cmd/podman/containers/unpause.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/pkg/domain/entities" @@ -16,20 +17,22 @@ import ( var ( unpauseDescription = `Unpauses one or more previously paused containers. The container name or ID can be used.` unpauseCommand = &cobra.Command{ - Use: "unpause [flags] CONTAINER [CONTAINER...]", - Short: "Unpause the processes in one or more containers", - Long: unpauseDescription, - RunE: unpause, + Use: "unpause [flags] CONTAINER [CONTAINER...]", + Short: "Unpause the processes in one or more containers", + Long: unpauseDescription, + RunE: unpause, + ValidArgsFunction: completion.AutocompleteContainersPaused, Example: `podman unpause ctrID podman unpause --all`, } unPauseOptions = entities.PauseUnPauseOptions{} containerUnpauseCommand = &cobra.Command{ - Use: unpauseCommand.Use, - Short: unpauseCommand.Short, - Long: unpauseCommand.Long, - RunE: unpauseCommand.RunE, + Use: unpauseCommand.Use, + Short: unpauseCommand.Short, + Long: unpauseCommand.Long, + RunE: unpauseCommand.RunE, + ValidArgsFunction: unpauseCommand.ValidArgsFunction, Example: `podman container unpause ctrID podman container unpause --all`, } diff --git a/cmd/podman/containers/wait.go b/cmd/podman/containers/wait.go index 1f4d4159bb10..5e5f91773d5b 100644 --- a/cmd/podman/containers/wait.go +++ b/cmd/podman/containers/wait.go @@ -5,6 +5,7 @@ import ( "fmt" "time" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/cmd/podman/validate" @@ -19,22 +20,24 @@ var ( waitDescription = `Block until one or more containers stop and then print their exit codes. ` waitCommand = &cobra.Command{ - Use: "wait [flags] CONTAINER [CONTAINER...]", - Short: "Block on one or more containers", - Long: waitDescription, - RunE: wait, - Args: validate.IdOrLatestArgs, + Use: "wait [flags] CONTAINER [CONTAINER...]", + Short: "Block on one or more containers", + Long: waitDescription, + RunE: wait, + Args: validate.IdOrLatestArgs, + ValidArgsFunction: completion.AutocompleteContainers, Example: `podman wait --latest podman wait --interval 5000 ctrID podman wait ctrID1 ctrID2`, } containerWaitCommand = &cobra.Command{ - Use: waitCommand.Use, - Short: waitCommand.Short, - Long: waitCommand.Long, - RunE: waitCommand.RunE, - Args: validate.IdOrLatestArgs, + Use: waitCommand.Use, + Short: waitCommand.Short, + Long: waitCommand.Long, + RunE: waitCommand.RunE, + ValidArgsFunction: waitCommand.ValidArgsFunction, + Args: validate.IdOrLatestArgs, Example: `podman container wait --latest podman container wait --interval 5000 ctrID podman container wait ctrID1 ctrID2`, diff --git a/cmd/podman/diff.go b/cmd/podman/diff.go index 1ff2fce40fbc..cbd7c744e0e9 100644 --- a/cmd/podman/diff.go +++ b/cmd/podman/diff.go @@ -3,6 +3,7 @@ package main import ( "fmt" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/containers" "github.com/containers/libpod/cmd/podman/images" "github.com/containers/libpod/cmd/podman/registry" @@ -17,12 +18,13 @@ var ( // Command: podman _diff_ Object_ID diffDescription = `Displays changes on a container or image's filesystem. The container or image will be compared to its parent layer.` diffCmd = &cobra.Command{ - Use: "diff [flags] {CONTAINER_ID | IMAGE_ID}", - Args: validate.IdOrLatestArgs, - Short: "Display the changes of object's file system", - Long: diffDescription, - TraverseChildren: true, - RunE: diff, + Use: "diff [flags] {CONTAINER_ID | IMAGE_ID}", + Args: validate.IdOrLatestArgs, + Short: "Display the changes of object's file system", + Long: diffDescription, + TraverseChildren: true, + RunE: diff, + ValidArgsFunction: completion.AutocompleteContainersAndImages, Example: `podman diff imageID podman diff ctrID podman diff --format json redis:alpine`, diff --git a/cmd/podman/generate/kube.go b/cmd/podman/generate/kube.go index 86a9cc686a4e..cc0f6878e7fc 100644 --- a/cmd/podman/generate/kube.go +++ b/cmd/podman/generate/kube.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "os" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/pkg/domain/entities" @@ -20,11 +21,12 @@ var ( Whether the input is for a container or pod, Podman will always generate the specification as a pod.` kubeCmd = &cobra.Command{ - Use: "kube [flags] CONTAINER | POD", - Short: "Generate Kubernetes YAML from a container or pod.", - Long: kubeDescription, - RunE: kube, - Args: cobra.ExactArgs(1), + Use: "kube [flags] CONTAINER | POD", + Short: "Generate Kubernetes YAML from a container or pod.", + Long: kubeDescription, + RunE: kube, + Args: cobra.ExactArgs(1), + ValidArgsFunction: completion.AutocompleteContainersAndPods, Example: `podman generate kube ctrID podman generate kube podID podman generate kube --service podID`, diff --git a/cmd/podman/generate/systemd.go b/cmd/podman/generate/systemd.go index 75031e070544..51a2b2966486 100644 --- a/cmd/podman/generate/systemd.go +++ b/cmd/podman/generate/systemd.go @@ -3,6 +3,7 @@ package pods import ( "fmt" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/pkg/domain/entities" @@ -16,11 +17,12 @@ var ( The generated units can later be controlled via systemctl(1).` systemdCmd = &cobra.Command{ - Use: "systemd [flags] CTR|POD", - Short: "Generate systemd units.", - Long: systemdDescription, - RunE: systemd, - Args: cobra.MinimumNArgs(1), + Use: "systemd [flags] CTR|POD", + Short: "Generate systemd units.", + Long: systemdDescription, + RunE: systemd, + Args: cobra.MinimumNArgs(1), + ValidArgsFunction: completion.AutocompleteContainersAndPods, Example: `podman generate systemd CTR podman generate systemd --new --time 10 CTR podman generate systemd --files --name POD`, @@ -37,11 +39,15 @@ func init() { flags.BoolVarP(&systemdOptions.Name, "name", "n", false, "Use container/pod names instead of IDs") flags.BoolVarP(&systemdOptions.Files, "files", "f", false, "Generate .service files instead of printing to stdout") flags.UintVarP(&systemdTimeout, "time", "t", containerConfig.Engine.StopTimeout, "Stop timeout override") - flags.StringVar(&systemdOptions.RestartPolicy, "restart-policy", "on-failure", "Systemd restart-policy") flags.BoolVarP(&systemdOptions.New, "new", "", false, "Create a new container instead of starting an existing one") flags.StringVar(&systemdOptions.ContainerPrefix, "container-prefix", "container", "Systemd unit name prefix for containers") flags.StringVar(&systemdOptions.PodPrefix, "pod-prefix", "pod", "Systemd unit name prefix for pods") flags.StringVar(&systemdOptions.Separator, "separator", "-", "Systemd unit name seperator between name/id and prefix") + + restartPolicyFlagName := "restart-policy" + flags.StringVar(&systemdOptions.RestartPolicy, restartPolicyFlagName, "on-failure", "Systemd restart-policy") + _ = systemdCmd.RegisterFlagCompletionFunc(restartPolicyFlagName, completion.AutocompleteSystemdRestartOptions) + flags.SetNormalizeFunc(utils.AliasFlags) } diff --git a/cmd/podman/healthcheck/run.go b/cmd/podman/healthcheck/run.go index 5612910cb6cb..516a25a3cb69 100644 --- a/cmd/podman/healthcheck/run.go +++ b/cmd/podman/healthcheck/run.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/spf13/cobra" @@ -12,12 +13,13 @@ import ( var ( healthcheckRunDescription = "run the health check of a container" healthcheckrunCommand = &cobra.Command{ - Use: "run [flags] CONTAINER", - Short: "run the health check of a container", - Long: healthcheckRunDescription, - Example: `podman healthcheck run mywebapp`, - RunE: run, - Args: cobra.ExactArgs(1), + Use: "run [flags] CONTAINER", + Short: "run the health check of a container", + Long: healthcheckRunDescription, + Example: `podman healthcheck run mywebapp`, + RunE: run, + ValidArgsFunction: completion.AutocompleteContainers, + Args: cobra.ExactArgs(1), } ) diff --git a/cmd/podman/images/build.go b/cmd/podman/images/build.go index 2efc795cd486..2b7e2a32fee2 100644 --- a/cmd/podman/images/build.go +++ b/cmd/podman/images/build.go @@ -9,6 +9,7 @@ import ( "github.com/containers/buildah/imagebuildah" buildahCLI "github.com/containers/buildah/pkg/cli" "github.com/containers/buildah/pkg/parse" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/pkg/domain/entities" @@ -39,22 +40,24 @@ var ( // Command: podman _diff_ Object_ID buildDescription = "Builds an OCI or Docker image using instructions from one or more Containerfiles and a specified build context directory." buildCmd = &cobra.Command{ - Use: "build [flags] [CONTEXT]", - Short: "Build an image using instructions from Containerfiles", - Long: buildDescription, - TraverseChildren: true, - RunE: build, + Use: "build [flags] [CONTEXT]", + Short: "Build an image using instructions from Containerfiles", + Long: buildDescription, + TraverseChildren: true, + RunE: build, + ValidArgsFunction: completion.AutocompleteDefault, Example: `podman build . podman build --creds=username:password -t imageName -f Containerfile.simple . podman build --layers --force-rm --tag imageName .`, } imageBuildCmd = &cobra.Command{ - Args: buildCmd.Args, - Use: buildCmd.Use, - Short: buildCmd.Short, - Long: buildCmd.Long, - RunE: buildCmd.RunE, + Args: buildCmd.Args, + Use: buildCmd.Use, + Short: buildCmd.Short, + Long: buildCmd.Long, + RunE: buildCmd.RunE, + ValidArgsFunction: buildCmd.ValidArgsFunction, Example: `podman image build . podman image build --creds=username:password -t imageName -f Containerfile.simple . podman image build --layers --force-rm --tag imageName .`, diff --git a/cmd/podman/images/diff.go b/cmd/podman/images/diff.go index c24f98369965..2537a1eac386 100644 --- a/cmd/podman/images/diff.go +++ b/cmd/podman/images/diff.go @@ -1,6 +1,7 @@ package images import ( + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/report" "github.com/containers/libpod/pkg/domain/entities" @@ -12,11 +13,12 @@ import ( var ( // podman container _inspect_ diffCmd = &cobra.Command{ - Use: "diff [flags] IMAGE", - Args: cobra.ExactArgs(1), - Short: "Inspect changes on image's file systems", - Long: `Displays changes on a image's filesystem. The image will be compared to its parent layer.`, - RunE: diff, + Use: "diff [flags] IMAGE", + Args: cobra.ExactArgs(1), + Short: "Inspect changes on image's file systems", + Long: `Displays changes on a image's filesystem. The image will be compared to its parent layer.`, + RunE: diff, + ValidArgsFunction: completion.AutocompleteImages, Example: `podman image diff myImage podman image diff --format json redis:alpine`, } diff --git a/cmd/podman/images/exists.go b/cmd/podman/images/exists.go index 13191113fd5f..e32079c80839 100644 --- a/cmd/podman/images/exists.go +++ b/cmd/podman/images/exists.go @@ -1,6 +1,7 @@ package images import ( + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/spf13/cobra" @@ -8,11 +9,12 @@ import ( var ( existsCmd = &cobra.Command{ - Use: "exists IMAGE", - Short: "Check if an image exists in local storage", - Long: `If the named image exists in local storage, podman image exists exits with 0, otherwise the exit code will be 1.`, - Args: cobra.ExactArgs(1), - RunE: exists, + Use: "exists IMAGE", + Short: "Check if an image exists in local storage", + Long: `If the named image exists in local storage, podman image exists exits with 0, otherwise the exit code will be 1.`, + Args: cobra.ExactArgs(1), + RunE: exists, + ValidArgsFunction: completion.AutocompleteImages, Example: `podman image exists ID podman image exists IMAGE && podman pull IMAGE`, DisableFlagsInUseLine: true, diff --git a/cmd/podman/images/history.go b/cmd/podman/images/history.go index 17a80557e091..92ff031d28fb 100644 --- a/cmd/podman/images/history.go +++ b/cmd/podman/images/history.go @@ -10,6 +10,7 @@ import ( "time" "unicode" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/docker/go-units" @@ -25,21 +26,23 @@ var ( // podman _history_ historyCmd = &cobra.Command{ - Use: "history [flags] IMAGE", - Short: "Show history of a specified image", - Long: long, - Example: "podman history quay.io/fedora/fedora", - Args: cobra.ExactArgs(1), - RunE: history, + Use: "history [flags] IMAGE", + Short: "Show history of a specified image", + Long: long, + Example: "podman history quay.io/fedora/fedora", + Args: cobra.ExactArgs(1), + ValidArgsFunction: completion.AutocompleteImages, + RunE: history, } imageHistoryCmd = &cobra.Command{ - Args: historyCmd.Args, - Use: historyCmd.Use, - Short: historyCmd.Short, - Long: historyCmd.Long, - RunE: historyCmd.RunE, - Example: `podman image history imageID`, + Args: historyCmd.Args, + Use: historyCmd.Use, + Short: historyCmd.Short, + Long: historyCmd.Long, + RunE: historyCmd.RunE, + ValidArgsFunction: historyCmd.ValidArgsFunction, + Example: `podman image history imageID`, } opts = struct { diff --git a/cmd/podman/images/images.go b/cmd/podman/images/images.go index 96ef344bf723..3850dedfb16d 100644 --- a/cmd/podman/images/images.go +++ b/cmd/podman/images/images.go @@ -16,6 +16,7 @@ var ( Short: listCmd.Short, Long: listCmd.Long, RunE: listCmd.RunE, + ValidArgsFunction: listCmd.ValidArgsFunction, Example: strings.Replace(listCmd.Example, "podman image list", "podman images", -1), DisableFlagsInUseLine: true, } diff --git a/cmd/podman/images/import.go b/cmd/podman/images/import.go index 0e16128ce9a6..5f40b77b7e9b 100644 --- a/cmd/podman/images/import.go +++ b/cmd/podman/images/import.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/parse" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" @@ -19,21 +20,23 @@ var ( Note remote tar balls can be specified, via web address. Optionally tag the image. You can specify the instructions using the --change option.` importCommand = &cobra.Command{ - Use: "import [flags] PATH [REFERENCE]", - Short: "Import a tarball to create a filesystem image", - Long: importDescription, - RunE: importCon, + Use: "import [flags] PATH [REFERENCE]", + Short: "Import a tarball to create a filesystem image", + Long: importDescription, + RunE: importCon, + ValidArgsFunction: completion.AutocompleteDefault, Example: `podman import http://example.com/ctr.tar url-image cat ctr.tar | podman -q import --message "importing the ctr.tar tarball" - image-imported cat ctr.tar | podman import -`, } imageImportCommand = &cobra.Command{ - Args: cobra.MinimumNArgs(1), - Use: importCommand.Use, - Short: importCommand.Short, - Long: importCommand.Long, - RunE: importCommand.RunE, + Args: cobra.MinimumNArgs(1), + Use: importCommand.Use, + Short: importCommand.Short, + Long: importCommand.Long, + RunE: importCommand.RunE, + ValidArgsFunction: importCommand.ValidArgsFunction, Example: `podman image import http://example.com/ctr.tar url-image cat ctr.tar | podman -q image import --message "importing the ctr.tar tarball" - image-imported cat ctr.tar | podman image import -`, diff --git a/cmd/podman/images/inspect.go b/cmd/podman/images/inspect.go index 8c727eb07c4b..d25828f9be4b 100644 --- a/cmd/podman/images/inspect.go +++ b/cmd/podman/images/inspect.go @@ -1,6 +1,7 @@ package images import ( + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/inspect" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" @@ -10,10 +11,11 @@ import ( var ( // Command: podman image _inspect_ inspectCmd = &cobra.Command{ - Use: "inspect [flags] IMAGE", - Short: "Display the configuration of an image", - Long: `Displays the low-level information of an image identified by name or ID.`, - RunE: inspectExec, + Use: "inspect [flags] IMAGE", + Short: "Display the configuration of an image", + Long: `Displays the low-level information of an image identified by name or ID.`, + RunE: inspectExec, + ValidArgsFunction: completion.AutocompleteImages, Example: `podman inspect alpine podman inspect --format "imageId: {{.Id}} size: {{.Size}}" alpine podman inspect --format "image: {{.ImageName}} driver: {{.Driver}}" myctr`, diff --git a/cmd/podman/images/list.go b/cmd/podman/images/list.go index 4f8948b8b1d0..d55b6486b972 100644 --- a/cmd/podman/images/list.go +++ b/cmd/podman/images/list.go @@ -11,6 +11,7 @@ import ( "time" "unicode" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/docker/go-units" @@ -32,12 +33,13 @@ type listFlagType struct { var ( // Command: podman image _list_ listCmd = &cobra.Command{ - Use: "list [FLAGS] [IMAGE]", - Aliases: []string{"ls"}, - Args: cobra.MaximumNArgs(1), - Short: "List images in local storage", - Long: "Lists images previously pulled to the system or created on the system.", - RunE: images, + Use: "list [FLAGS] [IMAGE]", + Aliases: []string{"ls"}, + Args: cobra.MaximumNArgs(1), + Short: "List images in local storage", + Long: "Lists images previously pulled to the system or created on the system.", + RunE: images, + ValidArgsFunction: completion.AutocompleteImages, Example: `podman image list --format json podman image list --sort repository --format "table {{.ID}} {{.Repository}} {{.Tag}}" podman image list --filter dangling=true`, diff --git a/cmd/podman/images/load.go b/cmd/podman/images/load.go index a984ad81f690..1103c1c6f9a2 100644 --- a/cmd/podman/images/load.go +++ b/cmd/podman/images/load.go @@ -9,6 +9,7 @@ import ( "strings" "github.com/containers/image/v5/docker/reference" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/parse" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" @@ -22,19 +23,21 @@ import ( var ( loadDescription = "Loads an image from a locally stored archive (tar file) into container storage." loadCommand = &cobra.Command{ - Use: "load [flags] [NAME[:TAG]]", - Short: "Load an image from container archive", - Long: loadDescription, - RunE: load, - Args: cobra.MaximumNArgs(1), + Use: "load [flags] [NAME[:TAG]]", + Short: "Load an image from container archive", + Long: loadDescription, + RunE: load, + ValidArgsFunction: completion.AutocompleteNone, + Args: cobra.MaximumNArgs(1), } imageLoadCommand = &cobra.Command{ - Args: cobra.MinimumNArgs(1), - Use: loadCommand.Use, - Short: loadCommand.Short, - Long: loadCommand.Long, - RunE: loadCommand.RunE, + Args: cobra.MinimumNArgs(1), + Use: loadCommand.Use, + Short: loadCommand.Short, + Long: loadCommand.Long, + ValidArgsFunction: loadCommand.ValidArgsFunction, + RunE: loadCommand.RunE, } ) diff --git a/cmd/podman/images/prune.go b/cmd/podman/images/prune.go index 676382a99087..9bbd7766ae77 100644 --- a/cmd/podman/images/prune.go +++ b/cmd/podman/images/prune.go @@ -6,6 +6,7 @@ import ( "os" "strings" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/cmd/podman/validate" @@ -19,12 +20,13 @@ var ( If an image is not being used by a container, it will be removed from the system.` pruneCmd = &cobra.Command{ - Use: "prune", - Args: validate.NoArgs, - Short: "Remove unused images", - Long: pruneDescription, - RunE: prune, - Example: `podman image prune`, + Use: "prune", + Args: validate.NoArgs, + Short: "Remove unused images", + Long: pruneDescription, + RunE: prune, + ValidArgsFunction: completion.AutocompleteNone, + Example: `podman image prune`, } pruneOpts = entities.ImagePruneOptions{} diff --git a/cmd/podman/images/pull.go b/cmd/podman/images/pull.go index 9e137b5d6569..950bac8fcbce 100644 --- a/cmd/podman/images/pull.go +++ b/cmd/podman/images/pull.go @@ -6,6 +6,7 @@ import ( "github.com/containers/common/pkg/auth" "github.com/containers/image/v5/types" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/util" @@ -30,11 +31,12 @@ var ( // Command: podman pull pullCmd = &cobra.Command{ - Use: "pull [flags] IMAGE", - Args: cobra.ExactArgs(1), - Short: "Pull an image from a registry", - Long: pullDescription, - RunE: imagePull, + Use: "pull [flags] IMAGE", + Args: cobra.ExactArgs(1), + Short: "Pull an image from a registry", + Long: pullDescription, + RunE: imagePull, + ValidArgsFunction: completion.AutocompleteImages, Example: `podman pull imageName podman pull fedora:latest`, } @@ -43,11 +45,12 @@ var ( // It's basically a clone of `pullCmd` with the exception of being a // child of the images command. imagesPullCmd = &cobra.Command{ - Use: pullCmd.Use, - Short: pullCmd.Short, - Long: pullCmd.Long, - RunE: pullCmd.RunE, - Args: cobra.ExactArgs(1), + Use: pullCmd.Use, + Short: pullCmd.Short, + Long: pullCmd.Long, + RunE: pullCmd.RunE, + Args: cobra.ExactArgs(1), + ValidArgsFunction: pullCmd.ValidArgsFunction, Example: `podman image pull imageName podman image pull fedora:latest`, } diff --git a/cmd/podman/images/push.go b/cmd/podman/images/push.go index a1614dc7a2c4..bb00036ccc4c 100644 --- a/cmd/podman/images/push.go +++ b/cmd/podman/images/push.go @@ -5,6 +5,7 @@ import ( "github.com/containers/common/pkg/auth" "github.com/containers/image/v5/types" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/util" @@ -29,10 +30,11 @@ var ( // Command: podman push pushCmd = &cobra.Command{ - Use: "push [flags] SOURCE DESTINATION", - Short: "Push an image to a specified destination", - Long: pushDescription, - RunE: imagePush, + Use: "push [flags] SOURCE DESTINATION", + Short: "Push an image to a specified destination", + Long: pushDescription, + RunE: imagePush, + ValidArgsFunction: completion.AutocompleteImages, Example: `podman push imageID docker://registry.example.com/repository:tag podman push imageID oci-archive:/path/to/layout:image:tag`, } @@ -41,10 +43,11 @@ var ( // It's basically a clone of `pushCmd` with the exception of being a // child of the images command. imagePushCmd = &cobra.Command{ - Use: pushCmd.Use, - Short: pushCmd.Short, - Long: pushCmd.Long, - RunE: pushCmd.RunE, + Use: pushCmd.Use, + Short: pushCmd.Short, + Long: pushCmd.Long, + RunE: pushCmd.RunE, + ValidArgsFunction: pushCmd.ValidArgsFunction, Example: `podman image push imageID docker://registry.example.com/repository:tag podman image push imageID oci-archive:/path/to/layout:image:tag`, } diff --git a/cmd/podman/images/rm.go b/cmd/podman/images/rm.go index 4b9920532298..a32340d0fa28 100644 --- a/cmd/podman/images/rm.go +++ b/cmd/podman/images/rm.go @@ -3,6 +3,7 @@ package images import ( "fmt" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/errorhandling" @@ -14,10 +15,11 @@ import ( var ( rmDescription = "Removes one or more previously pulled or locally created images." rmCmd = &cobra.Command{ - Use: "rm [flags] IMAGE [IMAGE...]", - Short: "Removes one or more images from local storage", - Long: rmDescription, - RunE: rm, + Use: "rm [flags] IMAGE [IMAGE...]", + Short: "Removes one or more images from local storage", + Long: rmDescription, + RunE: rm, + ValidArgsFunction: completion.AutocompleteImages, Example: `podman image rm imageID podman image rm --force alpine podman image rm c4dfb1609ee2 93fd78260bd1 c0ed59d05ff7`, diff --git a/cmd/podman/images/rmi.go b/cmd/podman/images/rmi.go index 8e1759ef47a5..84369f12726e 100644 --- a/cmd/podman/images/rmi.go +++ b/cmd/podman/images/rmi.go @@ -10,12 +10,13 @@ import ( var ( rmiCmd = &cobra.Command{ - Use: strings.Replace(rmCmd.Use, "rm ", "rmi ", 1), - Args: rmCmd.Args, - Short: rmCmd.Short, - Long: rmCmd.Long, - RunE: rmCmd.RunE, - Example: strings.Replace(rmCmd.Example, "podman image rm", "podman rmi", -1), + Use: strings.Replace(rmCmd.Use, "rm ", "rmi ", 1), + Args: rmCmd.Args, + Short: rmCmd.Short, + Long: rmCmd.Long, + RunE: rmCmd.RunE, + ValidArgsFunction: rmCmd.ValidArgsFunction, + Example: strings.Replace(rmCmd.Example, "podman image rm", "podman rmi", -1), } ) diff --git a/cmd/podman/images/save.go b/cmd/podman/images/save.go index 56953e41c2df..bda5225ab51a 100644 --- a/cmd/podman/images/save.go +++ b/cmd/podman/images/save.go @@ -7,6 +7,7 @@ import ( "github.com/containers/libpod/libpod/define" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/parse" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" @@ -40,6 +41,7 @@ var ( } return nil }, + ValidArgsFunction: completion.AutocompleteNone, Example: `podman save --quiet -o myimage.tar imageID podman save --format docker-dir -o ubuntu-dir ubuntu podman save > alpine-all.tar alpine:latest`, diff --git a/cmd/podman/images/search.go b/cmd/podman/images/search.go index ccac7e3fec05..f7bc3723b1cf 100644 --- a/cmd/podman/images/search.go +++ b/cmd/podman/images/search.go @@ -8,6 +8,7 @@ import ( "github.com/containers/buildah/pkg/formats" "github.com/containers/common/pkg/auth" "github.com/containers/image/v5/types" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/util/camelcase" @@ -33,11 +34,12 @@ var ( // Command: podman search searchCmd = &cobra.Command{ - Use: "search [flags] TERM", - Short: "Search registry for image", - Long: searchDescription, - RunE: imageSearch, - Args: cobra.ExactArgs(1), + Use: "search [flags] TERM", + Short: "Search registry for image", + Long: searchDescription, + RunE: imageSearch, + Args: cobra.ExactArgs(1), + ValidArgsFunction: completion.AutocompleteImages, Example: `podman search --filter=is-official --limit 3 alpine podman search registry.fedoraproject.org/ # only works with v2 registries podman search --format "table {{.Index}} {{.Name}}" registry.fedoraproject.org/fedora`, @@ -45,12 +47,13 @@ var ( // Command: podman image search imageSearchCmd = &cobra.Command{ - Use: searchCmd.Use, - Short: searchCmd.Short, - Long: searchCmd.Long, - RunE: searchCmd.RunE, - Args: searchCmd.Args, - Annotations: searchCmd.Annotations, + Use: searchCmd.Use, + Short: searchCmd.Short, + Long: searchCmd.Long, + RunE: searchCmd.RunE, + Args: searchCmd.Args, + Annotations: searchCmd.Annotations, + ValidArgsFunction: searchCmd.ValidArgsFunction, Example: `podman image search --filter=is-official --limit 3 alpine podman image search registry.fedoraproject.org/ # only works with v2 registries podman image search --format "table {{.Index}} {{.Name}}" registry.fedoraproject.org/fedora`, diff --git a/cmd/podman/images/sign.go b/cmd/podman/images/sign.go index bd9cf2ea7d0d..55fd8e5dd4e5 100644 --- a/cmd/podman/images/sign.go +++ b/cmd/podman/images/sign.go @@ -3,6 +3,7 @@ package images import ( "os" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/pkg/errors" @@ -12,11 +13,12 @@ import ( var ( signDescription = "Create a signature file that can be used later to verify the image." signCommand = &cobra.Command{ - Use: "sign [flags] IMAGE [IMAGE...]", - Short: "Sign an image", - Long: signDescription, - RunE: sign, - Args: cobra.MinimumNArgs(1), + Use: "sign [flags] IMAGE [IMAGE...]", + Short: "Sign an image", + Long: signDescription, + RunE: sign, + Args: cobra.MinimumNArgs(1), + ValidArgsFunction: completion.AutocompleteImages, Example: `podman image sign --sign-by mykey imageID podman image sign --sign-by mykey --directory ./mykeydir imageID`, } diff --git a/cmd/podman/images/tag.go b/cmd/podman/images/tag.go index dae3416c40fc..4c54459a08e5 100644 --- a/cmd/podman/images/tag.go +++ b/cmd/podman/images/tag.go @@ -1,6 +1,7 @@ package images import ( + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/spf13/cobra" @@ -9,22 +10,24 @@ import ( var ( tagDescription = "Adds one or more additional names to locally-stored image." tagCommand = &cobra.Command{ - Use: "tag [flags] IMAGE TARGET_NAME [TARGET_NAME...]", - Short: "Add an additional name to a local image", - Long: tagDescription, - RunE: tag, - Args: cobra.MinimumNArgs(2), + Use: "tag [flags] IMAGE TARGET_NAME [TARGET_NAME...]", + Short: "Add an additional name to a local image", + Long: tagDescription, + RunE: tag, + Args: cobra.MinimumNArgs(2), + ValidArgsFunction: completion.AutocompleteImages, Example: `podman tag 0e3bbc2 fedora:latest podman tag imageID:latest myNewImage:newTag podman tag httpd myregistryhost:5000/fedora/httpd:v2`, } imageTagCommand = &cobra.Command{ - Args: tagCommand.Args, - Use: tagCommand.Use, - Short: tagCommand.Short, - Long: tagCommand.Long, - RunE: tagCommand.RunE, + Args: tagCommand.Args, + Use: tagCommand.Use, + Short: tagCommand.Short, + Long: tagCommand.Long, + RunE: tagCommand.RunE, + ValidArgsFunction: tagCommand.ValidArgsFunction, Example: `podman image tag 0e3bbc2 fedora:latest podman image tag imageID:latest myNewImage:newTag podman image tag httpd myregistryhost:5000/fedora/httpd:v2`, diff --git a/cmd/podman/images/tree.go b/cmd/podman/images/tree.go index 5e82e9dea0a9..3c1dbd651506 100644 --- a/cmd/podman/images/tree.go +++ b/cmd/podman/images/tree.go @@ -3,6 +3,7 @@ package images import ( "fmt" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/spf13/cobra" @@ -11,12 +12,13 @@ import ( var ( treeDescription = "Prints layer hierarchy of an image in a tree format" treeCmd = &cobra.Command{ - Use: "tree [flags] IMAGE", - Args: cobra.ExactArgs(1), - Short: treeDescription, - Long: treeDescription, - RunE: tree, - Example: "podman image tree alpine:latest", + Use: "tree [flags] IMAGE", + Args: cobra.ExactArgs(1), + Short: treeDescription, + Long: treeDescription, + RunE: tree, + ValidArgsFunction: completion.AutocompleteImages, + Example: "podman image tree alpine:latest", } treeOpts entities.ImageTreeOptions ) diff --git a/cmd/podman/images/trust_set.go b/cmd/podman/images/trust_set.go index 5868f5546a07..3455321b4bae 100644 --- a/cmd/podman/images/trust_set.go +++ b/cmd/podman/images/trust_set.go @@ -1,6 +1,7 @@ package images import ( + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/libpod/image" "github.com/containers/libpod/pkg/domain/entities" @@ -12,12 +13,13 @@ import ( var ( setTrustDescription = "Set default trust policy or add a new trust policy for a registry" setTrustCommand = &cobra.Command{ - Use: "set [flags] REGISTRY", - Short: "Set default trust policy or a new trust policy for a registry", - Long: setTrustDescription, - Example: "", - RunE: setTrust, - Args: cobra.ExactArgs(1), + Use: "set [flags] REGISTRY", + Short: "Set default trust policy or a new trust policy for a registry", + Long: setTrustDescription, + Example: "", + RunE: setTrust, + ValidArgsFunction: completion.AutocompleteRegistries, + Args: cobra.ExactArgs(1), } ) diff --git a/cmd/podman/images/trust_show.go b/cmd/podman/images/trust_show.go index 23ee6c709c13..6a924e921e0b 100644 --- a/cmd/podman/images/trust_show.go +++ b/cmd/podman/images/trust_show.go @@ -6,6 +6,7 @@ import ( "text/tabwriter" "text/template" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/spf13/cobra" @@ -14,11 +15,12 @@ import ( var ( showTrustDescription = "Display trust policy for the system" showTrustCommand = &cobra.Command{ - Use: "show [flags] [REGISTRY]", - Short: "Display trust policy for the system", - Long: showTrustDescription, - RunE: showTrust, - Example: "", + Use: "show [flags] [REGISTRY]", + Short: "Display trust policy for the system", + Long: showTrustDescription, + RunE: showTrust, + ValidArgsFunction: completion.AutocompleteRegistries, + Example: "", } ) diff --git a/cmd/podman/images/untag.go b/cmd/podman/images/untag.go index 266a3f1157e8..5248e191704a 100644 --- a/cmd/podman/images/untag.go +++ b/cmd/podman/images/untag.go @@ -1,6 +1,7 @@ package images import ( + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/spf13/cobra" @@ -8,22 +9,24 @@ import ( var ( untagCommand = &cobra.Command{ - Use: "untag [flags] IMAGE [NAME...]", - Short: "Remove a name from a local image", - Long: "Removes one or more names from a locally-stored image.", - RunE: untag, - Args: cobra.MinimumNArgs(1), + Use: "untag [flags] IMAGE [NAME...]", + Short: "Remove a name from a local image", + Long: "Removes one or more names from a locally-stored image.", + RunE: untag, + Args: cobra.MinimumNArgs(1), + ValidArgsFunction: completion.AutocompleteImages, Example: `podman untag 0e3bbc2 podman untag imageID:latest otherImageName:latest podman untag httpd myregistryhost:5000/fedora/httpd:v2`, } imageUntagCommand = &cobra.Command{ - Args: untagCommand.Args, - Use: untagCommand.Use, - Short: untagCommand.Short, - Long: untagCommand.Long, - RunE: untagCommand.RunE, + Args: untagCommand.Args, + Use: untagCommand.Use, + Short: untagCommand.Short, + Long: untagCommand.Long, + RunE: untagCommand.RunE, + ValidArgsFunction: untagCommand.ValidArgsFunction, Example: `podman image untag 0e3bbc2 podman image untag imageID:latest otherImageName:latest podman image untag httpd myregistryhost:5000/fedora/httpd:v2`, diff --git a/cmd/podman/inspect.go b/cmd/podman/inspect.go index a5fdaedc27f4..729cbba68385 100644 --- a/cmd/podman/inspect.go +++ b/cmd/podman/inspect.go @@ -1,6 +1,7 @@ package main import ( + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/inspect" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" @@ -10,11 +11,12 @@ import ( var ( // Command: podman _inspect_ Object_ID inspectCmd = &cobra.Command{ - Use: "inspect [flags] {CONTAINER_ID | IMAGE_ID}", - Short: "Display the configuration of object denoted by ID", - Long: "Displays the low-level information on an object identified by name or ID", - TraverseChildren: true, - RunE: inspectExec, + Use: "inspect [flags] {CONTAINER_ID | IMAGE_ID}", + Short: "Display the configuration of object denoted by ID", + Long: "Displays the low-level information on an object identified by name or ID", + TraverseChildren: true, + RunE: inspectExec, + ValidArgsFunction: completion.AutocompleteContainersAndImages, Example: `podman inspect fedora podman inspect --type image fedora podman inspect CtrID ImgID diff --git a/cmd/podman/login.go b/cmd/podman/login.go index 92f13d0e7a36..d110a1ba1f1f 100644 --- a/cmd/podman/login.go +++ b/cmd/podman/login.go @@ -6,6 +6,7 @@ import ( "github.com/containers/common/pkg/auth" "github.com/containers/image/v5/types" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/registries" @@ -20,11 +21,12 @@ type loginOptionsWrapper struct { var ( loginOptions = loginOptionsWrapper{} loginCommand = &cobra.Command{ - Use: "login [flags] [REGISTRY]", - Short: "Login to a container registry", - Long: "Login to a container registry on a specified server.", - RunE: login, - Args: cobra.MaximumNArgs(1), + Use: "login [flags] [REGISTRY]", + Short: "Login to a container registry", + Long: "Login to a container registry on a specified server.", + RunE: login, + Args: cobra.MaximumNArgs(1), + ValidArgsFunction: completion.AutocompleteRegistries, Example: `podman login quay.io podman login --username ... --password ... quay.io podman login --authfile dir/auth.json quay.io`, diff --git a/cmd/podman/logout.go b/cmd/podman/logout.go index c016de8aed05..f077fa37a516 100644 --- a/cmd/podman/logout.go +++ b/cmd/podman/logout.go @@ -5,6 +5,7 @@ import ( "github.com/containers/common/pkg/auth" "github.com/containers/image/v5/types" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/registries" @@ -14,11 +15,12 @@ import ( var ( logoutOptions = auth.LogoutOptions{} logoutCommand = &cobra.Command{ - Use: "logout [flags] [REGISTRY]", - Short: "Logout of a container registry", - Long: "Remove the cached username and password for the registry.", - RunE: logout, - Args: cobra.MaximumNArgs(1), + Use: "logout [flags] [REGISTRY]", + Short: "Logout of a container registry", + Long: "Remove the cached username and password for the registry.", + RunE: logout, + Args: cobra.MaximumNArgs(1), + ValidArgsFunction: completion.AutocompleteRegistries, Example: `podman logout quay.io podman logout --authfile dir/auth.json quay.io podman logout --all`, diff --git a/cmd/podman/main.go b/cmd/podman/main.go index 76ec7bc8e75d..ccf15566ee5e 100644 --- a/cmd/podman/main.go +++ b/cmd/podman/main.go @@ -4,6 +4,7 @@ import ( "fmt" "os" + _ "github.com/containers/libpod/cmd/podman/completion" _ "github.com/containers/libpod/cmd/podman/containers" _ "github.com/containers/libpod/cmd/podman/generate" _ "github.com/containers/libpod/cmd/podman/healthcheck" diff --git a/cmd/podman/manifest/add.go b/cmd/podman/manifest/add.go index 38f832fadfae..bbbf6bbc03c3 100644 --- a/cmd/podman/manifest/add.go +++ b/cmd/podman/manifest/add.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/pkg/errors" @@ -17,6 +18,8 @@ var ( Short: "Add images to a manifest list or image index", Long: "Adds an image to a manifest list or image index.", RunE: add, + //TODO change completion function + ValidArgsFunction: completion.AutocompleteNone, Example: `podman manifest add mylist:v1.11 image:v1.11-amd64 podman manifest add mylist:v1.11 transport:imageName`, Args: cobra.ExactArgs(2), diff --git a/cmd/podman/manifest/annotate.go b/cmd/podman/manifest/annotate.go index 82ee1ffdae9a..d73ae1e95a4e 100644 --- a/cmd/podman/manifest/annotate.go +++ b/cmd/podman/manifest/annotate.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/pkg/errors" @@ -13,12 +14,14 @@ import ( var ( manifestAnnotateOpts = entities.ManifestAnnotateOptions{} annotateCmd = &cobra.Command{ - Use: "annotate [flags] LIST IMAGE", - Short: "Add or update information about an entry in a manifest list or image index", - Long: "Adds or updates information about an entry in a manifest list or image index.", - RunE: annotate, - Example: `podman manifest annotate --annotation left=right mylist:v1.11 image:v1.11-amd64`, - Args: cobra.ExactArgs(2), + Use: "annotate [flags] LIST IMAGE", + Short: "Add or update information about an entry in a manifest list or image index", + Long: "Adds or updates information about an entry in a manifest list or image index.", + RunE: annotate, + //TODO change completion function + ValidArgsFunction: completion.AutocompleteNone, + Example: `podman manifest annotate --annotation left=right mylist:v1.11 image:v1.11-amd64`, + Args: cobra.ExactArgs(2), } ) diff --git a/cmd/podman/manifest/create.go b/cmd/podman/manifest/create.go index 9c0097b9062b..758c95911818 100644 --- a/cmd/podman/manifest/create.go +++ b/cmd/podman/manifest/create.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/pkg/errors" @@ -17,6 +18,8 @@ var ( Short: "Create manifest list or image index", Long: "Creates manifest lists or image indexes.", RunE: create, + //TODO change completion function + ValidArgsFunction: completion.AutocompleteNone, Example: `podman manifest create mylist:v1.11 podman manifest create mylist:v1.11 arch-specific-image-to-add podman manifest create --all mylist:v1.11 transport:tagged-image-to-add`, diff --git a/cmd/podman/manifest/inspect.go b/cmd/podman/manifest/inspect.go index 5112aa5b229a..89f65a623669 100644 --- a/cmd/podman/manifest/inspect.go +++ b/cmd/podman/manifest/inspect.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/pkg/errors" @@ -12,12 +13,14 @@ import ( var ( inspectCmd = &cobra.Command{ - Use: "inspect [flags] IMAGE", - Short: "Display the contents of a manifest list or image index", - Long: "Display the contents of a manifest list or image index.", - RunE: inspect, - Example: "podman manifest inspect localhost/list", - Args: cobra.ExactArgs(1), + Use: "inspect [flags] IMAGE", + Short: "Display the contents of a manifest list or image index", + Long: "Display the contents of a manifest list or image index.", + RunE: inspect, + //TODO change completion function + ValidArgsFunction: completion.AutocompleteNone, + Example: "podman manifest inspect localhost/list", + Args: cobra.ExactArgs(1), } ) diff --git a/cmd/podman/manifest/push.go b/cmd/podman/manifest/push.go index a2e68aff1b84..bdcb957426fd 100644 --- a/cmd/podman/manifest/push.go +++ b/cmd/podman/manifest/push.go @@ -3,6 +3,7 @@ package manifest import ( "github.com/containers/common/pkg/auth" "github.com/containers/image/v5/types" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/util" @@ -22,12 +23,14 @@ type manifestPushOptsWrapper struct { var ( manifestPushOpts = manifestPushOptsWrapper{} pushCmd = &cobra.Command{ - Use: "push [flags] SOURCE DESTINATION", - Short: "Push a manifest list or image index to a registry", - Long: "Pushes manifest lists and image indexes to registries.", - RunE: push, - Example: `podman manifest push mylist:v1.11 quay.io/myimagelist`, - Args: cobra.ExactArgs(2), + Use: "push [flags] SOURCE DESTINATION", + Short: "Push a manifest list or image index to a registry", + Long: "Pushes manifest lists and image indexes to registries.", + RunE: push, + //TODO change completion function + ValidArgsFunction: completion.AutocompleteNone, + Example: `podman manifest push mylist:v1.11 quay.io/myimagelist`, + Args: cobra.ExactArgs(2), } ) diff --git a/cmd/podman/manifest/remove.go b/cmd/podman/manifest/remove.go index 4d345efc0d68..b2b7c7ba0a9b 100644 --- a/cmd/podman/manifest/remove.go +++ b/cmd/podman/manifest/remove.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/pkg/errors" @@ -12,12 +13,14 @@ import ( var ( removeCmd = &cobra.Command{ - Use: "remove [flags] LIST IMAGE", - Short: "Remove an entry from a manifest list or image index", - Long: "Removes an image from a manifest list or image index.", - RunE: remove, - Example: `podman manifest remove mylist:v1.11 sha256:15352d97781ffdf357bf3459c037be3efac4133dc9070c2dce7eca7c05c3e736`, - Args: cobra.ExactArgs(2), + Use: "remove [flags] LIST IMAGE", + Short: "Remove an entry from a manifest list or image index", + Long: "Removes an image from a manifest list or image index.", + RunE: remove, + //TODO change completion function + ValidArgsFunction: completion.AutocompleteNone, + Example: `podman manifest remove mylist:v1.11 sha256:15352d97781ffdf357bf3459c037be3efac4133dc9070c2dce7eca7c05c3e736`, + Args: cobra.ExactArgs(2), } ) diff --git a/cmd/podman/networks/create.go b/cmd/podman/networks/create.go index 5d28c714058c..03861463fefc 100644 --- a/cmd/podman/networks/create.go +++ b/cmd/podman/networks/create.go @@ -4,6 +4,7 @@ import ( "fmt" "net" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/libpod/define" "github.com/containers/libpod/pkg/domain/entities" @@ -16,11 +17,12 @@ import ( var ( networkCreateDescription = `create CNI networks for containers and pods` networkCreateCommand = &cobra.Command{ - Use: "create [flags] [NETWORK]", - Short: "network create", - Long: networkCreateDescription, - RunE: networkCreate, - Example: `podman network create podman1`, + Use: "create [flags] [NETWORK]", + Short: "network create", + Long: networkCreateDescription, + RunE: networkCreate, + ValidArgsFunction: completion.AutocompleteNone, + Example: `podman network create podman1`, Annotations: map[string]string{ registry.ParentNSRequired: "", }, diff --git a/cmd/podman/networks/inspect.go b/cmd/podman/networks/inspect.go index 1b2e899097da..e56a8a7faea1 100644 --- a/cmd/podman/networks/inspect.go +++ b/cmd/podman/networks/inspect.go @@ -8,6 +8,7 @@ import ( "os" "strings" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/spf13/cobra" @@ -16,12 +17,13 @@ import ( var ( networkinspectDescription = `Inspect network` networkinspectCommand = &cobra.Command{ - Use: "inspect NETWORK [NETWORK...] [flags] ", - Short: "network inspect", - Long: networkinspectDescription, - RunE: networkInspect, - Example: `podman network inspect podman`, - Args: cobra.MinimumNArgs(1), + Use: "inspect NETWORK [NETWORK...] [flags] ", + Short: "network inspect", + Long: networkinspectDescription, + RunE: networkInspect, + ValidArgsFunction: completion.AutocompleteNetworks, + Example: `podman network inspect podman`, + Args: cobra.MinimumNArgs(1), Annotations: map[string]string{ registry.ParentNSRequired: "", }, diff --git a/cmd/podman/networks/list.go b/cmd/podman/networks/list.go index 24604c0551a8..1aae566d546d 100644 --- a/cmd/podman/networks/list.go +++ b/cmd/podman/networks/list.go @@ -8,6 +8,7 @@ import ( "strings" "text/tabwriter" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/validate" "github.com/containers/libpod/pkg/domain/entities" @@ -19,12 +20,13 @@ import ( var ( networklistDescription = `List networks` networklistCommand = &cobra.Command{ - Use: "ls", - Args: validate.NoArgs, - Short: "network list", - Long: networklistDescription, - RunE: networkList, - Example: `podman network list`, + Use: "ls", + Args: validate.NoArgs, + Short: "network list", + Long: networklistDescription, + RunE: networkList, + Example: `podman network list`, + ValidArgsFunction: completion.AutocompleteNone, Annotations: map[string]string{ registry.ParentNSRequired: "", }, diff --git a/cmd/podman/networks/rm.go b/cmd/podman/networks/rm.go index 34d57f6ef68e..3360a4c5dbd8 100644 --- a/cmd/podman/networks/rm.go +++ b/cmd/podman/networks/rm.go @@ -3,6 +3,7 @@ package network import ( "fmt" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/pkg/domain/entities" @@ -13,12 +14,13 @@ import ( var ( networkrmDescription = `Remove networks` networkrmCommand = &cobra.Command{ - Use: "rm [flags] NETWORK [NETWORK...]", - Short: "network rm", - Long: networkrmDescription, - RunE: networkRm, - Example: `podman network rm podman`, - Args: cobra.MinimumNArgs(1), + Use: "rm [flags] NETWORK [NETWORK...]", + Short: "network rm", + Long: networkrmDescription, + RunE: networkRm, + ValidArgsFunction: completion.AutocompleteNetworks, + Example: `podman network rm podman`, + Args: cobra.MinimumNArgs(1), Annotations: map[string]string{ registry.ParentNSRequired: "", }, diff --git a/cmd/podman/play/kube.go b/cmd/podman/play/kube.go index 1fbf24d5e7b5..f1ff1cbcebcd 100644 --- a/cmd/podman/play/kube.go +++ b/cmd/podman/play/kube.go @@ -6,6 +6,7 @@ import ( "github.com/containers/common/pkg/auth" "github.com/containers/image/v5/types" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/pkg/domain/entities" @@ -32,11 +33,12 @@ var ( It creates the pod and containers described in the YAML. The containers within the pod are then started and the ID of the new Pod is output.` kubeCmd = &cobra.Command{ - Use: "kube [flags] KUBEFILE", - Short: "Play a pod based on Kubernetes YAML.", - Long: kubeDescription, - RunE: kube, - Args: cobra.ExactArgs(1), + Use: "kube [flags] KUBEFILE", + Short: "Play a pod based on Kubernetes YAML.", + Long: kubeDescription, + RunE: kube, + Args: cobra.ExactArgs(1), + ValidArgsFunction: completion.AutocompleteDefault, Example: `podman play kube nginx.yml podman play kube --creds user:password --seccomp-profile-root /custom/path apache.yml`, } diff --git a/cmd/podman/pods/create.go b/cmd/podman/pods/create.go index 62b5b849e812..ae66e00f2a54 100644 --- a/cmd/podman/pods/create.go +++ b/cmd/podman/pods/create.go @@ -8,6 +8,7 @@ import ( "strings" "github.com/containers/libpod/cmd/podman/common" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/parse" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/validate" @@ -27,11 +28,12 @@ var ( You can then start it at any time with the podman pod start command. The pod will be created with the initial state 'created'.` createCommand = &cobra.Command{ - Use: "create", - Args: validate.NoArgs, - Short: "Create a new empty pod", - Long: podCreateDescription, - RunE: create, + Use: "create", + Args: validate.NoArgs, + Short: "Create a new empty pod", + Long: podCreateDescription, + RunE: create, + ValidArgsFunction: completion.AutocompleteNone, } ) diff --git a/cmd/podman/pods/exists.go b/cmd/podman/pods/exists.go index cf3e3eae5905..21bc6464a825 100644 --- a/cmd/podman/pods/exists.go +++ b/cmd/podman/pods/exists.go @@ -3,6 +3,7 @@ package pods import ( "context" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/spf13/cobra" @@ -12,11 +13,12 @@ var ( podExistsDescription = `If the named pod exists in local storage, podman pod exists exits with 0, otherwise the exit code will be 1.` existsCommand = &cobra.Command{ - Use: "exists POD", - Short: "Check if a pod exists in local storage", - Long: podExistsDescription, - RunE: exists, - Args: cobra.ExactArgs(1), + Use: "exists POD", + Short: "Check if a pod exists in local storage", + Long: podExistsDescription, + RunE: exists, + Args: cobra.ExactArgs(1), + ValidArgsFunction: completion.AutocompletePods, Example: `podman pod exists podID podman pod exists mypod || podman pod create --name mypod`, DisableFlagsInUseLine: true, diff --git a/cmd/podman/pods/inspect.go b/cmd/podman/pods/inspect.go index 34c07c11b997..ba80526fcdb1 100644 --- a/cmd/podman/pods/inspect.go +++ b/cmd/podman/pods/inspect.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/containers/buildah/pkg/formats" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/pkg/errors" @@ -21,11 +22,12 @@ var ( By default, this will render all results in a JSON array.`) inspectCmd = &cobra.Command{ - Use: "inspect [flags] POD [POD...]", - Short: "Displays a pod configuration", - Long: inspectDescription, - RunE: inspect, - Example: `podman pod inspect podID`, + Use: "inspect [flags] POD [POD...]", + Short: "Displays a pod configuration", + Long: inspectDescription, + RunE: inspect, + ValidArgsFunction: completion.AutocompletePods, + Example: `podman pod inspect podID`, } ) diff --git a/cmd/podman/pods/kill.go b/cmd/podman/pods/kill.go index 02089016e628..ef2d88048607 100644 --- a/cmd/podman/pods/kill.go +++ b/cmd/podman/pods/kill.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/parse" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/utils" @@ -23,6 +24,7 @@ var ( Args: func(cmd *cobra.Command, args []string) error { return parse.CheckAllLatestAndCIDFile(cmd, args, false, false) }, + ValidArgsFunction: completion.AutocompletePodsRunning, //it makes no sence to show stopped pods Example: `podman pod kill podID podman pod kill --signal TERM mywebserver podman pod kill --latest`, diff --git a/cmd/podman/pods/pause.go b/cmd/podman/pods/pause.go index 4ee1826611c8..7c4bc297919e 100644 --- a/cmd/podman/pods/pause.go +++ b/cmd/podman/pods/pause.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/parse" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/utils" @@ -23,6 +24,7 @@ var ( Args: func(cmd *cobra.Command, args []string) error { return parse.CheckAllLatestAndCIDFile(cmd, args, false, false) }, + ValidArgsFunction: completion.AutocompletePodsRunning, //it makes no sence to show stopped pods Example: `podman pod pause podID1 podID2 podman pod pause --latest podman pod pause --all`, diff --git a/cmd/podman/pods/prune.go b/cmd/podman/pods/prune.go index bc15d8035968..b1f64084ca37 100644 --- a/cmd/podman/pods/prune.go +++ b/cmd/podman/pods/prune.go @@ -7,6 +7,7 @@ import ( "os" "strings" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/pkg/domain/entities" @@ -22,11 +23,12 @@ var ( pruneDescription = fmt.Sprintf(`podman pod prune Removes all exited pods`) pruneCommand = &cobra.Command{ - Use: "prune [flags]", - Short: "Remove all stopped pods and their containers", - Long: pruneDescription, - RunE: prune, - Example: `podman pod prune`, + Use: "prune [flags]", + Short: "Remove all stopped pods and their containers", + Long: pruneDescription, + RunE: prune, + ValidArgsFunction: completion.AutocompletePods, + Example: `podman pod prune`, } ) diff --git a/cmd/podman/pods/ps.go b/cmd/podman/pods/ps.go index 5703bd1727d5..69f0724cb1b8 100644 --- a/cmd/podman/pods/ps.go +++ b/cmd/podman/pods/ps.go @@ -11,6 +11,7 @@ import ( "text/template" "time" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/validate" "github.com/containers/libpod/pkg/domain/entities" @@ -24,12 +25,13 @@ var ( // Command: podman pod _ps_ psCmd = &cobra.Command{ - Use: "ps", - Aliases: []string{"ls", "list"}, - Short: "List pods", - Long: psDescription, - RunE: pods, - Args: validate.NoArgs, + Use: "ps", + Aliases: []string{"ls", "list"}, + Short: "List pods", + Long: psDescription, + RunE: pods, + ValidArgsFunction: completion.AutocompleteNone, + Args: validate.NoArgs, } ) diff --git a/cmd/podman/pods/restart.go b/cmd/podman/pods/restart.go index 1f617a2774db..7f9bb2df0671 100644 --- a/cmd/podman/pods/restart.go +++ b/cmd/podman/pods/restart.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/parse" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/utils" @@ -23,6 +24,7 @@ var ( Args: func(cmd *cobra.Command, args []string) error { return parse.CheckAllLatestAndCIDFile(cmd, args, false, false) }, + ValidArgsFunction: completion.AutocompletePods, Example: `podman pod restart podID1 podID2 podman pod restart --latest podman pod restart --all`, diff --git a/cmd/podman/pods/rm.go b/cmd/podman/pods/rm.go index 4b9882f8a69a..b23cee355b54 100644 --- a/cmd/podman/pods/rm.go +++ b/cmd/podman/pods/rm.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/parse" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/utils" @@ -23,6 +24,7 @@ var ( Args: func(cmd *cobra.Command, args []string) error { return parse.CheckAllLatestAndCIDFile(cmd, args, false, false) }, + ValidArgsFunction: completion.AutocompletePods, Example: `podman pod rm mywebserverpod podman pod rm -f 860a4b23 podman pod rm -f -a`, diff --git a/cmd/podman/pods/start.go b/cmd/podman/pods/start.go index d0150a3c26e3..8e572d0d3f0c 100644 --- a/cmd/podman/pods/start.go +++ b/cmd/podman/pods/start.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/parse" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/utils" @@ -23,6 +24,7 @@ var ( Args: func(cmd *cobra.Command, args []string) error { return parse.CheckAllLatestAndCIDFile(cmd, args, false, false) }, + ValidArgsFunction: completion.AutocompletePods, Example: `podman pod start podID podman pod start --latest podman pod start --all`, diff --git a/cmd/podman/pods/stats.go b/cmd/podman/pods/stats.go index d3950fdbc02c..b323de5d1dd8 100644 --- a/cmd/podman/pods/stats.go +++ b/cmd/podman/pods/stats.go @@ -12,6 +12,7 @@ import ( "github.com/buger/goterm" "github.com/containers/buildah/pkg/formats" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/util/camelcase" @@ -34,10 +35,11 @@ var ( statsDescription = `Display the containers' resource-usage statistics of one or more running pod` // Command: podman pod _pod_ statsCmd = &cobra.Command{ - Use: "stats [flags] [POD...]", - Short: "Display a live stream of resource usage statistics for the containers in one or more pods", - Long: statsDescription, - RunE: stats, + Use: "stats [flags] [POD...]", + Short: "Display a live stream of resource usage statistics for the containers in one or more pods", + Long: statsDescription, + RunE: stats, + ValidArgsFunction: completion.AutocompletePodsRunning, //it makes no sence to show stopped pods Example: `podman pod stats podman pod stats a69b23034235 named-pod podman pod stats --latest diff --git a/cmd/podman/pods/stop.go b/cmd/podman/pods/stop.go index daf05d640c59..1adc6314ccd9 100644 --- a/cmd/podman/pods/stop.go +++ b/cmd/podman/pods/stop.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/parse" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/utils" @@ -24,6 +25,7 @@ var ( Args: func(cmd *cobra.Command, args []string) error { return parse.CheckAllLatestAndCIDFile(cmd, args, false, false) }, + ValidArgsFunction: completion.AutocompletePodsRunning, //it makes no sence to show stopped pods Example: `podman pod stop mywebserverpod podman pod stop --latest podman pod stop --time 0 490eb 3557fb`, diff --git a/cmd/podman/pods/top.go b/cmd/podman/pods/top.go index ba1efb63835b..1e22f66f9a8c 100644 --- a/cmd/podman/pods/top.go +++ b/cmd/podman/pods/top.go @@ -7,6 +7,7 @@ import ( "strings" "text/tabwriter" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/util" @@ -22,11 +23,12 @@ var ( topOptions = entities.PodTopOptions{} topCommand = &cobra.Command{ - Use: "top [flags] POD [FORMAT-DESCRIPTORS|ARGS]", - Short: "Display the running processes of containers in a pod", - Long: topDescription, - RunE: top, - Args: cobra.ArbitraryArgs, + Use: "top [flags] POD [FORMAT-DESCRIPTORS|ARGS]", + Short: "Display the running processes of containers in a pod", + Long: topDescription, + RunE: top, + Args: cobra.ArbitraryArgs, + ValidArgsFunction: completion.AutocompletePodsRunning, //it makes no sence to show stopped pods Example: `podman pod top podID podman pod top --latest podman pod top podID pid seccomp args %C diff --git a/cmd/podman/pods/unpause.go b/cmd/podman/pods/unpause.go index b30bd930a18c..bba9c7d98233 100644 --- a/cmd/podman/pods/unpause.go +++ b/cmd/podman/pods/unpause.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/parse" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/utils" @@ -23,6 +24,9 @@ var ( Args: func(cmd *cobra.Command, args []string) error { return parse.CheckAllLatestAndCIDFile(cmd, args, false, false) }, + // TODO have a function wich shows only pods wich could be unpaused + // for now show all + ValidArgsFunction: completion.AutocompletePods, Example: `podman pod unpause podID1 podID2 podman pod unpause --all podman pod unpause --latest`, diff --git a/cmd/podman/system/df.go b/cmd/podman/system/df.go index 8fe035209b14..d08c8b686203 100644 --- a/cmd/podman/system/df.go +++ b/cmd/podman/system/df.go @@ -9,6 +9,7 @@ import ( "text/tabwriter" "time" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/validate" "github.com/containers/libpod/pkg/domain/entities" @@ -23,11 +24,12 @@ var ( Show podman disk usage ` dfSystemCommand = &cobra.Command{ - Use: "df", - Args: validate.NoArgs, - Short: "Show podman disk usage", - Long: dfSystemDescription, - RunE: df, + Use: "df", + Args: validate.NoArgs, + Short: "Show podman disk usage", + Long: dfSystemDescription, + RunE: df, + ValidArgsFunction: completion.AutocompleteNone, } ) diff --git a/cmd/podman/system/events.go b/cmd/podman/system/events.go index 27e80138ec1b..26a35a64a04a 100644 --- a/cmd/podman/system/events.go +++ b/cmd/podman/system/events.go @@ -8,6 +8,7 @@ import ( "strings" "github.com/containers/buildah/pkg/formats" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/validate" "github.com/containers/libpod/libpod/events" @@ -19,11 +20,12 @@ import ( var ( eventsDescription = "Monitor podman events" eventsCommand = &cobra.Command{ - Use: "events", - Args: validate.NoArgs, - Short: "Show podman events", - Long: eventsDescription, - RunE: eventsCmd, + Use: "events", + Args: validate.NoArgs, + Short: "Show podman events", + Long: eventsDescription, + RunE: eventsCmd, + ValidArgsFunction: completion.AutocompleteNone, Example: `podman events podman events --filter event=create podman events --since 1h30s`, diff --git a/cmd/podman/system/info.go b/cmd/podman/system/info.go index dad63bcd4a5c..54141543cb8e 100644 --- a/cmd/podman/system/info.go +++ b/cmd/podman/system/info.go @@ -5,6 +5,7 @@ import ( "os" "text/template" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/validate" "github.com/containers/libpod/pkg/domain/entities" @@ -19,12 +20,13 @@ var ( Useful for the user and when reporting issues. ` infoCommand = &cobra.Command{ - Use: "info", - Args: validate.NoArgs, - Long: infoDescription, - Short: "Display podman system information", - RunE: info, - Example: `podman info`, + Use: "info", + Args: validate.NoArgs, + Long: infoDescription, + Short: "Display podman system information", + RunE: info, + ValidArgsFunction: completion.AutocompleteNone, + Example: `podman info`, } systemInfoCommand = &cobra.Command{ diff --git a/cmd/podman/system/migrate.go b/cmd/podman/system/migrate.go index 13aa162c757b..4a34d9d7bf50 100644 --- a/cmd/podman/system/migrate.go +++ b/cmd/podman/system/migrate.go @@ -4,6 +4,7 @@ import ( "fmt" "os" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/validate" "github.com/containers/libpod/pkg/domain/entities" @@ -19,11 +20,12 @@ var ( ` migrateCommand = &cobra.Command{ - Use: "migrate", - Args: validate.NoArgs, - Short: "Migrate containers", - Long: migrateDescription, - Run: migrate, + Use: "migrate", + Args: validate.NoArgs, + Short: "Migrate containers", + Long: migrateDescription, + Run: migrate, + ValidArgsFunction: completion.AutocompleteNone, } ) diff --git a/cmd/podman/system/prune.go b/cmd/podman/system/prune.go index cc9b473f1d00..2bff72f12937 100644 --- a/cmd/podman/system/prune.go +++ b/cmd/podman/system/prune.go @@ -7,6 +7,7 @@ import ( "os" "strings" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/cmd/podman/validate" @@ -25,12 +26,13 @@ var ( `) pruneCommand = &cobra.Command{ - Use: "prune [flags]", - Short: "Remove unused data", - Args: validate.NoArgs, - Long: pruneDescription, - RunE: prune, - Example: `podman system prune`, + Use: "prune [flags]", + Short: "Remove unused data", + Args: validate.NoArgs, + Long: pruneDescription, + RunE: prune, + Example: `podman system prune`, + ValidArgsFunction: completion.AutocompleteNone, } force bool ) diff --git a/cmd/podman/system/renumber.go b/cmd/podman/system/renumber.go index 5ee6b3be670d..7eb145763f13 100644 --- a/cmd/podman/system/renumber.go +++ b/cmd/podman/system/renumber.go @@ -4,6 +4,7 @@ import ( "fmt" "os" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/validate" "github.com/containers/libpod/pkg/domain/entities" @@ -20,11 +21,12 @@ var ( ` renumberCommand = &cobra.Command{ - Use: "renumber", - Args: validate.NoArgs, - Short: "Migrate lock numbers", - Long: renumberDescription, - Run: renumber, + Use: "renumber", + Args: validate.NoArgs, + Short: "Migrate lock numbers", + Long: renumberDescription, + Run: renumber, + ValidArgsFunction: completion.AutocompleteNone, } ) diff --git a/cmd/podman/system/reset.go b/cmd/podman/system/reset.go index 6caa916903a7..cd6a9fb96388 100644 --- a/cmd/podman/system/reset.go +++ b/cmd/podman/system/reset.go @@ -6,6 +6,7 @@ import ( "os" "strings" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/validate" "github.com/containers/libpod/pkg/domain/entities" @@ -20,11 +21,12 @@ var ( All containers will be stopped and removed, and all images, volumes and container content will be removed. ` systemResetCommand = &cobra.Command{ - Use: "reset", - Args: validate.NoArgs, - Short: "Reset podman storage", - Long: systemResetDescription, - Run: reset, + Use: "reset", + Args: validate.NoArgs, + Short: "Reset podman storage", + Long: systemResetDescription, + Run: reset, + ValidArgsFunction: completion.AutocompleteNone, } forceFlag bool diff --git a/cmd/podman/system/service.go b/cmd/podman/system/service.go index 0f42ae28bce0..d29b938cf3b0 100644 --- a/cmd/podman/system/service.go +++ b/cmd/podman/system/service.go @@ -10,6 +10,7 @@ import ( "syscall" "time" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/rootless" @@ -27,12 +28,13 @@ Enable a listening service for API access to Podman commands. ` srvCmd = &cobra.Command{ - Use: "service [flags] [URI]", - Args: cobra.MaximumNArgs(1), - Short: "Run API service", - Long: srvDescription, - RunE: service, - Example: `podman system service --time=0 unix:///tmp/podman.sock`, + Use: "service [flags] [URI]", + Args: cobra.MaximumNArgs(1), + Short: "Run API service", + Long: srvDescription, + RunE: service, + ValidArgsFunction: completion.AutocompleteDefault, + Example: `podman system service --time=0 unix:///tmp/podman.sock`, } srvArgs = struct { diff --git a/cmd/podman/system/unshare.go b/cmd/podman/system/unshare.go index 7db5d36d2933..8cbf7a0051b0 100644 --- a/cmd/podman/system/unshare.go +++ b/cmd/podman/system/unshare.go @@ -3,6 +3,7 @@ package system import ( "os" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/rootless" @@ -17,6 +18,8 @@ var ( Short: "Run a command in a modified user namespace", Long: unshareDescription, RunE: unshare, + //let the default completion here because we may want to run a command with a path + ValidArgsFunction: completion.AutocompleteDefault, Example: `podman unshare id podman unshare cat /proc/self/uid_map, podman unshare podman-script.sh`, diff --git a/cmd/podman/system/varlink.go b/cmd/podman/system/varlink.go index 6a38b3d28820..c9b60e0f7336 100644 --- a/cmd/podman/system/varlink.go +++ b/cmd/podman/system/varlink.go @@ -5,6 +5,7 @@ package system import ( "time" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/spf13/cobra" @@ -16,11 +17,12 @@ var ( Tools speaking varlink protocol can remotely manage pods, containers and images. ` varlinkCmd = &cobra.Command{ - Use: "varlink [flags] [URI]", - Args: cobra.MinimumNArgs(1), - Short: "Run varlink interface", - Long: varlinkDescription, - RunE: varlinkE, + Use: "varlink [flags] [URI]", + Args: cobra.MinimumNArgs(1), + Short: "Run varlink interface", + Long: varlinkDescription, + RunE: varlinkE, + ValidArgsFunction: completion.AutocompleteDefault, Example: `podman varlink unix:/run/podman/io.podman podman varlink --time 5000 unix:/run/podman/io.podman`, } diff --git a/cmd/podman/system/version.go b/cmd/podman/system/version.go index 92a3225b6b42..827ea554fbe1 100644 --- a/cmd/podman/system/version.go +++ b/cmd/podman/system/version.go @@ -8,6 +8,7 @@ import ( "text/tabwriter" "github.com/containers/buildah/pkg/formats" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/validate" "github.com/containers/libpod/libpod/define" @@ -17,10 +18,11 @@ import ( var ( versionCommand = &cobra.Command{ - Use: "version", - Args: validate.NoArgs, - Short: "Display the Podman Version Information", - RunE: version, + Use: "version", + Args: validate.NoArgs, + Short: "Display the Podman Version Information", + ValidArgsFunction: completion.AutocompleteNone, + RunE: version, } versionFormat string ) diff --git a/cmd/podman/volumes/create.go b/cmd/podman/volumes/create.go index 1bec8d0e70db..6b3e0f628898 100644 --- a/cmd/podman/volumes/create.go +++ b/cmd/podman/volumes/create.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/parse" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" @@ -15,10 +16,11 @@ var ( createDescription = `If using the default driver, "local", the volume will be created on the host in the volumes directory under container storage.` createCommand = &cobra.Command{ - Use: "create [flags] [NAME]", - Short: "Create a new volume", - Long: createDescription, - RunE: create, + Use: "create [flags] [NAME]", + Short: "Create a new volume", + Long: createDescription, + RunE: create, + ValidArgsFunction: completion.AutocompleteNone, Example: `podman volume create myvol podman volume create podman volume create --label foo=bar myvol`, diff --git a/cmd/podman/volumes/inspect.go b/cmd/podman/volumes/inspect.go index 79f65ea4ad08..ada3d53bc72c 100644 --- a/cmd/podman/volumes/inspect.go +++ b/cmd/podman/volumes/inspect.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/containers/buildah/pkg/formats" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/pkg/errors" @@ -19,10 +20,11 @@ var ( Use a Go template to change the format from JSON.` inspectCommand = &cobra.Command{ - Use: "inspect [flags] VOLUME [VOLUME...]", - Short: "Display detailed information on one or more volumes", - Long: volumeInspectDescription, - RunE: inspect, + Use: "inspect [flags] VOLUME [VOLUME...]", + Short: "Display detailed information on one or more volumes", + Long: volumeInspectDescription, + RunE: inspect, + ValidArgsFunction: completion.AutocompleteVolumes, Example: `podman volume inspect myvol podman volume inspect --all podman volume inspect --format "{{.Driver}} {{.Scope}}" myvol`, diff --git a/cmd/podman/volumes/list.go b/cmd/podman/volumes/list.go index 72bf9f25b0a0..c0d97fb7a482 100644 --- a/cmd/podman/volumes/list.go +++ b/cmd/podman/volumes/list.go @@ -9,6 +9,7 @@ import ( "strings" "text/tabwriter" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/validate" "github.com/containers/libpod/pkg/domain/entities" @@ -23,12 +24,13 @@ podman volume ls List all available volumes. The output of the volumes can be filtered and the output format can be changed to JSON or a user specified Go template.` lsCommand = &cobra.Command{ - Use: "ls", - Aliases: []string{"list"}, - Args: validate.NoArgs, - Short: "List volumes", - Long: volumeLsDescription, - RunE: list, + Use: "ls", + Aliases: []string{"list"}, + Args: validate.NoArgs, + Short: "List volumes", + Long: volumeLsDescription, + ValidArgsFunction: completion.AutocompleteNone, + RunE: list, } ) diff --git a/cmd/podman/volumes/prune.go b/cmd/podman/volumes/prune.go index 57344385b5dd..841b0781e245 100644 --- a/cmd/podman/volumes/prune.go +++ b/cmd/podman/volumes/prune.go @@ -7,6 +7,7 @@ import ( "os" "strings" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/cmd/podman/validate" @@ -21,11 +22,12 @@ var ( The command prompts for confirmation which can be overridden with the --force flag. Note all data will be destroyed.` pruneCommand = &cobra.Command{ - Use: "prune", - Args: validate.NoArgs, - Short: "Remove all unused volumes", - Long: volumePruneDescription, - RunE: prune, + Use: "prune", + Args: validate.NoArgs, + Short: "Remove all unused volumes", + Long: volumePruneDescription, + RunE: prune, + ValidArgsFunction: completion.AutocompleteNone, } ) diff --git a/cmd/podman/volumes/rm.go b/cmd/podman/volumes/rm.go index f5a898ff303a..65b6177950a8 100644 --- a/cmd/podman/volumes/rm.go +++ b/cmd/podman/volumes/rm.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/containers/libpod/cmd/podman/completion" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/cmd/podman/utils" "github.com/containers/libpod/pkg/domain/entities" @@ -16,11 +17,12 @@ var ( By default only volumes that are not being used by any containers will be removed. To remove the volumes anyways, use the --force flag.` rmCommand = &cobra.Command{ - Use: "rm [flags] VOLUME [VOLUME...]", - Aliases: []string{"remove"}, - Short: "Remove one or more volumes", - Long: volumeRmDescription, - RunE: rm, + Use: "rm [flags] VOLUME [VOLUME...]", + Aliases: []string{"remove"}, + Short: "Remove one or more volumes", + Long: volumeRmDescription, + RunE: rm, + ValidArgsFunction: completion.AutocompleteVolumes, Example: `podman volume rm myvol1 myvol2 podman volume rm --all podman volume rm --force myvol`, diff --git a/docs/source/markdown/podman-completion-bash.1.md b/docs/source/markdown/podman-completion-bash.1.md new file mode 100644 index 000000000000..046e8692ab86 --- /dev/null +++ b/docs/source/markdown/podman-completion-bash.1.md @@ -0,0 +1,24 @@ +% podman-container-bash(1) + +## NAME +podman\-completion\-bash - Generate bash completion script for podman + +## SYNOPSIS +**podman completion bash** [*options*] + +## DESCRIPTION +Generate bash completion script for podman. +To load in your current session run +source <(podman completion bash) + +## OPTIONS +**--file**, **-f** + +Write the generated output to file. + +## EXAMPLE + +podman completion bash -f podman + +## SEE ALSO +podman(1), podman-completion(1) diff --git a/docs/source/markdown/podman-completion-fish.1.md b/docs/source/markdown/podman-completion-fish.1.md new file mode 100644 index 000000000000..4fa7bac16b33 --- /dev/null +++ b/docs/source/markdown/podman-completion-fish.1.md @@ -0,0 +1,24 @@ +% podman-container-fish(1) + +## NAME +podman\-completion\-fish - Generate fish completion script for podman + +## SYNOPSIS +**podman completion fish** [*options*] + +## DESCRIPTION +Generate fish completion script for podman. +To load in your current session run +podman completion fish | source + +## OPTIONS +**--file**, **-f** + +Write the generated output to file. + +## EXAMPLE + +podman completion fish -f podman + +## SEE ALSO +podman(1), podman-completion(1) diff --git a/docs/source/markdown/podman-completion-powershell.1.md b/docs/source/markdown/podman-completion-powershell.1.md new file mode 100644 index 000000000000..442bcfd5be20 --- /dev/null +++ b/docs/source/markdown/podman-completion-powershell.1.md @@ -0,0 +1,22 @@ +% podman-container-powershell(1) + +## NAME +podman\-completion\-powershell - Generate powershell completion script for podman + +## SYNOPSIS +**podman completion powershell** [*options*] + +## DESCRIPTION +Generate powershell completion script for podman. + +## OPTIONS +**--file**, **-f** + +Write the generated output to file. + +## EXAMPLE + +podman completion powershell -f podman + +## SEE ALSO +podman(1), podman-completion(1) diff --git a/docs/source/markdown/podman-completion-zsh.1.md b/docs/source/markdown/podman-completion-zsh.1.md new file mode 100644 index 000000000000..40c20e9fe1f9 --- /dev/null +++ b/docs/source/markdown/podman-completion-zsh.1.md @@ -0,0 +1,24 @@ +% podman-container-zsh(1) + +## NAME +podman\-completion\-zsh - Generate zsh completion script for podman + +## SYNOPSIS +**podman completion zsh** [*options*] + +## DESCRIPTION +Generate zsh completion script for podman. +To load in your current session run +source <(podman completion zsh) && compinit + +## OPTIONS +**--file**, **-f** + +Write the generated output to file. + +## EXAMPLE + +podman completion zsh -f podman + +## SEE ALSO +podman(1), podman-completion(1) diff --git a/docs/source/markdown/podman-completion.1.md b/docs/source/markdown/podman-completion.1.md new file mode 100644 index 000000000000..9f2933978317 --- /dev/null +++ b/docs/source/markdown/podman-completion.1.md @@ -0,0 +1,44 @@ +% podman-completion(1) + +## NAME + +podman\-completion - Generate shell completions + +## SYNOPSIS + +**podman completion** _subcommand_ + +## DESCRIPTION + +The completion command allows you to generate shell completion scripts + +## COMMANDS + +| Command | Man Page | Description | +| ---------- | -------------------------------------------------------------------- | ------------------------------------------------- | +| bash | [podman-completion-bash(1)](podman-completion-bash.1.md) | Generate bash completion script for podman. | +| fish | [podman-completion-fish(1)](podman-completion-fish.1.md) | Generate fish completion script for podman. | +| powershell | [podman-completion-powershell(1)](podman-completion-powershell.1.md) | Generate powershell completion script for podman. | +| zsh | [podman-completion-zsh(1)](podman-completion-zsh.1.md) | Generate zsh completion script for podman. | + +## IMPLEMENTATION + +This table shows how a command gets autocompleted. + +| Command | Main Args | Flags | +| ------------------------------------------------------------------------------------ | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| [podman-attach](podman-attach.1.md)
[podman-container-attach](podman-attach.1.md) | running containers | **--detach-keys** -> _ctrl-_ | +| [podman-auto-update](podman-auto-update.1.md) | none | | +| [podman-build](podman-build.1.md)
[podman-image-build](podman-build.1.md) | default shell | skipping for now because flags are defined in buildah | +| [podman-commit](podman-commit.1.md)
[podman-container-commit](podman-commit.1.md) | all containers | **--change** -> _CMD, ENTRYPOINT, ENV, EXPOSE, LABEL, STOPSIGNAL, USER, VOLUME, WORKDIR_
**--format** -> _oci,docker_
**--iidfile** -> default shell
**--author** -> none
**--message** -> none | +| [podman-container-checkpoint](podman-container-checkpoint.1.md) | running containers | **--export** -> default shell | +| [podman-container-cleanup](podman-container-cleanup.1.md) | exited containers | **--exec** -> none | +| [podman-container-exists](podman-container-exists.1.md) | all containers | | +| [podman-container-prune](podman-container-prune.1.md) | none | **--filter** -> none | +| [podman-container-restore](podman-container-restore.1.md) | all containers | **--import** -> default shell
**--name** -> none | +| [podman-container-runlabel](podman-container-runlabel.1.md) | all images | **--authfile** -> default shell
**--cert-dir** -> default shell
**--creds** -> none
**--name** -> none | + + +## SEE ALSO + +podman diff --git a/pkg/domain/entities/completion.go b/pkg/domain/entities/completion.go new file mode 100644 index 000000000000..d8004b7513ce --- /dev/null +++ b/pkg/domain/entities/completion.go @@ -0,0 +1,7 @@ +package entities + +//Args for the completion subcommand +type CompletionOptions struct { + //File - generate file + File string +} diff --git a/pkg/systemd/generate/systemdgen.go b/pkg/systemd/generate/systemdgen.go index 73fe52c0ef1c..837c737dea55 100644 --- a/pkg/systemd/generate/systemdgen.go +++ b/pkg/systemd/generate/systemdgen.go @@ -65,11 +65,11 @@ type ContainerInfo struct { EnvVariable string } -var restartPolicies = []string{"no", "on-success", "on-failure", "on-abnormal", "on-watchdog", "on-abort", "always"} +var RestartPolicies = []string{"no", "on-success", "on-failure", "on-abnormal", "on-watchdog", "on-abort", "always"} // validateRestartPolicy checks that the user-provided policy is valid. func validateRestartPolicy(restart string) error { - for _, i := range restartPolicies { + for _, i := range RestartPolicies { if i == restart { return nil }