diff --git a/cmd/root.go b/cmd/root.go index 515c5432..85d78b42 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -36,7 +36,6 @@ func init() { rootCmd.PersistentFlags().BoolP("verbose", "v", false, "Print verbose logging") rootCmd.PersistentFlags().StringP("token", "t", "", "API token from https://app.foundries.io/settings/tokens/") - rootCmd.MarkPersistentFlagRequired("token") if err := viper.BindPFlags(rootCmd.PersistentFlags()); err != nil { fmt.Println(err) @@ -66,6 +65,12 @@ func initConfig() { if viper.GetBool("verbose") { logrus.SetLevel(logrus.DebugLevel) } + if len(viper.GetString("token")) == 0 { + rootCmd.MarkPersistentFlagRequired("token") + } + if len(viper.GetString("factory")) == 0 { + targetsCmd.MarkPersistentFlagRequired("factory") + } api = client.NewApiClient("https://api.foundries.io", viper.GetString("token")) } diff --git a/cmd/targets.go b/cmd/targets.go index dcec740e..6c453ebf 100644 --- a/cmd/targets.go +++ b/cmd/targets.go @@ -16,7 +16,6 @@ var targetsCmd = &cobra.Command{ func init() { rootCmd.AddCommand(targetsCmd) targetsCmd.PersistentFlags().StringP("factory", "f", "", "Factory to list targets for") - targetsCmd.MarkPersistentFlagRequired("factory") if err := viper.BindPFlags(targetsCmd.PersistentFlags()); err != nil { fmt.Println(err)