allow "cscli completion..." without configuration file (#1340)

This commit is contained in:
mmetc 2022-03-10 14:57:14 +01:00 committed by GitHub
parent 8120fe7d5d
commit b6aca81ebd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View file

@ -2,6 +2,7 @@ package main
import (
"fmt"
"os"
"path"
"path/filepath"
"strings"
@ -151,7 +152,11 @@ It is meant to allow you to manage bans, parsers/scenarios/etc, api and generall
if err := rootCmd.PersistentFlags().MarkHidden("branch"); err != nil {
log.Fatalf("failed to make branch hidden : %s", err)
}
cobra.OnInitialize(initConfig)
if os.Args[1] != "completion" {
cobra.OnInitialize(initConfig)
}
/*don't sort flags so we can enforce order*/
rootCmd.Flags().SortFlags = false
rootCmd.PersistentFlags().SortFlags = false

View file

@ -127,3 +127,15 @@ declare stderr
run -0 echo "$stderr"
assert_output --partial "Local Api Metrics:"
}
@test "$FILE 'cscli completion' with or without configuration file" {
run -0 cscli completion bash
assert_output --partial "# bash completion for cscli"
run -0 cscli completion zsh
assert_output --partial "# zsh completion for cscli"
rm "${CONFIG_DIR}/config.yaml"
run -0 cscli completion bash
assert_output --partial "# bash completion for cscli"
run -0 cscli completion zsh
assert_output --partial "# zsh completion for cscli"
}