Skip to content

Commit eb1defa

Browse files
committed
Merge branch 'master' into releases/1.6.x
2 parents ec4055f + a001e1d commit eb1defa

File tree

14 files changed

+115
-131
lines changed

14 files changed

+115
-131
lines changed

cmd/crowdsec-cli/clihub/hub.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ cscli hub update --with-content`,
163163
return cmd
164164
}
165165

166-
func (cli *cliHub) upgrade(ctx context.Context, yes bool, dryRun bool, force bool) error {
166+
func (cli *cliHub) upgrade(ctx context.Context, interactive bool, dryRun bool, force bool) error {
167167
cfg := cli.cfg()
168168

169169
hub, err := require.Hub(cfg, log.StandardLogger())
@@ -189,7 +189,7 @@ func (cli *cliHub) upgrade(ctx context.Context, yes bool, dryRun bool, force boo
189189

190190
verbose := (cfg.Cscli.Output == "raw")
191191

192-
if err := plan.Execute(ctx, yes, dryRun, verbose); err != nil {
192+
if err := plan.Execute(ctx, interactive, dryRun, verbose); err != nil {
193193
return err
194194
}
195195

@@ -202,9 +202,9 @@ func (cli *cliHub) upgrade(ctx context.Context, yes bool, dryRun bool, force boo
202202

203203
func (cli *cliHub) newUpgradeCmd() *cobra.Command {
204204
var (
205-
yes bool
206-
dryRun bool
207-
force bool
205+
interactive bool
206+
dryRun bool
207+
force bool
208208
)
209209

210210
cmd := &cobra.Command{
@@ -217,19 +217,23 @@ Upgrade all configs installed from Crowdsec Hub. Run 'sudo cscli hub update' if
217217
cscli hub upgrade
218218
219219
# Upgrade tainted items as well; force re-download of data files.
220-
cscli hub upgrade --force`,
220+
cscli hub upgrade --force
221+
222+
# Prompt for confirmation if running in an interactive terminal; otherwise, the option is ignored.
223+
cscli hub upgrade --interactive
224+
cscli hub upgrade -i`,
221225
Args: cobra.NoArgs,
222226
DisableAutoGenTag: true,
223227
RunE: func(cmd *cobra.Command, _ []string) error {
224-
return cli.upgrade(cmd.Context(), yes, dryRun, force)
228+
return cli.upgrade(cmd.Context(), interactive, dryRun, force)
225229
},
226230
}
227231

228232
flags := cmd.Flags()
229-
flags.BoolVar(&yes, "yes", false, "Confirm execution without prompt")
233+
flags.BoolVarP(&interactive, "interactive", "i", false, "Ask for confirmation before proceeding")
230234
flags.BoolVar(&dryRun, "dry-run", false, "Don't install or remove anything; print the execution plan")
231235
flags.BoolVar(&force, "force", false, "Force upgrade: overwrite tainted and outdated items; always update data files")
232-
cmd.MarkFlagsMutuallyExclusive("yes", "dry-run")
236+
cmd.MarkFlagsMutuallyExclusive("interactive", "dry-run")
233237

234238
return cmd
235239
}

cmd/crowdsec-cli/cliitem/cmdinstall.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func suggestNearestMessage(hub *cwhub.Hub, itemType string, itemName string) str
4242
return msg
4343
}
4444

45-
func (cli cliItem) install(ctx context.Context, args []string, yes bool, dryRun bool, downloadOnly bool, force bool, ignoreError bool) error {
45+
func (cli cliItem) install(ctx context.Context, args []string, interactive bool, dryRun bool, downloadOnly bool, force bool, ignoreError bool) error {
4646
cfg := cli.cfg()
4747

4848
hub, err := require.Hub(cfg, log.StandardLogger())
@@ -80,7 +80,7 @@ func (cli cliItem) install(ctx context.Context, args []string, yes bool, dryRun
8080

8181
verbose := (cfg.Cscli.Output == "raw")
8282

83-
if err := plan.Execute(ctx, yes, dryRun, verbose); err != nil {
83+
if err := plan.Execute(ctx, interactive, dryRun, verbose); err != nil {
8484
if !ignoreError {
8585
return err
8686
}
@@ -116,7 +116,7 @@ func compAllItems(itemType string, args []string, toComplete string, cfg configG
116116

117117
func (cli cliItem) newInstallCmd() *cobra.Command {
118118
var (
119-
yes bool
119+
interactive bool
120120
dryRun bool
121121
downloadOnly bool
122122
force bool
@@ -134,17 +134,17 @@ func (cli cliItem) newInstallCmd() *cobra.Command {
134134
return compAllItems(cli.name, args, toComplete, cli.cfg)
135135
},
136136
RunE: func(cmd *cobra.Command, args []string) error {
137-
return cli.install(cmd.Context(), args, yes, dryRun, downloadOnly, force, ignoreError)
137+
return cli.install(cmd.Context(), args, interactive, dryRun, downloadOnly, force, ignoreError)
138138
},
139139
}
140140

141141
flags := cmd.Flags()
142-
flags.BoolVarP(&yes, "yes", "y", false, "Confirm execution without prompt")
142+
flags.BoolVarP(&interactive, "interactive", "i", false, "Ask for confirmation before proceeding")
143143
flags.BoolVar(&dryRun, "dry-run", false, "Don't install or remove anything; print the execution plan")
144144
flags.BoolVarP(&downloadOnly, "download-only", "d", false, "Only download packages, don't enable")
145145
flags.BoolVar(&force, "force", false, "Force install: overwrite tainted and outdated files")
146146
flags.BoolVar(&ignoreError, "ignore", false, "Ignore errors when installing multiple "+cli.name)
147-
cmd.MarkFlagsMutuallyExclusive("yes", "dry-run")
147+
cmd.MarkFlagsMutuallyExclusive("interactive", "dry-run")
148148

149149
return cmd
150150
}

cmd/crowdsec-cli/cliitem/cmdremove.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func installedParentNames(item *cwhub.Item) []string {
8585
return ret
8686
}
8787

88-
func (cli cliItem) remove(ctx context.Context, args []string, yes bool, dryRun bool, purge bool, force bool, all bool) error {
88+
func (cli cliItem) remove(ctx context.Context, args []string, interactive bool, dryRun bool, purge bool, force bool, all bool) error {
8989
cfg := cli.cfg()
9090

9191
hub, err := require.Hub(cli.cfg(), log.StandardLogger())
@@ -100,7 +100,7 @@ func (cli cliItem) remove(ctx context.Context, args []string, yes bool, dryRun b
100100

101101
verbose := (cfg.Cscli.Output == "raw")
102102

103-
if err := plan.Execute(ctx, yes, dryRun, verbose); err != nil {
103+
if err := plan.Execute(ctx, interactive, dryRun, verbose); err != nil {
104104
return err
105105
}
106106

@@ -113,11 +113,11 @@ func (cli cliItem) remove(ctx context.Context, args []string, yes bool, dryRun b
113113

114114
func (cli cliItem) newRemoveCmd() *cobra.Command {
115115
var (
116-
yes bool
117-
dryRun bool
118-
purge bool
119-
force bool
120-
all bool
116+
interactive bool
117+
dryRun bool
118+
purge bool
119+
force bool
120+
all bool
121121
)
122122

123123
cmd := &cobra.Command{
@@ -135,17 +135,17 @@ func (cli cliItem) newRemoveCmd() *cobra.Command {
135135
return errors.New("can't specify items and '--all' at the same time")
136136
}
137137

138-
return cli.remove(cmd.Context(), args, yes, dryRun, purge, force, all)
138+
return cli.remove(cmd.Context(), args, interactive, dryRun, purge, force, all)
139139
},
140140
}
141141

142142
flags := cmd.Flags()
143-
flags.BoolVarP(&yes, "yes", "y", false, "Confirm execution without prompt")
143+
flags.BoolVarP(&interactive, "interactive", "i", false, "Ask for confirmation before proceeding")
144144
flags.BoolVar(&dryRun, "dry-run", false, "Don't install or remove anything; print the execution plan")
145145
flags.BoolVar(&purge, "purge", false, "Delete source file too")
146146
flags.BoolVar(&force, "force", false, "Force remove: remove tainted and outdated files")
147147
flags.BoolVar(&all, "all", false, "Remove all the "+cli.name)
148-
cmd.MarkFlagsMutuallyExclusive("yes", "dry-run")
148+
cmd.MarkFlagsMutuallyExclusive("interactive", "dry-run")
149149

150150
return cmd
151151
}

cmd/crowdsec-cli/cliitem/cmdupgrade.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (cli cliItem) upgradePlan(hub *cwhub.Hub, contentProvider cwhub.ContentProv
4545
return plan, nil
4646
}
4747

48-
func (cli cliItem) upgrade(ctx context.Context, args []string, yes bool, dryRun bool, force bool, all bool) error {
48+
func (cli cliItem) upgrade(ctx context.Context, args []string, interactive bool, dryRun bool, force bool, all bool) error {
4949
cfg := cli.cfg()
5050

5151
hub, err := require.Hub(cfg, log.StandardLogger())
@@ -62,7 +62,7 @@ func (cli cliItem) upgrade(ctx context.Context, args []string, yes bool, dryRun
6262

6363
verbose := (cfg.Cscli.Output == "raw")
6464

65-
if err := plan.Execute(ctx, yes, dryRun, verbose); err != nil {
65+
if err := plan.Execute(ctx, interactive, dryRun, verbose); err != nil {
6666
return err
6767
}
6868

@@ -75,10 +75,10 @@ func (cli cliItem) upgrade(ctx context.Context, args []string, yes bool, dryRun
7575

7676
func (cli cliItem) newUpgradeCmd() *cobra.Command {
7777
var (
78-
yes bool
79-
dryRun bool
80-
all bool
81-
force bool
78+
interactive bool
79+
dryRun bool
80+
all bool
81+
force bool
8282
)
8383

8484
cmd := &cobra.Command{
@@ -91,16 +91,16 @@ func (cli cliItem) newUpgradeCmd() *cobra.Command {
9191
return compInstalledItems(cli.name, args, toComplete, cli.cfg)
9292
},
9393
RunE: func(cmd *cobra.Command, args []string) error {
94-
return cli.upgrade(cmd.Context(), args, yes, dryRun, force, all)
94+
return cli.upgrade(cmd.Context(), args, interactive, dryRun, force, all)
9595
},
9696
}
9797

9898
flags := cmd.Flags()
99-
flags.BoolVarP(&yes, "yes", "y", false, "Confirm execution without prompt")
99+
flags.BoolVarP(&interactive, "interactive", "i", false, "Ask for confirmation before proceeding")
100100
flags.BoolVar(&dryRun, "dry-run", false, "Don't install or remove anything; print the execution plan")
101101
flags.BoolVarP(&all, "all", "a", false, "Upgrade all the "+cli.name)
102102
flags.BoolVar(&force, "force", false, "Force upgrade: overwrite tainted and outdated files")
103-
cmd.MarkFlagsMutuallyExclusive("yes", "dry-run")
103+
cmd.MarkFlagsMutuallyExclusive("interactive", "dry-run")
104104

105105
return cmd
106106
}

cmd/crowdsec-cli/cliitem/hubappsec.go

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@ cscli appsec-configs install crowdsecurity/virtual-patching --download-only
4343
# Install over tainted items. Can be used to restore or repair after local modifications or missing dependencies.
4444
cscli appsec-configs install crowdsecurity/virtual-patching --force
4545
46-
# Proceed without prompting.
47-
cscli appsec-configs install crowdsecurity/virtual-patching --yes
48-
49-
# The "--yes" parameter is implied when the command is not connected to a terminal, like pipes or scripts.`,
46+
# Prompt for confirmation if running in an interactive terminal; otherwise, the option is ignored.
47+
cscli appsec-configs install crowdsecurity/virtual-patching -i
48+
cscli appsec-configs install crowdsecurity/virtual-patching --interactive`,
5049
},
5150
removeHelp: cliHelp{
5251
example: `# Uninstall some appsec-configs.
@@ -64,10 +63,9 @@ cscli appsec-configs remove crowdsecurity/virtual-patching --purge
6463
# Remove tainted items.
6564
cscli appsec-configs remove crowdsecurity/virtual-patching --force
6665
67-
# Proceed without prompting.
68-
cscli appsec-configs remove crowdsecurity/virtual-patching --yes
69-
70-
# The "--yes" parameter is implied when the command is not connected to a terminal, like pipes or scripts.`,
66+
# Prompt for confirmation if running in an interactive terminal; otherwise, the option is ignored.
67+
cscli appsec-configs remove crowdsecurity/virtual-patching -i
68+
cscli appsec-configs remove crowdsecurity/virtual-patching --interactive`,
7169
},
7270
upgradeHelp: cliHelp{
7371
example: `# Upgrade some appsec-configs. If they are not currently installed, they are downloaded but not installed.
@@ -82,10 +80,9 @@ cscli appsec-configs upgrade crowdsecurity/virtual-patching --dry-run -o raw
8280
# Upgrade over tainted items. Can be used to restore or repair after local modifications or missing dependencies.
8381
cscli appsec-configs upgrade crowdsecurity/virtual-patching --force
8482
85-
# Proceed without prompting.
86-
cscli appsec-configs upgrade crowdsecurity/virtual-patching --yes
87-
88-
# The "--yes" parameter is implied when the command is not connected to a terminal, like pipes or scripts.`,
83+
# Prompt for confirmation if running in an interactive terminal; otherwise, the option is ignored.
84+
cscli appsec-configs upgrade crowdsecurity/virtual-patching -i
85+
cscli appsec-configs upgrade crowdsecurity/virtual-patching --interactive`,
8986
},
9087
inspectHelp: cliHelp{
9188
example: `# Display metadata, state, metrics and ancestor collections of appsec-configs (installed or not).
@@ -183,10 +180,9 @@ cscli appsec-rules install crowdsecurity/crs --download-only
183180
# Install over tainted items. Can be used to restore or repair after local modifications or missing dependencies.
184181
cscli appsec-rules install crowdsecurity/crs --force
185182
186-
# Proceed without prompting.
187-
cscli appsec-rules install crowdsecurity/crs --yes
188-
189-
# The "--yes" parameter is implied when the command is not connected to a terminal, like pipes or scripts.`,
183+
# Prompt for confirmation if running in an interactive terminal; otherwise, the option is ignored.
184+
cscli appsec-rules install crowdsecurity/crs -i
185+
cscli appsec-rules install crowdsecurity/crs --interactive`,
190186
},
191187
removeHelp: cliHelp{
192188
example: `# Uninstall some appsec-rules.
@@ -204,10 +200,9 @@ cscli appsec-rules remove crowdsecurity/crs --purge
204200
# Remove tainted items.
205201
cscli appsec-rules remove crowdsecurity/crs --force
206202
207-
# Proceed without prompting.
208-
cscli appsec-rules remove crowdsecurity/crs --yes
209-
210-
# The "--yes" parameter is implied when the command is not connected to a terminal, like pipes or scripts.`,
203+
# Prompt for confirmation if running in an interactive terminal; otherwise, the option is ignored.
204+
cscli appsec-rules remove crowdsecurity/crs -i
205+
cscli appsec-rules remove crowdsecurity/crs --interactive`,
211206
},
212207
upgradeHelp: cliHelp{
213208
example: `# Upgrade some appsec-rules. If they are not currently installed, they are downloaded but not installed.
@@ -222,10 +217,9 @@ cscli appsec-rules upgrade crowdsecurity/crs --dry-run -o raw
222217
# Upgrade over tainted items. Can be used to restore or repair after local modifications or missing dependencies.
223218
cscli appsec-rules upgrade crowdsecurity/crs --force
224219
225-
# Proceed without prompting.
226-
cscli appsec-rules upgrade crowdsecurity/crs --yes
227-
228-
# The "--yes" parameter is implied when the command is not connected to a terminal, like pipes or scripts.`,
220+
# Prompt for confirmation if running in an interactive terminal; otherwise, the option is ignored.
221+
cscli appsec-rules upgrade crowdsecurity/crs -i
222+
cscli appsec-rules upgrade crowdsecurity/crs --interactive`,
229223
},
230224
inspectHelp: cliHelp{
231225
example: `# Display metadata, state, metrics and ancestor collections of appsec-rules (installed or not).

