MCPcopy Index your code
hub / github.com/jetify-com/devbox / searchCmd

Function searchCmd

internal/boxcli/search.go:26–66  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

24}
25
26func searchCmd() *cobra.Command {
27 flags := &searchCmdFlags{}
28 command := &cobra.Command{
29 Use: "search <pkg>",
30 Short: "Search for nix packages",
31 Args: cobra.ExactArgs(1),
32 RunE: func(cmd *cobra.Command, args []string) error {
33 query := args[0]
34 name, version, isVersioned := searcher.ParseVersionedPackage(query)
35 if !isVersioned {
36 results, err := searcher.Client().Search(cmd.Context(), query)
37 if err != nil {
38 return err
39 }
40 return printSearchResults(
41 cmd.OutOrStdout(), query, results, flags.showAll)
42 }
43 packageVersion, err := searcher.Client().Resolve(name, version)
44 if err != nil {
45 // This is not ideal. Search service should return valid response we
46 // can parse
47 return usererr.WithUserMessage(err, "No results found for %q\n", query)
48 }
49 fmt.Fprintf(
50 cmd.OutOrStdout(),
51 "%s resolves to: %s@%s\n",
52 query,
53 packageVersion.Name,
54 packageVersion.Version,
55 )
56 return nil
57 },
58 }
59
60 command.Flags().BoolVar(
61 &flags.showAll, "show-all", false,
62 "show all available templates",
63 )
64
65 return command
66}
67
68func printSearchResults(
69 w io.Writer,

Callers 1

RootCmdFunction · 0.85

Calls 6

ParseVersionedPackageFunction · 0.92
ClientFunction · 0.92
WithUserMessageFunction · 0.92
printSearchResultsFunction · 0.85
SearchMethod · 0.80
ResolveMethod · 0.65

Tested by

no test coverage detected