diff --git a/opencloud/pkg/command/backup.go b/opencloud/pkg/command/backup.go index 05b922474..19a862296 100644 --- a/opencloud/pkg/command/backup.go +++ b/opencloud/pkg/command/backup.go @@ -34,17 +34,11 @@ func ConsistencyCommand(cfg *config.Config) *cobra.Command { Use: "consistency", Short: "check backup consistency", RunE: func(cmd *cobra.Command, args []string) error { - basePath, _ := cmd.Flags().GetString("basepath") - if basePath == "" { - fmt.Println("basepath is required") - _ = cmd.Help() - return nil - } - var ( bs backup.ListBlobstore err error ) + basePath, _ := cmd.Flags().GetString("basepath") blobstoreFlag, _ := cmd.Flags().GetString("blobstore") switch blobstoreFlag { case "decomposeds3": @@ -77,10 +71,7 @@ func ConsistencyCommand(cfg *config.Config) *cobra.Command { }, } consCmd.Flags().StringP("basepath", "p", "", "the basepath of the decomposedfs (e.g. /var/tmp/opencloud/storage/users)") - err := consCmd.MarkFlagRequired("basepath") - if err != nil { - fmt.Println(err) - } + _ = consCmd.MarkFlagRequired("basepath") consCmd.Flags().StringP("blobstore", "b", "decomposed", "the blobstore type. Can be (none, decomposed, decomposeds3). Default decomposed") consCmd.Flags().Bool("fail", false, "exit with non-zero status if consistency check fails") return consCmd diff --git a/opencloud/pkg/command/decomposedfs.go b/opencloud/pkg/command/decomposedfs.go index d2f64ec93..32516e336 100644 --- a/opencloud/pkg/command/decomposedfs.go +++ b/opencloud/pkg/command/decomposedfs.go @@ -52,15 +52,9 @@ func checkCmd(_ *config.Config) *cobra.Command { RunE: check, } cCmd.Flags().StringP("root", "r", "", "Path to the root directory of the decomposedfs") - err := cCmd.MarkFlagRequired("root") - if err != nil { - fmt.Println(err) - } + _ = cCmd.MarkFlagRequired("root") cCmd.Flags().StringP("node", "n", "", "Space ID of the Space to inspect") - err = cCmd.MarkFlagRequired("node") - if err != nil { - fmt.Println(err) - } + _ = cCmd.MarkFlagRequired("node") cCmd.Flags().Bool("repair", false, "Try to repair nodes with incorrect treesize metadata. IMPORTANT: Only use this while OpenCloud is not running.") cCmd.Flags().Bool("force", false, "Do not prompt for confirmation when running in repair mode.") @@ -187,15 +181,9 @@ func metadataCmd(cfg *config.Config) *cobra.Command { } metaCmd.AddCommand(dumpCmd(cfg), getCmd(cfg), setCmd(cfg)) metaCmd.Flags().StringP("root", "r", "", "Path to the root directory of the decomposedfs") - err := metaCmd.MarkFlagRequired("root") - if err != nil { - fmt.Println(err) - } + _ = metaCmd.MarkFlagRequired("root") metaCmd.Flags().StringP("node", "n", "", "Path to or ID of the node to inspect") - err = metaCmd.MarkFlagRequired("node") - if err != nil { - fmt.Println(err) - } + _ = metaCmd.MarkFlagRequired("node") return metaCmd } @@ -285,16 +273,10 @@ func setCmd(_ *config.Config) *cobra.Command { }, } sCmd.Flags().StringP("attribute", "a", "", "attribute to inspect, can be a glob pattern (e.g. 'user.*' will match all attributes starting with 'user.').") - err := sCmd.MarkFlagRequired("attribute") - if err != nil { - fmt.Println(err) - } + _ = sCmd.MarkFlagRequired("attribute") sCmd.Flags().StringP("value", "v", "", "value to set") - err = sCmd.MarkFlagRequired("value") - if err != nil { - fmt.Println(err) - } + _ = sCmd.MarkFlagRequired("value") return sCmd } diff --git a/opencloud/pkg/command/revisions.go b/opencloud/pkg/command/revisions.go index f8c928c49..212388759 100644 --- a/opencloud/pkg/command/revisions.go +++ b/opencloud/pkg/command/revisions.go @@ -46,11 +46,6 @@ func PurgeRevisionsCommand(cfg *config.Config) *cobra.Command { Short: "purge revisions", RunE: func(cmd *cobra.Command, args []string) error { basePath, _ := cmd.Flags().GetString("basepath") - if basePath == "" { - fmt.Println("basepath is required") - _ = cmd.Help() - return nil - } var ( bs revisions.DelBlobstore @@ -128,6 +123,7 @@ func PurgeRevisionsCommand(cfg *config.Config) *cobra.Command { }, } revCmd.Flags().StringP("basepath", "p", "", "the basepath of the decomposedfs (e.g. /var/tmp/opencloud/storage/metadata)") + _ = revCmd.MarkFlagRequired("basepath") revCmd.Flags().StringP("blobstore", "b", "decomposed", "the blobstore type. Can be (none, decomposed, decomposeds3). Default decomposed") revCmd.Flags().Bool("dry-run", true, "do not delete anything, just print what would be deleted") revCmd.Flags().BoolP("verbose", "v", false, "print verbose output") diff --git a/opencloud/pkg/command/shares.go b/opencloud/pkg/command/shares.go index 0bb3c9b2a..f9cd84180 100644 --- a/opencloud/pkg/command/shares.go +++ b/opencloud/pkg/command/shares.go @@ -2,7 +2,6 @@ package command import ( "errors" - "fmt" "github.com/opencloud-eu/opencloud/opencloud/pkg/register" "github.com/opencloud-eu/opencloud/pkg/config" @@ -66,24 +65,14 @@ func cleanupCmd(cfg *config.Config) *cobra.Command { }, } cleanCmd.Flags().String("service-account-id", "", "Name of the service account to use for the cleanup") - err := viper.BindEnv("service-account-id", "OC_SERVICE_ACCOUNT_ID") - if err != nil { - fmt.Printf("Could not bind environment variable OC_SERVICE_ACCOUNT_ID: %s", err) - } - err = viper.BindPFlag("service-account-id", cleanCmd.Flags().Lookup("service-account-id")) - if err != nil { - fmt.Printf("Could not bind flag OC_SERVICE_ACCOUNT_ID: %s", err) - } + _ = cleanCmd.MarkFlagRequired("service-account-id") + _ = viper.BindEnv("service-account-id", "OC_SERVICE_ACCOUNT_ID") + _ = viper.BindPFlag("service-account-id", cleanCmd.Flags().Lookup("service-account-id")) cleanCmd.Flags().String("service-account-secret", "", "Secret for the service account") - err = viper.BindEnv("service-account-secret", "OC_SERVICE_ACCOUNT_SECRET") - if err != nil { - fmt.Printf("Could not bind environment variable OC_SERVICE_ACCOUNT_SECRET: %s", err) - } - err = viper.BindPFlag("service-account-secret", cleanCmd.Flags().Lookup("service-account-secret")) - if err != nil { - fmt.Printf("Could not bind flag OC_SERVICE_ACCOUNT_SECRET: %s", err) - } + _ = cleanCmd.MarkFlagRequired("service-account-secret") + _ = viper.BindEnv("service-account-secret", "OC_SERVICE_ACCOUNT_SECRET") + _ = viper.BindPFlag("service-account-secret", cleanCmd.Flags().Lookup("service-account-secret")) return cleanCmd } diff --git a/opencloud/pkg/command/trash.go b/opencloud/pkg/command/trash.go index 06210c012..18b0979bd 100644 --- a/opencloud/pkg/command/trash.go +++ b/opencloud/pkg/command/trash.go @@ -35,12 +35,6 @@ func TrashPurgeEmptyDirsCommand(cfg *config.Config) *cobra.Command { Short: "purge empty directories", RunE: func(cmd *cobra.Command, args []string) error { basePath, _ := cmd.Flags().GetString("basepath") - if basePath == "" { - fmt.Println("basepath is required") - _ = cmd.Help() - return nil - } - dryRun, _ := cmd.Flags().GetBool("dry-run") if err := trash.PurgeTrashEmptyPaths(basePath, dryRun); err != nil { fmt.Println(err) @@ -51,10 +45,7 @@ func TrashPurgeEmptyDirsCommand(cfg *config.Config) *cobra.Command { }, } trashPurgeCmd.Flags().StringP("basepath", "p", "", "the basepath of the decomposedfs (e.g. /var/tmp/opencloud/storage/users)") - err := trashPurgeCmd.MarkFlagRequired("basepath") - if err != nil { - fmt.Println(err) - } + _ = trashPurgeCmd.MarkFlagRequired("basepath") trashPurgeCmd.Flags().Bool("dry-run", true, "do not delete anything, just print what would be deleted")