mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2025-12-19 19:10:29 -06:00
double check required args
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
This commit is contained in:
committed by
Florian Schade
parent
d0e51010bf
commit
61707ab6d0
@@ -34,17 +34,11 @@ func ConsistencyCommand(cfg *config.Config) *cobra.Command {
|
|||||||
Use: "consistency",
|
Use: "consistency",
|
||||||
Short: "check backup consistency",
|
Short: "check backup consistency",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
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 (
|
var (
|
||||||
bs backup.ListBlobstore
|
bs backup.ListBlobstore
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
basePath, _ := cmd.Flags().GetString("basepath")
|
||||||
blobstoreFlag, _ := cmd.Flags().GetString("blobstore")
|
blobstoreFlag, _ := cmd.Flags().GetString("blobstore")
|
||||||
switch blobstoreFlag {
|
switch blobstoreFlag {
|
||||||
case "decomposeds3":
|
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)")
|
consCmd.Flags().StringP("basepath", "p", "", "the basepath of the decomposedfs (e.g. /var/tmp/opencloud/storage/users)")
|
||||||
err := consCmd.MarkFlagRequired("basepath")
|
_ = consCmd.MarkFlagRequired("basepath")
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
consCmd.Flags().StringP("blobstore", "b", "decomposed", "the blobstore type. Can be (none, decomposed, decomposeds3). Default decomposed")
|
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")
|
consCmd.Flags().Bool("fail", false, "exit with non-zero status if consistency check fails")
|
||||||
return consCmd
|
return consCmd
|
||||||
|
|||||||
@@ -52,15 +52,9 @@ func checkCmd(_ *config.Config) *cobra.Command {
|
|||||||
RunE: check,
|
RunE: check,
|
||||||
}
|
}
|
||||||
cCmd.Flags().StringP("root", "r", "", "Path to the root directory of the decomposedfs")
|
cCmd.Flags().StringP("root", "r", "", "Path to the root directory of the decomposedfs")
|
||||||
err := cCmd.MarkFlagRequired("root")
|
_ = cCmd.MarkFlagRequired("root")
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
cCmd.Flags().StringP("node", "n", "", "Space ID of the Space to inspect")
|
cCmd.Flags().StringP("node", "n", "", "Space ID of the Space to inspect")
|
||||||
err = cCmd.MarkFlagRequired("node")
|
_ = cCmd.MarkFlagRequired("node")
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
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("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.")
|
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.AddCommand(dumpCmd(cfg), getCmd(cfg), setCmd(cfg))
|
||||||
metaCmd.Flags().StringP("root", "r", "", "Path to the root directory of the decomposedfs")
|
metaCmd.Flags().StringP("root", "r", "", "Path to the root directory of the decomposedfs")
|
||||||
err := metaCmd.MarkFlagRequired("root")
|
_ = metaCmd.MarkFlagRequired("root")
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
metaCmd.Flags().StringP("node", "n", "", "Path to or ID of the node to inspect")
|
metaCmd.Flags().StringP("node", "n", "", "Path to or ID of the node to inspect")
|
||||||
err = metaCmd.MarkFlagRequired("node")
|
_ = metaCmd.MarkFlagRequired("node")
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
return metaCmd
|
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.').")
|
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")
|
_ = sCmd.MarkFlagRequired("attribute")
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
sCmd.Flags().StringP("value", "v", "", "value to set")
|
sCmd.Flags().StringP("value", "v", "", "value to set")
|
||||||
err = sCmd.MarkFlagRequired("value")
|
_ = sCmd.MarkFlagRequired("value")
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return sCmd
|
return sCmd
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,11 +46,6 @@ func PurgeRevisionsCommand(cfg *config.Config) *cobra.Command {
|
|||||||
Short: "purge revisions",
|
Short: "purge revisions",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
basePath, _ := cmd.Flags().GetString("basepath")
|
basePath, _ := cmd.Flags().GetString("basepath")
|
||||||
if basePath == "" {
|
|
||||||
fmt.Println("basepath is required")
|
|
||||||
_ = cmd.Help()
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
bs revisions.DelBlobstore
|
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.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().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().Bool("dry-run", true, "do not delete anything, just print what would be deleted")
|
||||||
revCmd.Flags().BoolP("verbose", "v", false, "print verbose output")
|
revCmd.Flags().BoolP("verbose", "v", false, "print verbose output")
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package command
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/opencloud-eu/opencloud/opencloud/pkg/register"
|
"github.com/opencloud-eu/opencloud/opencloud/pkg/register"
|
||||||
"github.com/opencloud-eu/opencloud/pkg/config"
|
"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")
|
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")
|
_ = cleanCmd.MarkFlagRequired("service-account-id")
|
||||||
if err != nil {
|
_ = viper.BindEnv("service-account-id", "OC_SERVICE_ACCOUNT_ID")
|
||||||
fmt.Printf("Could not bind environment variable OC_SERVICE_ACCOUNT_ID: %s", err)
|
_ = viper.BindPFlag("service-account-id", cleanCmd.Flags().Lookup("service-account-id"))
|
||||||
}
|
|
||||||
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.Flags().String("service-account-secret", "", "Secret for the service account")
|
cleanCmd.Flags().String("service-account-secret", "", "Secret for the service account")
|
||||||
err = viper.BindEnv("service-account-secret", "OC_SERVICE_ACCOUNT_SECRET")
|
_ = cleanCmd.MarkFlagRequired("service-account-secret")
|
||||||
if err != nil {
|
_ = viper.BindEnv("service-account-secret", "OC_SERVICE_ACCOUNT_SECRET")
|
||||||
fmt.Printf("Could not bind environment variable OC_SERVICE_ACCOUNT_SECRET: %s", err)
|
_ = viper.BindPFlag("service-account-secret", cleanCmd.Flags().Lookup("service-account-secret"))
|
||||||
}
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
return cleanCmd
|
return cleanCmd
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,12 +35,6 @@ func TrashPurgeEmptyDirsCommand(cfg *config.Config) *cobra.Command {
|
|||||||
Short: "purge empty directories",
|
Short: "purge empty directories",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
basePath, _ := cmd.Flags().GetString("basepath")
|
basePath, _ := cmd.Flags().GetString("basepath")
|
||||||
if basePath == "" {
|
|
||||||
fmt.Println("basepath is required")
|
|
||||||
_ = cmd.Help()
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
dryRun, _ := cmd.Flags().GetBool("dry-run")
|
dryRun, _ := cmd.Flags().GetBool("dry-run")
|
||||||
if err := trash.PurgeTrashEmptyPaths(basePath, dryRun); err != nil {
|
if err := trash.PurgeTrashEmptyPaths(basePath, dryRun); err != nil {
|
||||||
fmt.Println(err)
|
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)")
|
trashPurgeCmd.Flags().StringP("basepath", "p", "", "the basepath of the decomposedfs (e.g. /var/tmp/opencloud/storage/users)")
|
||||||
err := trashPurgeCmd.MarkFlagRequired("basepath")
|
_ = trashPurgeCmd.MarkFlagRequired("basepath")
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
trashPurgeCmd.Flags().Bool("dry-run", true, "do not delete anything, just print what would be deleted")
|
trashPurgeCmd.Flags().Bool("dry-run", true, "do not delete anything, just print what would be deleted")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user