mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-11 20:36:12 +02:00
fix "cscli [machines|bouncers] delete" autocompletion (#3101)
* fix "cscli [machines|bouncers] delete" autocompletion * func test
This commit is contained in:
parent
1acc35442c
commit
27935f6d4c
4 changed files with 62 additions and 2 deletions
|
@ -206,10 +206,28 @@ cscli bouncers add MyBouncerName --key <random-key>`,
|
|||
return cmd
|
||||
}
|
||||
|
||||
func (cli *cliBouncers) deleteValid(_ *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
func (cli *cliBouncers) deleteValid(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
// need to load config and db because PersistentPreRunE is not called for completions
|
||||
|
||||
var err error
|
||||
|
||||
cfg := cli.cfg()
|
||||
|
||||
if err = require.LAPI(cfg); err != nil {
|
||||
cobra.CompError("unable to list bouncers " + err.Error())
|
||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
|
||||
cli.db, err = require.DBClient(cmd.Context(), cfg.DbConfig)
|
||||
if err != nil {
|
||||
cobra.CompError("unable to list bouncers " + err.Error())
|
||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
|
||||
bouncers, err := cli.db.ListBouncers()
|
||||
if err != nil {
|
||||
cobra.CompError("unable to list bouncers " + err.Error())
|
||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
|
||||
ret := []string{}
|
||||
|
|
|
@ -349,10 +349,28 @@ func (cli *cliMachines) add(args []string, machinePassword string, dumpFile stri
|
|||
return nil
|
||||
}
|
||||
|
||||
func (cli *cliMachines) deleteValid(_ *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
func (cli *cliMachines) deleteValid(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
// need to load config and db because PersistentPreRunE is not called for completions
|
||||
|
||||
var err error
|
||||
|
||||
cfg := cli.cfg()
|
||||
|
||||
if err = require.LAPI(cfg); err != nil {
|
||||
cobra.CompError("unable to list machines " + err.Error())
|
||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
|
||||
cli.db, err = require.DBClient(cmd.Context(), cfg.DbConfig)
|
||||
if err != nil {
|
||||
cobra.CompError("unable to list machines " + err.Error())
|
||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
|
||||
machines, err := cli.db.ListMachines()
|
||||
if err != nil {
|
||||
cobra.CompError("unable to list machines " + err.Error())
|
||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
|
||||
ret := []string{}
|
||||
|
|
|
@ -42,6 +42,18 @@ teardown() {
|
|||
assert_json '[]'
|
||||
}
|
||||
|
||||
@test "bouncers delete has autocompletion" {
|
||||
rune -0 cscli bouncers add foo1
|
||||
rune -0 cscli bouncers add foo2
|
||||
rune -0 cscli bouncers add bar
|
||||
rune -0 cscli bouncers add baz
|
||||
rune -0 cscli __complete bouncers delete 'foo'
|
||||
assert_line --index 0 'foo1'
|
||||
assert_line --index 1 'foo2'
|
||||
refute_line 'bar'
|
||||
refute_line 'baz'
|
||||
}
|
||||
|
||||
@test "cscli bouncers list" {
|
||||
export API_KEY=bouncerkey
|
||||
rune -0 cscli bouncers add ciTestBouncer --key "$API_KEY"
|
||||
|
|
|
@ -62,6 +62,18 @@ teardown() {
|
|||
assert_output 1
|
||||
}
|
||||
|
||||
@test "machines delete has autocompletion" {
|
||||
rune -0 cscli machines add -a -f /dev/null foo1
|
||||
rune -0 cscli machines add -a -f /dev/null foo2
|
||||
rune -0 cscli machines add -a -f /dev/null bar
|
||||
rune -0 cscli machines add -a -f /dev/null baz
|
||||
rune -0 cscli __complete machines delete 'foo'
|
||||
assert_line --index 0 'foo1'
|
||||
assert_line --index 1 'foo2'
|
||||
refute_line 'bar'
|
||||
refute_line 'baz'
|
||||
}
|
||||
|
||||
@test "heartbeat is initially null" {
|
||||
rune -0 cscli machines add foo --auto --file /dev/null
|
||||
rune -0 cscli machines list -o json
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue