newSearchCommand creates a new `docker search` command
(dockerCLI command.Cli)
| 30 | |
| 31 | // newSearchCommand creates a new `docker search` command |
| 32 | func newSearchCommand(dockerCLI command.Cli) *cobra.Command { |
| 33 | options := searchOptions{filter: opts.NewFilterOpt()} |
| 34 | |
| 35 | cmd := &cobra.Command{ |
| 36 | Use: "search [OPTIONS] TERM", |
| 37 | Short: "Search Docker Hub for images", |
| 38 | Args: cli.ExactArgs(1), |
| 39 | RunE: func(cmd *cobra.Command, args []string) error { |
| 40 | options.term = args[0] |
| 41 | return runSearch(cmd.Context(), dockerCLI, options) |
| 42 | }, |
| 43 | Annotations: map[string]string{ |
| 44 | "category-top": "10", |
| 45 | }, |
| 46 | DisableFlagsInUseLine: true, |
| 47 | } |
| 48 | |
| 49 | flags := cmd.Flags() |
| 50 | |
| 51 | flags.BoolVar(&options.noTrunc, "no-trunc", false, "Don't truncate output") |
| 52 | flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided") |
| 53 | flags.IntVar(&options.limit, "limit", 0, "Max number of search results") |
| 54 | flags.StringVar(&options.format, "format", "", "Pretty-print search using a Go template") |
| 55 | |
| 56 | return cmd |
| 57 | } |
| 58 | |
| 59 | func runSearch(ctx context.Context, dockerCli command.Cli, options searchOptions) error { |
| 60 | if _, ok := options.filter.Value()["is-automated"]; ok { |
nothing calls this directly
no test coverage detected
searching dependent graphs…