cmd/crowdsec-cli/cliitem/hubcollection.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ cscli collections install crowdsecurity/http-cve crowdsecurity/iptables --downlo
3434
# Install over tainted items. Can be used to restore or repair after local modifications or missing dependencies.
3535
cscli collections install crowdsecurity/http-cve crowdsecurity/iptables --force
3636
37-
# Proceed without prompting.
38-
cscli collections install crowdsecurity/http-cve crowdsecurity/iptables --yes
39-
40-
# The "--yes" parameter is implied when the command is not connected to a terminal, like pipes or scripts.`,
37+
# Prompt for confirmation if running in an interactive terminal; otherwise, the option is ignored.
38+
cscli collections install crowdsecurity/http-cve crowdsecurity/iptables -i
39+
cscli collections install crowdsecurity/http-cve crowdsecurity/iptables --interactive`,
4140
},
4241
removeHelp: cliHelp{
4342
example: `# Uninstall some collections.
@@ -55,10 +54,9 @@ cscli collections remove crowdsecurity/http-cve crowdsecurity/iptables --purge
5554
# Remove tainted items.
5655
cscli collections remove crowdsecurity/http-cve crowdsecurity/iptables --force
5756
58-
# Proceed without prompting.
59-
cscli collections remove crowdsecurity/http-cve crowdsecurity/iptables --yes
60-
61-
# The "--yes" parameter is implied when the command is not connected to a terminal, like pipes or scripts.`,
57+
# Prompt for confirmation if running in an interactive terminal; otherwise, the option is ignored.
58+
cscli collections remove crowdsecurity/http-cve crowdsecurity/iptables -i
59+
cscli collections remove crowdsecurity/http-cve crowdsecurity/iptables --interactive`,
6260
},
6361
upgradeHelp: cliHelp{
6462
example: `# Upgrade some collections. If they are not currently installed, they are downloaded but not installed.
@@ -73,10 +71,9 @@ cscli collections upgrade crowdsecurity/http-cve crowdsecurity/iptables --dry-ru
7371
# Upgrade over tainted items. Can be used to restore or repair after local modifications or missing dependencies.
7472
cscli collections upgrade crowdsecurity/http-cve crowdsecurity/iptables --force
7573
76-
# Proceed without prompting.
77-
cscli collections upgrade crowdsecurity/http-cve crowdsecurity/iptables --yes
78-
79-
# The "--yes" parameter is implied when the command is not connected to a terminal, like pipes or scripts.`,
74+
# Prompt for confirmation if running in an interactive terminal; otherwise, the option is ignored.
75+
cscli collections upgrade crowdsecurity/http-cve crowdsecurity/iptables -i
76+
cscli collections upgrade crowdsecurity/http-cve crowdsecurity/iptables --interactive`,
8077
},
8178
inspectHelp: cliHelp{
8279
example: `# Display metadata, state, metrics and dependencies of collections (installed or not).

cmd/crowdsec-cli/cliitem/hubcontext.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ cscli contexts install crowdsecurity/bf_base crowdsecurity/fortinet --download-o
3434
# Install over tainted items. Can be used to restore or repair after local modifications or missing dependencies.
3535
cscli contexts install crowdsecurity/bf_base crowdsecurity/fortinet --force
3636
37-
# Proceed without prompting.
38-
cscli contexts install crowdsecurity/bf_base crowdsecurity/fortinet --yes
39-
40-
# The "--yes" parameter is implied when the command is not connected to a terminal, like pipes or scripts.`,
37+
# Prompt for confirmation if running in an interactive terminal; otherwise, the option is ignored.
38+
cscli contexts install crowdsecurity/bf_base crowdsecurity/fortinet -i
39+
cscli contexts install crowdsecurity/bf_base crowdsecurity/fortinet --interactive`,
4140
},
4241
removeHelp: cliHelp{
4342
example: `# Uninstall some contexts.
@@ -55,10 +54,9 @@ cscli contexts remove crowdsecurity/bf_base crowdsecurity/fortinet --purge
5554
# Remove tainted items.
5655
cscli contexts remove crowdsecurity/bf_base crowdsecurity/fortinet --force
5756
58-
# Proceed without prompting.
59-
cscli contexts remove crowdsecurity/bf_base crowdsecurity/fortinet --yes
60-
61-
# The "--yes" parameter is implied when the command is not connected to a terminal, like pipes or scripts.`,
57+
# Prompt for confirmation if running in an interactive terminal; otherwise, the option is ignored.
58+
cscli contexts remove crowdsecurity/bf_base crowdsecurity/fortinet -i
59+
cscli contexts remove crowdsecurity/bf_base crowdsecurity/fortinet --interactive`,
6260
},
6361
upgradeHelp: cliHelp{
6462
example: `# Upgrade some contexts. If they are not currently installed, they are downloaded but not installed.
@@ -73,10 +71,9 @@ cscli contexts upgrade crowdsecurity/bf_base crowdsecurity/fortinet --dry-run -o
7371
# Upgrade over tainted items. Can be used to restore or repair after local modifications or missing dependencies.
7472
cscli contexts upgrade crowdsecurity/bf_base crowdsecurity/fortinet --force
7573
76-
# Proceed without prompting.
77-
cscli contexts upgrade crowdsecurity/bf_base crowdsecurity/fortinet --yes
78-
79-
# The "--yes" parameter is implied when the command is not connected to a terminal, like pipes or scripts.`,
74+
# Prompt for confirmation if running in an interactive terminal; otherwise, the option is ignored.
75+
cscli contexts upgrade crowdsecurity/bf_base crowdsecurity/fortinet -i
76+
cscli contexts upgrade crowdsecurity/bf_base crowdsecurity/fortinet --interactive`,
8077
},
8178
inspectHelp: cliHelp{
8279
example: `# Display metadata, state and ancestor collections of contexts (installed or not).

0 commit comments

Comments
 (0)