MCPcopy Create free account
hub / github.com/archlinux-de/pkgstats-cli / newSearchCmd

Function newSearchCmd

cmd/search.go:16–49  ·  view source on GitHub ↗
(baseURL *string)

Source from the content-addressed store, hash-verified

14)
15
16func newSearchCmd(baseURL *string) *cobra.Command {
17 limit := 10
18
19 searchCmd := &cobra.Command{
20 Use: "search",
21 Short: "Search packages and list their popularity",
22 Args: cobra.ExactArgs(1),
23 RunE: func(cmd *cobra.Command, args []string) error {
24 if limit < minLimit || limit > maxLimit {
25 return fmt.Errorf("valid limit needs to be between %d and %d", minLimit, maxLimit)
26 }
27 if err := request.ValidatePackageName(args[0]); err != nil {
28 return err
29 }
30
31 client := request.NewClient(*baseURL)
32
33 ppl, err := client.SearchPackages(args[0], limit)
34 if err != nil {
35 return err
36 }
37
38 request.PrintPackagePopularities(cmd.OutOrStdout(), ppl)
39 fmt.Fprintln(cmd.OutOrStdout())
40 request.PrintSearchURL(cmd.OutOrStdout(), *baseURL, args[0])
41
42 return nil
43 },
44 }
45
46 searchCmd.Flags().IntVarP(&limit, "limit", "l", limit, fmt.Sprintf("Limit the results from %d to %d entries", minLimit, maxLimit))
47
48 return searchCmd
49}

Callers 1

NewRootCmdFunction · 0.85

Calls 5

SearchPackagesMethod · 0.95
ValidatePackageNameFunction · 0.92
NewClientFunction · 0.92
PrintPackagePopularitiesFunction · 0.92
PrintSearchURLFunction · 0.92

Tested by

no test coverage detected