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

Function newSubmitCmd

cmd/submit.go:19–78  ·  view source on GitHub ↗
(baseURL, pacmanConf, pkgstatsConf *string)

Source from the content-addressed store, hash-verified

17)
18
19func newSubmitCmd(baseURL, pacmanConf, pkgstatsConf *string) *cobra.Command {
20 var (
21 dumpJSON = false
22 quiet = false
23 configHelp = false
24 )
25
26 submitCmd := &cobra.Command{
27 Use: "submit",
28 Short: "Submit a list of your installed packages to the pkgstats project",
29 Long: "Submit a list of your installed packages, your system architecture\nand the mirror you are using to the pkgstats project.\n\n" +
30 "Statistics are available at https://pkgstats.archlinux.de",
31 Args: cobra.NoArgs,
32 RunE: func(cmd *cobra.Command, args []string) error {
33 if configHelp {
34 printConfigHelp(cmd.OutOrStdout())
35 return nil
36 }
37
38 if dumpJSON && quiet {
39 return errors.New("--quiet and --dump-json cannot be used at the same time")
40 }
41
42 if !dumpJSON && !quiet {
43 fmt.Fprintln(cmd.OutOrStdout(), "Collecting data...")
44 }
45
46 p, err := pacman.Parse(*pacmanConf)
47 if err != nil {
48 return err
49 }
50
51 req, err := submit.CreateRequest(p, system.NewSystem())
52 if err != nil {
53 return err
54 }
55
56 c, err := config.Load(*pkgstatsConf)
57 if err != nil {
58 return err
59 }
60 err = filter.FilterRequest(c, req)
61 if err != nil {
62 return err
63 }
64
65 if dumpJSON {
66 return dumpRequest(cmd.OutOrStdout(), req)
67 } else {
68 return submitRequest(cmd.OutOrStdout(), req, *baseURL, quiet)
69 }
70 },
71 }
72
73 submitCmd.Flags().BoolVar(&configHelp, "config-help", configHelp, "Show help for configuring blocklists in /etc/pkgstats.yaml")
74 submitCmd.Flags().BoolVarP(&dumpJSON, "dump-json", "d", dumpJSON, "Dump information that would be sent as JSON")
75 submitCmd.Flags().BoolVarP(&quiet, "quiet", "q", quiet, "Suppress any output except errors")
76

Callers 1

NewRootCmdFunction · 0.85

Calls 8

ParseFunction · 0.92
CreateRequestFunction · 0.92
NewSystemFunction · 0.92
LoadFunction · 0.92
FilterRequestFunction · 0.92
printConfigHelpFunction · 0.85
dumpRequestFunction · 0.85
submitRequestFunction · 0.85

Tested by

no test coverage detected