Run cscli hubtest without being root (#1658)
This commit is contained in:
parent
8decbe7670
commit
24b1a99c42
|
@ -51,6 +51,8 @@ func initConfig() {
|
||||||
}
|
}
|
||||||
logFormatter := &log.TextFormatter{TimestampFormat: "02-01-2006 03:04:05 PM", FullTimestamp: true}
|
logFormatter := &log.TextFormatter{TimestampFormat: "02-01-2006 03:04:05 PM", FullTimestamp: true}
|
||||||
log.SetFormatter(logFormatter)
|
log.SetFormatter(logFormatter)
|
||||||
|
|
||||||
|
if !inSlice(os.Args[1], NoNeedConfig) {
|
||||||
csConfig, err = csconfig.NewConfig(ConfigFilePath, false, false)
|
csConfig, err = csconfig.NewConfig(ConfigFilePath, false, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf(err.Error())
|
log.Fatalf(err.Error())
|
||||||
|
@ -59,6 +61,9 @@ func initConfig() {
|
||||||
if err := csConfig.LoadCSCLI(); err != nil {
|
if err := csConfig.LoadCSCLI(); err != nil {
|
||||||
log.Fatalf(err.Error())
|
log.Fatalf(err.Error())
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
csConfig = csconfig.NewDefaultConfig()
|
||||||
|
}
|
||||||
|
|
||||||
if csConfig.Cscli == nil {
|
if csConfig.Cscli == nil {
|
||||||
log.Fatalf("missing 'cscli' configuration in '%s', exiting", ConfigFilePath)
|
log.Fatalf("missing 'cscli' configuration in '%s', exiting", ConfigFilePath)
|
||||||
|
@ -76,7 +81,6 @@ func initConfig() {
|
||||||
if csConfig.Cscli.Output == "" {
|
if csConfig.Cscli.Output == "" {
|
||||||
csConfig.Cscli.Output = "human"
|
csConfig.Cscli.Output = "human"
|
||||||
}
|
}
|
||||||
|
|
||||||
if csConfig.Cscli.Output == "json" {
|
if csConfig.Cscli.Output == "json" {
|
||||||
log.SetFormatter(&log.JSONFormatter{})
|
log.SetFormatter(&log.JSONFormatter{})
|
||||||
log.SetLevel(log.ErrorLevel)
|
log.SetLevel(log.ErrorLevel)
|
||||||
|
@ -107,6 +111,15 @@ func linkHandler(name string) string {
|
||||||
return fmt.Sprintf("/cscli/%s", name)
|
return fmt.Sprintf("/cscli/%s", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
NoNeedConfig = []string{
|
||||||
|
"help",
|
||||||
|
"completion",
|
||||||
|
"version",
|
||||||
|
"hubtest",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
|
@ -158,7 +171,7 @@ It is meant to allow you to manage bans, parsers/scenarios/etc, api and generall
|
||||||
log.Fatalf("failed to hide flag: %s", err)
|
log.Fatalf("failed to hide flag: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(os.Args) > 1 && os.Args[1] != "completion" && os.Args[1] != "version" && os.Args[1] != "help" {
|
if len(os.Args) > 1 {
|
||||||
cobra.OnInitialize(initConfig)
|
cobra.OnInitialize(initConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue