Skip to content

Commit

Permalink
cscli refact - rename item types for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc committed Dec 11, 2023
1 parent 7e3f512 commit 35f984f
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 33 deletions.
8 changes: 4 additions & 4 deletions cmd/crowdsec-cli/hubappsec.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
)

func NewAppsecConfigCLI() *itemCLI {
return &itemCLI{
func NewCLIAppsecConfig() *cliItem {
return &cliItem{
name: cwhub.APPSEC_CONFIGS,
singular: "appsec-config",
oneOrMore: "appsec-config(s)",
Expand Down Expand Up @@ -46,7 +46,7 @@ cscli appsec-configs list crowdsecurity/vpatch`,
}
}

func NewAppsecRuleCLI() *itemCLI {
func NewCLIAppsecRule() *cliItem {
inspectDetail := func(item *cwhub.Item) error {
appsecRule := appsec.AppsecCollectionConfig{}
yamlContent, err := os.ReadFile(item.State.LocalPath)
Expand All @@ -71,7 +71,7 @@ func NewAppsecRuleCLI() *itemCLI {
return nil
}

return &itemCLI{
return &cliItem{
name: "appsec-rules",
singular: "appsec-rule",
oneOrMore: "appsec-rule(s)",
Expand Down
4 changes: 2 additions & 2 deletions cmd/crowdsec-cli/hubcollection.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
)

func NewCollectionCLI() *itemCLI {
return &itemCLI{
func NewCLICollection() *cliItem {
return &cliItem{
name: cwhub.COLLECTIONS,
singular: "collection",
oneOrMore: "collection(s)",
Expand Down
4 changes: 2 additions & 2 deletions cmd/crowdsec-cli/hubcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
)

func NewContextCLI() *itemCLI {
return &itemCLI{
func NewCLIContext() *cliItem {
return &cliItem{
name: cwhub.CONTEXTS,
singular: "context",
oneOrMore: "context(s)",
Expand Down
4 changes: 2 additions & 2 deletions cmd/crowdsec-cli/hubparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
)

func NewParserCLI() *itemCLI {
return &itemCLI{
func NewCLIParser() *cliItem {
return &cliItem{
name: cwhub.PARSERS,
singular: "parser",
oneOrMore: "parser(s)",
Expand Down
4 changes: 2 additions & 2 deletions cmd/crowdsec-cli/hubpostoverflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
)

func NewPostOverflowCLI() *itemCLI {
return &itemCLI{
func NewCLIPostOverflow() *cliItem {
return &cliItem{
name: cwhub.POSTOVERFLOWS,
singular: "postoverflow",
oneOrMore: "postoverflow(s)",
Expand Down
4 changes: 2 additions & 2 deletions cmd/crowdsec-cli/hubscenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
)

func NewScenarioCLI() *itemCLI {
return &itemCLI{
func NewCLIScenario() *cliItem {
return &cliItem{
name: cwhub.SCENARIOS,
singular: "scenario",
oneOrMore: "scenario(s)",
Expand Down
24 changes: 12 additions & 12 deletions cmd/crowdsec-cli/itemcli.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type cliHelp struct {
example string
}

type itemCLI struct {
type cliItem struct {
name string // plural, as used in the hub index
singular string
oneOrMore string // parenthetical pluralizaion: "parser(s)"
Expand All @@ -35,7 +35,7 @@ type itemCLI struct {
listHelp cliHelp
}

func (it itemCLI) NewCommand() *cobra.Command {
func (it cliItem) NewCommand() *cobra.Command {
cmd := &cobra.Command{
Use: coalesce.String(it.help.use, fmt.Sprintf("%s <action> [item]...", it.name)),
Short: coalesce.String(it.help.short, fmt.Sprintf("Manage hub %s", it.name)),
Expand All @@ -55,7 +55,7 @@ func (it itemCLI) NewCommand() *cobra.Command {
return cmd
}

func (it itemCLI) Install(cmd *cobra.Command, args []string) error {
func (it cliItem) Install(cmd *cobra.Command, args []string) error {
flags := cmd.Flags()

downloadOnly, err := flags.GetBool("download-only")
Expand Down Expand Up @@ -103,7 +103,7 @@ func (it itemCLI) Install(cmd *cobra.Command, args []string) error {
return nil
}

func (it itemCLI) NewInstallCmd() *cobra.Command {
func (it cliItem) NewInstallCmd() *cobra.Command {
cmd := &cobra.Command{
Use: coalesce.String(it.installHelp.use, "install [item]..."),
Short: coalesce.String(it.installHelp.short, fmt.Sprintf("Install given %s", it.oneOrMore)),
Expand Down Expand Up @@ -138,7 +138,7 @@ func istalledParentNames(item *cwhub.Item) []string {
return ret
}

func (it itemCLI) Remove(cmd *cobra.Command, args []string) error {
func (it cliItem) Remove(cmd *cobra.Command, args []string) error {
flags := cmd.Flags()

purge, err := flags.GetBool("purge")
Expand Down Expand Up @@ -232,7 +232,7 @@ func (it itemCLI) Remove(cmd *cobra.Command, args []string) error {
return nil
}

func (it itemCLI) NewRemoveCmd() *cobra.Command {
func (it cliItem) NewRemoveCmd() *cobra.Command {
cmd := &cobra.Command{
Use: coalesce.String(it.removeHelp.use, "remove [item]..."),
Short: coalesce.String(it.removeHelp.short, fmt.Sprintf("Remove given %s", it.oneOrMore)),
Expand All @@ -254,7 +254,7 @@ func (it itemCLI) NewRemoveCmd() *cobra.Command {
return cmd
}

func (it itemCLI) Upgrade(cmd *cobra.Command, args []string) error {
func (it cliItem) Upgrade(cmd *cobra.Command, args []string) error {
flags := cmd.Flags()

force, err := flags.GetBool("force")
Expand Down Expand Up @@ -328,7 +328,7 @@ func (it itemCLI) Upgrade(cmd *cobra.Command, args []string) error {
return nil
}

func (it itemCLI) NewUpgradeCmd() *cobra.Command {
func (it cliItem) NewUpgradeCmd() *cobra.Command {
cmd := &cobra.Command{
Use: coalesce.String(it.upgradeHelp.use, "upgrade [item]..."),
Short: coalesce.String(it.upgradeHelp.short, fmt.Sprintf("Upgrade given %s", it.oneOrMore)),
Expand All @@ -348,7 +348,7 @@ func (it itemCLI) NewUpgradeCmd() *cobra.Command {
return cmd
}

func (it itemCLI) Inspect(cmd *cobra.Command, args []string) error {
func (it cliItem) Inspect(cmd *cobra.Command, args []string) error {
flags := cmd.Flags()

url, err := flags.GetString("url")
Expand Down Expand Up @@ -389,7 +389,7 @@ func (it itemCLI) Inspect(cmd *cobra.Command, args []string) error {
return nil
}

func (it itemCLI) NewInspectCmd() *cobra.Command {
func (it cliItem) NewInspectCmd() *cobra.Command {
cmd := &cobra.Command{
Use: coalesce.String(it.inspectHelp.use, "inspect [item]..."),
Short: coalesce.String(it.inspectHelp.short, fmt.Sprintf("Inspect given %s", it.oneOrMore)),
Expand All @@ -410,7 +410,7 @@ func (it itemCLI) NewInspectCmd() *cobra.Command {
return cmd
}

func (it itemCLI) List(cmd *cobra.Command, args []string) error {
func (it cliItem) List(cmd *cobra.Command, args []string) error {
flags := cmd.Flags()

all, err := flags.GetBool("all")
Expand All @@ -437,7 +437,7 @@ func (it itemCLI) List(cmd *cobra.Command, args []string) error {
return nil
}

func (it itemCLI) NewListCmd() *cobra.Command {
func (it cliItem) NewListCmd() *cobra.Command {
cmd := &cobra.Command{
Use: coalesce.String(it.listHelp.use, "list [item... | -a]"),
Short: coalesce.String(it.listHelp.short, fmt.Sprintf("List %s", it.oneOrMore)),
Expand Down
14 changes: 7 additions & 7 deletions cmd/crowdsec-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,13 @@ It is meant to allow you to manage bans, parsers/scenarios/etc, api and generall
rootCmd.AddCommand(NewCLINotifications().NewCommand())
rootCmd.AddCommand(NewCLISupport().NewCommand())
rootCmd.AddCommand(NewCLIPapi().NewCommand())
rootCmd.AddCommand(NewCollectionCLI().NewCommand())
rootCmd.AddCommand(NewParserCLI().NewCommand())
rootCmd.AddCommand(NewScenarioCLI().NewCommand())
rootCmd.AddCommand(NewPostOverflowCLI().NewCommand())
rootCmd.AddCommand(NewContextCLI().NewCommand())
rootCmd.AddCommand(NewAppsecConfigCLI().NewCommand())
rootCmd.AddCommand(NewAppsecRuleCLI().NewCommand())
rootCmd.AddCommand(NewCLICollection().NewCommand())
rootCmd.AddCommand(NewCLIParser().NewCommand())
rootCmd.AddCommand(NewCLIScenario().NewCommand())
rootCmd.AddCommand(NewCLIPostOverflow().NewCommand())
rootCmd.AddCommand(NewCLIContext().NewCommand())
rootCmd.AddCommand(NewCLIAppsecConfig().NewCommand())
rootCmd.AddCommand(NewCLIAppsecRule().NewCommand())

if fflag.CscliSetup.IsEnabled() {
rootCmd.AddCommand(NewSetupCmd())
Expand Down

0 comments on commit 35f984f

Please sign in to comment.