()
| 34 | ) |
| 35 | |
| 36 | func PsCommand() *cobra.Command { |
| 37 | var cmd = &cobra.Command{ |
| 38 | Use: "ps", |
| 39 | Args: cobra.NoArgs, |
| 40 | Short: "List containers", |
| 41 | RunE: psAction, |
| 42 | SilenceUsage: true, |
| 43 | SilenceErrors: true, |
| 44 | } |
| 45 | cmd.Flags().BoolP("all", "a", false, "Show all containers (default shows just running)") |
| 46 | cmd.Flags().IntP("last", "n", -1, "Show n last created containers (includes all states)") |
| 47 | cmd.Flags().BoolP("latest", "l", false, "Show the latest created container (includes all states)") |
| 48 | cmd.Flags().Bool("no-trunc", false, "Don't truncate output") |
| 49 | cmd.Flags().BoolP("quiet", "q", false, "Only display container IDs") |
| 50 | cmd.Flags().BoolP("size", "s", false, "Display total file sizes") |
| 51 | |
| 52 | // Alias "-f" is reserved for "--filter" |
| 53 | cmd.Flags().String("format", "", "Format the output using the given Go template, e.g, '{{json .}}', 'wide'") |
| 54 | cmd.RegisterFlagCompletionFunc("format", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { |
| 55 | return []string{"json", "table", "wide"}, cobra.ShellCompDirectiveNoFileComp |
| 56 | }) |
| 57 | cmd.Flags().StringSliceP("filter", "f", nil, "Filter matches containers based on given conditions. When specifying the condition 'status', it filters all containers") |
| 58 | return cmd |
| 59 | } |
| 60 | |
| 61 | func processOptions(cmd *cobra.Command) (types.ContainerListOptions, FormattingAndPrintingOptions, error) { |
| 62 | globalOptions, err := helpers.ProcessRootCmdFlags(cmd) |
no test coverage detected
searching dependent graphs…