-
Notifications
You must be signed in to change notification settings - Fork 485
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Short build tag in version number (#2658)
* use short commit hash in version number * var -> const * cscli: extract version.go, doc.go * don't repeat commit hash in version number
- Loading branch information
Showing
6 changed files
with
162 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/cobra/doc" | ||
) | ||
|
||
type cliDoc struct{} | ||
|
||
func NewCLIDoc() *cliDoc { | ||
return &cliDoc{} | ||
} | ||
|
||
func (cli cliDoc) NewCommand(rootCmd *cobra.Command) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "doc", | ||
Short: "Generate the documentation in `./doc/`. Directory must exist.", | ||
Args: cobra.ExactArgs(0), | ||
Hidden: true, | ||
DisableAutoGenTag: true, | ||
RunE: func(_ *cobra.Command, _ []string) error { | ||
if err := doc.GenMarkdownTreeCustom(rootCmd, "./doc/", cli.filePrepender, cli.linkHandler); err != nil { | ||
return fmt.Errorf("failed to generate cobra doc: %s", err) | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func (cli cliDoc) filePrepender(filename string) string { | ||
const header = `--- | ||
id: %s | ||
title: %s | ||
--- | ||
` | ||
name := filepath.Base(filename) | ||
base := strings.TrimSuffix(name, filepath.Ext(name)) | ||
return fmt.Sprintf(header, base, strings.ReplaceAll(base, "_", " ")) | ||
} | ||
|
||
func (cli cliDoc) linkHandler(name string) string { | ||
return fmt.Sprintf("/cscli/%s", name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/crowdsecurity/crowdsec/pkg/cwversion" | ||
) | ||
|
||
type cliVersion struct{} | ||
|
||
func NewCLIVersion() *cliVersion { | ||
return &cliVersion{} | ||
} | ||
|
||
func (cli cliVersion) NewCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "version", | ||
Short: "Display version", | ||
Args: cobra.ExactArgs(0), | ||
DisableAutoGenTag: true, | ||
Run: func(_ *cobra.Command, _ []string) { | ||
cwversion.Show() | ||
}, | ||
} | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.