Skip to content

Commit

Permalink
style: unified the name of managing piece storage
Browse files Browse the repository at this point in the history
unified the name of sub command
check flag by cctx.IsSet
add ArgsUsage comment
  • Loading branch information
LinZexiao committed Jul 4, 2022
1 parent 3d22688 commit 2f48692
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions cli/piece-storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ var PieceStorageCmd = &cli.Command{
Usage: "Manage piece storage ",
Description: "The piece storage will decide where to store pieces and how to store them",
Subcommands: []*cli.Command{
addFsPieceStorageCmd,
addS3PieceStorageCmd,
PieceStorageListCmd,
PieceStorageRemoveCmd,
pieceStorageAddFsCmd,
pieceStorageAddS3Cmd,
pieceStorageListCmd,
pieceStorageRemoveCmd,
},
}

var addFsPieceStorageCmd = &cli.Command{
var pieceStorageAddFsCmd = &cli.Command{
Name: "add-fs",
Usage: "add a local filesystem piece storage",
Flags: []cli.Flag{
Expand All @@ -30,10 +30,9 @@ var addFsPieceStorageCmd = &cli.Command{
Usage: "path to the filesystem piece storage",
},
&cli.BoolFlag{
Name: "read-only",
Aliases: []string{"r"},
Usage: "read-only filesystem piece storage",
DefaultText: "false",
Name: "read-only",
Aliases: []string{"r"},
Usage: "read-only filesystem piece storage",
},
// name
&cli.StringFlag{
Expand All @@ -49,18 +48,18 @@ var addFsPieceStorageCmd = &cli.Command{
}
defer closer()

ctx := ReqContext(cctx)
path := cctx.String("path")
readOnly := cctx.Bool("read-only")
name := cctx.String("name")

if path == "" {
if !cctx.IsSet("path") {
return fmt.Errorf("path is required")
}
if name == "" {
if !cctx.IsSet("name") {
return fmt.Errorf("name is required")
}

ctx := ReqContext(cctx)
path := cctx.String("path")
readOnly := cctx.Bool("read-only")
name := cctx.String("name")

err = nodeApi.AddFsPieceStorage(ctx, readOnly, path, name)
if err != nil {
return err
Expand All @@ -71,7 +70,7 @@ var addFsPieceStorageCmd = &cli.Command{
},
}

var addS3PieceStorageCmd = &cli.Command{
var pieceStorageAddS3Cmd = &cli.Command{
Name: "add-s3",
Usage: "add a object storage for piece storage",
Flags: []cli.Flag{
Expand Down Expand Up @@ -122,26 +121,26 @@ var addS3PieceStorageCmd = &cli.Command{

ctx := ReqContext(cctx)

if !cctx.IsSet("endpoint") {
return fmt.Errorf("endpoint is required")
}
if !cctx.IsSet("access-key") {
return fmt.Errorf("access-key is required")
}
if !cctx.IsSet("secret-key") {
return fmt.Errorf("secret-key is required")
}
if !cctx.IsSet("name") {
return fmt.Errorf("name is required")
}

readOnly := cctx.Bool("readonly")
endpoint := cctx.String("endpoint")
accessKey := cctx.String("access-key")
secretKey := cctx.String("secret-key")
token := cctx.String("token")
name := cctx.String("name")

if endpoint == "" {
return fmt.Errorf("endpoint are required")
}
if accessKey == "" {
return fmt.Errorf("access key are required")
}
if secretKey == "" {
return fmt.Errorf("secret key are required")
}
if name == "" {
return fmt.Errorf("name are required")
}

err = nodeApi.AddS3PieceStorage(ctx, readOnly, endpoint, name, accessKey, secretKey, token)
if err != nil {
return err
Expand All @@ -152,7 +151,7 @@ var addS3PieceStorageCmd = &cli.Command{
},
}

var PieceStorageListCmd = &cli.Command{
var pieceStorageListCmd = &cli.Command{
Name: "list",
Usage: "list piece storages",
Action: func(cctx *cli.Context) error {
Expand Down Expand Up @@ -197,9 +196,10 @@ var PieceStorageListCmd = &cli.Command{
},
}

var PieceStorageRemoveCmd = &cli.Command{
Name: "remove",
Usage: "remove a piece storage",
var pieceStorageRemoveCmd = &cli.Command{
Name: "remove",
ArgsUsage: "<name>",
Usage: "remove a piece storage",
Action: func(cctx *cli.Context) error {
// get idx
name := cctx.Args().Get(0)
Expand Down

0 comments on commit 2f48692

Please sign in to comment.