| 19 | } |
| 20 | |
| 21 | func (s *searchCmd) Command(celer *configs.Celer) *cobra.Command { |
| 22 | s.celer = celer |
| 23 | command := &cobra.Command{ |
| 24 | Use: "search", |
| 25 | Short: "Search available ports from ports repository.", |
| 26 | Long: `Search available ports from ports repository. |
| 27 | |
| 28 | This command searches for ports by name and version pattern. It supports |
| 29 | wildcard matching for flexible searches. |
| 30 | |
| 31 | Pattern matching rules: |
| 32 | - Exact match: zlib@1.3.1 |
| 33 | - Prefix match: zlib* |
| 34 | - Suffix match: *@1.3.1 |
| 35 | - Contains match: *lib* |
| 36 | |
| 37 | Examples: |
| 38 | celer search zlib@1.3.1 # Search for exact match |
| 39 | celer search zlib* # Search for all zlib versions |
| 40 | celer search *@1.3.1 # Search for all ports with version 1.3.1 |
| 41 | celer search *ffmpeg* # Search for all ports containing 'ffmpeg'`, |
| 42 | Args: cobra.ExactArgs(1), |
| 43 | RunE: func(cmd *cobra.Command, args []string) error { |
| 44 | return s.doSearch(args[0]) |
| 45 | }, |
| 46 | ValidArgsFunction: s.completion, |
| 47 | } |
| 48 | |
| 49 | // Silence cobra's error and usage output to avoid duplicate messages. |
| 50 | command.SilenceErrors = true |
| 51 | command.SilenceUsage = true |
| 52 | return command |
| 53 | } |
| 54 | |
| 55 | func (s *searchCmd) doSearch(pattern string) error { |
| 56 | // Initialize celer configuration. |