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

Method NewCommand

cmd/crowdsec-cli/doc.go:21–47  ·  view source on GitHub ↗
(rootCmd *cobra.Command)

Source from the content-addressed store, hash-verified

19}
20
21func (cli cliDoc) NewCommand(rootCmd *cobra.Command) *cobra.Command {
22 var target string
23
24 const defaultTarget = "./doc"
25
26 cmd := &cobra.Command{
27 Use: "doc",
28 Short: "Generate the documentation related to cscli commands. Target directory must exist.",
29 Args: args.NoArgs,
30 Hidden: true,
31 DisableAutoGenTag: true,
32 RunE: func(_ *cobra.Command, _ []string) error {
33 if err := doc.GenMarkdownTreeCustom(rootCmd, target, cli.filePrepender, cli.linkHandler); err != nil {
34 return fmt.Errorf("failed to generate cscli documentation: %w", err)
35 }
36
37 fmt.Fprintln(os.Stdout, "Documentation generated in", target)
38
39 return nil
40 },
41 }
42
43 flags := cmd.Flags()
44 flags.StringVar(&target, "target", defaultTarget, "The target directory where the documentation will be generated")
45
46 return cmd
47}
48
49func (cliDoc) filePrepender(filename string) string {
50 const header = `---

Callers 1

addSetupMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected