MCPcopy
hub / github.com/crowdsecurity/crowdsec / install

Method install

cmd/crowdsec-cli/cliitem/cmdinstall.go:48–106  ·  view source on GitHub ↗
(ctx context.Context, args []string, interactive bool, dryRun bool, downloadOnly bool, force bool, ignoreError bool)

Source from the content-addressed store, hash-verified

46}
47
48func (cli *cliItem) install(ctx context.Context, args []string, interactive bool, dryRun bool, downloadOnly bool, force bool, ignoreError bool) error {
49 cfg := cli.cfg()
50
51 hub, err := require.Hub(cfg, log.StandardLogger())
52 if err != nil {
53 return err
54 }
55
56 plan := hubops.NewActionPlan(hub)
57
58 contentProvider, err := require.HubDownloader(ctx, cfg)
59 if err != nil {
60 return err
61 }
62
63 for _, name := range args {
64 item := hub.GetItem(cli.name, name)
65 if item == nil {
66 msg := suggestNearestMessage(hub, cli.name, name)
67 if !ignoreError {
68 return errors.New(msg)
69 }
70
71 log.Error(msg)
72
73 continue
74 }
75
76 if err = plan.AddCommand(hubops.NewDownloadCommand(item, contentProvider, force)); err != nil {
77 return err
78 }
79
80 if !downloadOnly {
81 if err = plan.AddCommand(hubops.NewEnableCommand(item, force)); err != nil {
82 return err
83 }
84 }
85 }
86
87 showPlan := (log.StandardLogger().Level >= log.InfoLevel)
88 verbosePlan := (cfg.Cscli.Output == "raw")
89
90 err = plan.Execute(ctx, interactive, dryRun, showPlan, verbosePlan)
91 switch {
92 case errors.Is(err, hubops.ErrUserCanceled) && err != nil:
93 // not a real error, and we'll want to print the reload message anyway
94 fmt.Fprintln(os.Stdout, err.Error())
95 case ignoreError:
96 log.Error(err)
97 case err != nil:
98 return err
99 }
100
101 if msg := reload.UserMessage(); msg != "" && plan.ReloadNeeded {
102 fmt.Fprintln(os.Stdout, "\n"+msg)
103 }
104
105 return nil

Callers 1

newInstallCmdMethod · 0.95

Calls 13

AddCommandMethod · 0.95
ExecuteMethod · 0.95
HubFunction · 0.92
NewActionPlanFunction · 0.92
HubDownloaderFunction · 0.92
NewDownloadCommandFunction · 0.92
NewEnableCommandFunction · 0.92
UserMessageFunction · 0.92
suggestNearestMessageFunction · 0.85
cfgMethod · 0.80
StandardLoggerMethod · 0.80
GetItemMethod · 0.80

Tested by

no test coverage detected