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

Method NewCommand

cmd/crowdsec-cli/main.go:206–321  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

204}
205
206func (cli *cliRoot) NewCommand() (*cobra.Command, error) {
207 // set the formatter asap and worry about level later
208 logFormatter := &log.TextFormatter{TimestampFormat: time.RFC3339, FullTimestamp: true}
209 log.SetFormatter(logFormatter)
210
211 if err := fflag.RegisterAllFeatures(); err != nil {
212 return nil, fmt.Errorf("failed to register features: %w", err)
213 }
214
215 if err := csconfig.LoadFeatureFlagsEnv(log.StandardLogger()); err != nil {
216 return nil, fmt.Errorf("failed to set feature flags from env: %w", err)
217 }
218
219 // list of valid subcommands for the shell completion
220 validArgs := []string{
221 "alerts", "appsec-configs", "waf-configs", "appsec-rules", "waf-rules", "bouncers", "capi", "collections",
222 "completion", "config", "console", "contexts", "dashboard", "decisions", "explain",
223 "hub", "hubtest", "lapi", "machines", "metrics", "notifications", "parsers",
224 "postoverflows", "scenarios", "simulation", "support", "version",
225 }
226
227 cmd := &cobra.Command{
228 Use: "cscli",
229 Short: "cscli allows you to manage crowdsec",
230 Long: `cscli is the main command to interact with your crowdsec service, scenarios & db.
231It is meant to allow you to manage bans, parsers/scenarios/etc, api and generally manage your crowdsec setup.`,
232 ValidArgs: validArgs,
233 DisableAutoGenTag: true,
234 SilenceErrors: true,
235 // We don't want usage to be printed for every error: Example 'cscli parser install foo/bar'
236 // But we set NoArgs for commands that require a subcommand and print Usage explicitly in RunE.
237 SilenceUsage: true,
238 Args: args.NoArgs,
239 RunE: func(cmd *cobra.Command, _ []string) error {
240 return cmd.Usage()
241 },
242 }
243
244 cli.colorize(cmd)
245
246 // don't sort flags so we can enforce order
247 cmd.Flags().SortFlags = false
248
249 pflags := cmd.PersistentFlags()
250 pflags.SortFlags = false
251
252 pflags.StringVarP(&ConfigFilePath, "config", "c", csconfig.DefaultConfigPath("config.yaml"), "path to crowdsec config file")
253 pflags.StringVarP(&cli.outputFormat, "output", "o", "", "Output format: human, json, raw")
254 pflags.StringVarP(&cli.outputColor, "color", "", "auto", "Output color: yes, no, auto")
255 pflags.BoolVar(&cli.logFlags.debug, "debug", false, "Set logging to debug")
256 pflags.BoolVar(&cli.logFlags.info, "info", false, "Set logging to info")
257 pflags.BoolVar(&cli.logFlags.warn, "warning", false, "Set logging to warning")
258 pflags.BoolVar(&cli.logFlags.error, "error", false, "Set logging to error")
259 pflags.BoolVar(&cli.logFlags.trace, "trace", false, "Set logging to trace")
260 pflags.StringVar(&cli.flagBranch, "branch", "", "Override hub branch on github")
261
262 _ = pflags.MarkHidden("branch")
263

Callers 1

mainWrapFunction · 0.45

Calls 15

colorizeMethod · 0.95
addSetupMethod · 0.95
initializeMethod · 0.95
RegisterAllFeaturesFunction · 0.92
LoadFeatureFlagsEnvFunction · 0.92
DefaultConfigPathFunction · 0.92
LoadFeatureFlagsFileFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92

Tested by

no test coverage detected