replace more .Value.String() occurences
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
This commit is contained in:
committed by
Florian Schade
parent
032c218789
commit
d0e51010bf
@@ -45,7 +45,8 @@ func ConsistencyCommand(cfg *config.Config) *cobra.Command {
|
||||
bs backup.ListBlobstore
|
||||
err error
|
||||
)
|
||||
switch cmd.Flag("blobstore").Value.String() {
|
||||
blobstoreFlag, _ := cmd.Flags().GetString("blobstore")
|
||||
switch blobstoreFlag {
|
||||
case "decomposeds3":
|
||||
bs, err = decomposeds3bs.New(
|
||||
cfg.StorageUsers.Drivers.DecomposedS3.Endpoint,
|
||||
|
||||
@@ -45,7 +45,7 @@ func init() {
|
||||
register.AddCommand(DecomposedfsCommand)
|
||||
}
|
||||
|
||||
func checkCmd(cfg *config.Config) *cobra.Command {
|
||||
func checkCmd(_ *config.Config) *cobra.Command {
|
||||
cCmd := &cobra.Command{
|
||||
Use: "check-treesize",
|
||||
Short: `cli tool to check the treesize metadata of a Space`,
|
||||
@@ -108,6 +108,9 @@ func check(cmd *cobra.Command, args []string) error {
|
||||
})
|
||||
|
||||
treeSize, err := walkTree(ctx, tree, lu, n, repairFlag)
|
||||
if err != nil {
|
||||
fmt.Printf("failed to walk tree of node %s: %s\n", n.ID, err)
|
||||
}
|
||||
treesizeFromMetadata, err := n.GetTreeSize(cmd.Context())
|
||||
if err != nil {
|
||||
fmt.Printf("failed to read treesize of node: %s: %s\n", n.ID, err)
|
||||
@@ -196,7 +199,7 @@ func metadataCmd(cfg *config.Config) *cobra.Command {
|
||||
return metaCmd
|
||||
}
|
||||
|
||||
func dumpCmd(cfg *config.Config) *cobra.Command {
|
||||
func dumpCmd(_ *config.Config) *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "dump",
|
||||
Short: `print the metadata of the given node. String attributes will be enclosed in quotes. Binary attributes will be returned encoded as base64 with their value being prefixed with '0s'.`,
|
||||
@@ -212,13 +215,14 @@ func dumpCmd(cfg *config.Config) *cobra.Command {
|
||||
fmt.Println("Error reading attributes")
|
||||
return err
|
||||
}
|
||||
printAttribs(attribs, cmd.Flag("attribute").Value.String())
|
||||
attributeFlag, _ := cmd.Flags().GetString("attribute")
|
||||
printAttribs(attribs, attributeFlag)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func getCmd(cfg *config.Config) *cobra.Command {
|
||||
func getCmd(_ *config.Config) *cobra.Command {
|
||||
gCmd := &cobra.Command{
|
||||
Use: "get",
|
||||
Short: `print a specific attribute of the given node. String attributes will be enclosed in quotes. Binary attributes will be returned encoded as base64 with their value being prefixed with '0s'.`,
|
||||
@@ -234,7 +238,8 @@ func getCmd(cfg *config.Config) *cobra.Command {
|
||||
fmt.Println("Error reading attributes")
|
||||
return err
|
||||
}
|
||||
printAttribs(attribs, cmd.Flag("attribute").Value.String())
|
||||
attributeFlag, _ := cmd.Flags().GetString("attribute")
|
||||
printAttribs(attribs, attributeFlag)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
@@ -242,7 +247,7 @@ func getCmd(cfg *config.Config) *cobra.Command {
|
||||
return gCmd
|
||||
}
|
||||
|
||||
func setCmd(cfg *config.Config) *cobra.Command {
|
||||
func setCmd(_ *config.Config) *cobra.Command {
|
||||
sCmd := &cobra.Command{
|
||||
Use: "set",
|
||||
Short: `manipulate metadata of the given node. Binary attributes can be given hex encoded (prefix by '0x') or base64 encoded (prefix by '0s').`,
|
||||
@@ -270,7 +275,8 @@ func setCmd(cfg *config.Config) *cobra.Command {
|
||||
}
|
||||
}
|
||||
|
||||
err = backend.Set(cmd.Context(), n, cmd.Flag("attribute").Value.String(), []byte(v))
|
||||
attributeFlag, _ := cmd.Flags().GetString("attribute")
|
||||
err = backend.Set(cmd.Context(), n, attributeFlag, []byte(v))
|
||||
if err != nil {
|
||||
fmt.Println("Error setting attribute")
|
||||
return err
|
||||
@@ -293,7 +299,7 @@ func setCmd(cfg *config.Config) *cobra.Command {
|
||||
return sCmd
|
||||
}
|
||||
|
||||
func backend(root, backend string) metadata.Backend {
|
||||
func backend(backend string) metadata.Backend {
|
||||
switch backend {
|
||||
case "xattrs":
|
||||
return metadata.NewXattrsBackend(cache.Config{})
|
||||
@@ -307,7 +313,7 @@ func getBackend(cmd *cobra.Command) (*lookup.Lookup, metadata.Backend) {
|
||||
rootFlag, _ := cmd.Flags().GetString("root")
|
||||
|
||||
bod := lookup.DetectBackendOnDisk(rootFlag)
|
||||
backend := backend(rootFlag, bod)
|
||||
backend := backend(bod)
|
||||
lu := lookup.New(backend, &options.Options{
|
||||
Root: rootFlag,
|
||||
MetadataBackend: bod,
|
||||
|
||||
@@ -33,11 +33,11 @@ func InitCommand(_ *config.Config) *cobra.Command {
|
||||
} else if insecureFlag == strings.ToLower("true") || insecureFlag == strings.ToLower("yes") || insecureFlag == strings.ToLower("y") {
|
||||
insecure = true
|
||||
}
|
||||
forceOverwrite, _ := cmd.Flags().GetBool("force-overwrite")
|
||||
diff, _ := cmd.Flags().GetBool("force-overwrite")
|
||||
err := ocinit.CreateConfig(insecure, forceOverwrite,
|
||||
diff, cmd.Flag("config-path").Value.String(),
|
||||
cmd.Flag("admin-password").Value.String())
|
||||
forceOverwriteFlag, _ := cmd.Flags().GetBool("force-overwrite")
|
||||
diffFlag, _ := cmd.Flags().GetBool("force-overwrite")
|
||||
configPathFlag, _ := cmd.Flags().GetString("config-path")
|
||||
adminPasswordFlag, _ := cmd.Flags().GetString("admin-password")
|
||||
err := ocinit.CreateConfig(insecure, forceOverwriteFlag, diffFlag, configPathFlag, adminPasswordFlag)
|
||||
if err != nil {
|
||||
log.Fatalf("Could not create config: %s", err)
|
||||
}
|
||||
|
||||
@@ -56,7 +56,8 @@ func PurgeRevisionsCommand(cfg *config.Config) *cobra.Command {
|
||||
bs revisions.DelBlobstore
|
||||
err error
|
||||
)
|
||||
switch cmd.Flag("blobstore").Value.String() {
|
||||
blobstoreFlag, _ := cmd.Flags().GetString("blobstore")
|
||||
switch blobstoreFlag {
|
||||
case "decomposeds3":
|
||||
bs, err = decomposeds3bs.New(
|
||||
cfg.StorageUsers.Drivers.DecomposedS3.Endpoint,
|
||||
@@ -79,7 +80,8 @@ func PurgeRevisionsCommand(cfg *config.Config) *cobra.Command {
|
||||
}
|
||||
|
||||
var rid *provider.ResourceId
|
||||
resid, err := storagespace.ParseID(cmd.Flag("resource-id").Value.String())
|
||||
resourceIDFlag, _ := cmd.Flags().GetString("resource-id")
|
||||
resid, err := storagespace.ParseID(resourceIDFlag)
|
||||
if err == nil {
|
||||
rid = &resid
|
||||
}
|
||||
|
||||
@@ -119,8 +119,9 @@ func cleanup(cmd *cobra.Command, cfg *config.Config) error {
|
||||
return configlog.ReturnError(err)
|
||||
}
|
||||
|
||||
serviceUserCtx, err := utils.GetServiceUserContext(cmd.Flag("service-account-id").Value.String(),
|
||||
client, cmd.Flag("service-account-secret").Value.String())
|
||||
serviceAccountIDFlag, _ := cmd.Flags().GetString("service-account-id")
|
||||
serviceAccountSecretFlag, _ := cmd.Flags().GetString("service-account-secret")
|
||||
serviceUserCtx, err := utils.GetServiceUserContext(serviceAccountIDFlag, client, serviceAccountSecretFlag)
|
||||
if err != nil {
|
||||
return configlog.ReturnError(err)
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ func Create(cfg *config.Config) *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
expiry, err := time.ParseDuration(cmd.Flag("expiration").Value.String())
|
||||
expiry, err := cmd.Flags().GetDuration("expiration")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -35,7 +35,8 @@ func ResetPassword(cfg *config.Config) *cobra.Command {
|
||||
ctx, cancel := context.WithCancel(cmd.Context())
|
||||
|
||||
defer cancel()
|
||||
return resetPassword(ctx, logger, cfg, cmd.Flag("user-name").Value.String())
|
||||
userNameFlag, _ := cmd.Flags().GetString("user-name")
|
||||
return resetPassword(ctx, logger, cfg, userNameFlag)
|
||||
},
|
||||
}
|
||||
resetPasswordCmd.Flags().StringP(
|
||||
|
||||
@@ -39,9 +39,10 @@ func RestartPostprocessing(cfg *config.Config) *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
uid, step, _ := cmd.Flags().GetString("upload-id"), ""
|
||||
uid, _ := cmd.Flags().GetString("upload-id")
|
||||
step := ""
|
||||
if uid == "" {
|
||||
step = cmd.Flag("step").Value.String()
|
||||
step, _ = cmd.Flags().GetString("step")
|
||||
}
|
||||
|
||||
restart, _ := cmd.Flags().GetBool("restart")
|
||||
|
||||
@@ -27,8 +27,9 @@ func Index(cfg *config.Config) *cobra.Command {
|
||||
return configlog.ReturnFatal(parser.ParseConfig(cfg))
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
allSpaces, _ := cmd.Flags().GetBool("all-spaces")
|
||||
if cmd.Flag("space").Value.String() == "" && !allSpaces {
|
||||
allSpacesFlag, _ := cmd.Flags().GetBool("all-spaces")
|
||||
spaceFlag, _ := cmd.Flags().GetString("space")
|
||||
if spaceFlag == "" && !allSpacesFlag {
|
||||
return errors.New("either --space or --all-spaces is required")
|
||||
}
|
||||
|
||||
@@ -47,7 +48,7 @@ func Index(cfg *config.Config) *cobra.Command {
|
||||
|
||||
c := searchsvc.NewSearchProviderService("eu.opencloud.api.search", grpcClient)
|
||||
_, err = c.IndexSpace(context.Background(), &searchsvc.IndexSpaceRequest{
|
||||
SpaceId: cmd.Flag("space").Value.String(),
|
||||
SpaceId: spaceFlag,
|
||||
}, func(opts *client.CallOptions) { opts.RequestTimeout = 10 * time.Minute })
|
||||
if err != nil {
|
||||
fmt.Println("failed to index space: " + err.Error())
|
||||
|
||||
@@ -30,16 +30,23 @@ func serveCmd() *cobra.Command {
|
||||
common.Wg.Add(2)
|
||||
|
||||
// set configs
|
||||
opencloudConfig.Set("bin", cmd.Flag("bin").Value.String())
|
||||
opencloudConfig.Set("url", cmd.Flag("url").Value.String())
|
||||
opencloudConfig.Set("retry", cmd.Flag("retry").Value.String())
|
||||
opencloudConfig.Set("adminUsername", cmd.Flag("admin-username").Value.String())
|
||||
opencloudConfig.Set("adminPassword", cmd.Flag("admin-password").Value.String())
|
||||
binFlag, _ := cmd.Flags().GetString("bin")
|
||||
opencloudConfig.Set("bin", binFlag)
|
||||
urlFlag, _ := cmd.Flags().GetString("url")
|
||||
opencloudConfig.Set("url", urlFlag)
|
||||
retryFlag, _ := cmd.Flags().GetString("retry")
|
||||
opencloudConfig.Set("retry", retryFlag)
|
||||
adminUsernameFlag, _ := cmd.Flags().GetString("admin-username")
|
||||
opencloudConfig.Set("adminUsername", adminUsernameFlag)
|
||||
adminPasswordFlag, _ := cmd.Flags().GetString("admin-password")
|
||||
opencloudConfig.Set("adminPassword", adminPasswordFlag)
|
||||
|
||||
if cmd.Flag("skip-OpenCloud-run").Value.String() == "false" {
|
||||
skipOpenCloudRunFlag, _ := cmd.Flags().GetBool("skip-OpenCloud-run")
|
||||
if !skipOpenCloudRunFlag {
|
||||
go opencloud.Start(nil)
|
||||
}
|
||||
go wrapper.Start(cmd.Flag("port").Value.String())
|
||||
portFlag, _ := cmd.Flags().GetString("port")
|
||||
go wrapper.Start(portFlag)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user