handling when no args are provided

This commit is contained in:
Diamon Wiggins
2022-09-14 00:36:04 -04:00
parent ec6ec59303
commit e7fe012f2f
2 changed files with 16 additions and 4 deletions
+3 -3
View File
@@ -17,7 +17,7 @@ import (
func RootCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "support-bundle [url]",
Args: cobra.MinimumNArgs(1),
Args: cobra.MinimumNArgs(0),
Short: "Generate a support bundle",
Long: `A support bundle is an archive of files, output, metrics and state
from a server that can be used to assist when troubleshooting a Kubernetes cluster.`,
@@ -47,8 +47,8 @@ from a server that can be used to assist when troubleshooting a Kubernetes clust
cmd.Flags().Bool("redact", true, "enable/disable default redactions")
cmd.Flags().Bool("interactive", true, "enable/disable interactive mode")
cmd.Flags().Bool("collect-without-permissions", true, "always generate a support bundle, even if it some require additional permissions")
cmd.Flags().StringSliceP("selector", "l", []string{"troubleshoot.io/kind=supportbundle-spec"}, "Selector to filter on for loading additional support bundle specs found in secrets within the cluster")
cmd.Flags().Bool("load-cluster-specs", false, "enable/disable loading additional support bundle specs found in secrets within the cluster")
cmd.Flags().StringSliceP("selector", "l", []string{"troubleshoot.io/kind=supportbundle-spec"}, "selector to filter on for loading additional support bundle specs found in secrets within the cluster")
cmd.Flags().Bool("load-cluster-specs", false, "enable/disable loading additional support bundle specs found in secrets within the cluster. required when no specs are provided on the command line")
cmd.Flags().String("since-time", "", "force pod logs collectors to return logs after a specific date (RFC3339)")
cmd.Flags().String("since", "", "force pod logs collectors to return logs newer than a relative duration like 5s, 2m, or 3h.")
cmd.Flags().StringP("output", "o", "", "specify the output file path for the support bundle")
+13 -1
View File
@@ -38,6 +38,10 @@ const (
)
func runTroubleshoot(v *viper.Viper, arg []string) error {
if v.GetBool("load-cluster-specs") == false && len(arg) == 0 {
return errors.New("flag load-cluster-specs must be set if no specs are provided on the command line")
}
interactive := v.GetBool("interactive") && isatty.IsTerminal(os.Stdout.Fd())
if interactive {
@@ -139,7 +143,11 @@ func runTroubleshoot(v *viper.Viper, arg []string) error {
return errors.Wrap(err, "failed to parse support bundle spec")
}
mainBundle = supportbundle.ConcatSpec(mainBundle, parsedBundlesFromSecrets)
if mainBundle == nil {
mainBundle = parsedBundlesFromSecrets
} else {
supportbundle.ConcatSpec(mainBundle, parsedBundlesFromSecrets)
}
parsedRedactors, err := supportbundle.ParseRedactorsFromSpec(multidocs)
if err != nil {
@@ -150,6 +158,10 @@ func runTroubleshoot(v *viper.Viper, arg []string) error {
}
}
if mainBundle == nil {
return errors.New("no specs provided to run")
}
for idx, redactor := range v.GetStringSlice("redactors") {
redactorObj, err := supportbundle.GetRedactorFromURI(redactor)
if err != nil {