Skip to content

Commit 1e03257

Browse files
committed
feat: remove blueprint commands position args
1 parent 093b120 commit 1e03257

10 files changed

Lines changed: 59 additions & 61 deletions

File tree

internal/app/enaptercli/cmd_blueprints_inspect.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
type cmdBlueprintsInpsect struct {
1111
cmdBlueprints
12+
blueprintID string
1213
}
1314

1415
func buildCmdBlueprintsInspect() *cli.Command {
@@ -19,33 +20,32 @@ func buildCmdBlueprintsInspect() *cli.Command {
1920
CustomHelpTemplate: cmd.HelpTemplate(),
2021
Flags: cmd.Flags(),
2122
Before: cmd.Before,
22-
Args: true,
23-
ArgsUsage: "<blueprint id or name>",
2423
Action: func(cliCtx *cli.Context) error {
25-
return cmd.inspect(cliCtx.Context, cliCtx.Args().Get(0))
24+
return cmd.inspect(cliCtx.Context)
2625
},
2726
}
2827
}
2928

30-
func (c *cmdBlueprintsInpsect) Before(cliCtx *cli.Context) error {
31-
if err := c.cmdBlueprints.Before(cliCtx); err != nil {
32-
return err
33-
}
34-
if cliCtx.Args().Get(0) == "" {
35-
return errBlueprintIDMissed
36-
}
37-
return nil
29+
func (c *cmdBlueprintsInpsect) Flags() []cli.Flag {
30+
flags := c.cmdBlueprints.Flags()
31+
return append(flags, &cli.StringFlag{
32+
Name: "blueprint-id",
33+
Aliases: []string{"b"},
34+
Usage: "blueprint name or ID to inspect",
35+
Destination: &c.blueprintID,
36+
Required: true,
37+
})
3838
}
3939

40-
func (c *cmdBlueprintsInpsect) inspect(ctx context.Context, blueprintID string) error {
41-
if isBlueprintID(blueprintID) {
40+
func (c *cmdBlueprintsInpsect) inspect(ctx context.Context) error {
41+
if isBlueprintID(c.blueprintID) {
4242
return c.doHTTPRequest(ctx, doHTTPRequestParams{
4343
Method: http.MethodGet,
44-
Path: "/blueprints/" + blueprintID,
44+
Path: "/blueprints/" + c.blueprintID,
4545
})
4646
}
4747

48-
blueprintName, blueprintTag := parseBlueprintName(blueprintID)
48+
blueprintName, blueprintTag := parseBlueprintName(c.blueprintID)
4949
return c.doHTTPRequest(ctx, doHTTPRequestParams{
5050
Method: http.MethodGet,
5151
Path: "/blueprints/enapter/" + blueprintName + "/" + blueprintTag,

internal/app/enaptercli/cmd_blueprints_profiles_upload.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
type cmdBlueprintsProfilesUpload struct {
1414
cmdBlueprintsProfiles
15+
profilesPath string
1516
}
1617

1718
func buildCmdBlueprintsProfilesUpload() *cli.Command {
@@ -22,27 +23,25 @@ func buildCmdBlueprintsProfilesUpload() *cli.Command {
2223
CustomHelpTemplate: cmd.HelpTemplate(),
2324
Flags: cmd.Flags(),
2425
Before: cmd.Before,
25-
Args: true,
26-
ArgsUsage: "profiles zip file path",
2726
Action: func(cliCtx *cli.Context) error {
28-
return cmd.upload(cliCtx.Context, cliCtx.Args().Get(0))
27+
return cmd.upload(cliCtx.Context)
2928
},
3029
}
3130
}
3231

33-
func (c *cmdBlueprintsProfilesUpload) Before(cliCtx *cli.Context) error {
34-
if err := c.cmdBlueprintsProfiles.Before(cliCtx); err != nil {
35-
return err
36-
}
37-
38-
if cliCtx.Args().Get(0) == "" {
39-
return errProfilesPathMissed
40-
}
41-
return nil
32+
func (c *cmdBlueprintsProfilesUpload) Flags() []cli.Flag {
33+
flags := c.cmdBlueprintsProfiles.Flags()
34+
return append(flags, &cli.StringFlag{
35+
Name: "profiles-path",
36+
Aliases: []string{"p"},
37+
Usage: "profiles zip file path",
38+
Destination: &c.profilesPath,
39+
Required: true,
40+
})
4241
}
4342

44-
func (c *cmdBlueprintsProfilesUpload) upload(ctx context.Context, blueprintPath string) error {
45-
data, err := os.ReadFile(blueprintPath)
43+
func (c *cmdBlueprintsProfilesUpload) upload(ctx context.Context) error {
44+
data, err := os.ReadFile(c.profilesPath)
4645
if err != nil {
4746
return fmt.Errorf("read zip file: %w", err)
4847
}

internal/app/enaptercli/cmd_blueprints_upload.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,49 +12,48 @@ import (
1212

1313
type cmdBlueprintsUpload struct {
1414
cmdBlueprints
15+
blueprintPath string
1516
}
1617

1718
func buildCmdBlueprintsUpload() *cli.Command {
1819
cmd := &cmdBlueprintsUpload{}
1920
return &cli.Command{
2021
Name: "upload",
21-
Usage: "Upload blueprint directory into Platform",
22+
Usage: "Upload blueprint into Platform",
2223
CustomHelpTemplate: cmd.HelpTemplate(),
2324
Flags: cmd.Flags(),
2425
Before: cmd.Before,
25-
Args: true,
26-
ArgsUsage: "<blueprint path (zip file or directory)>",
2726
Action: func(cliCtx *cli.Context) error {
28-
return cmd.upload(cliCtx.Context, cliCtx.Args().Get(0))
27+
return cmd.upload(cliCtx.Context)
2928
},
3029
}
3130
}
3231

33-
func (c *cmdBlueprintsUpload) Before(cliCtx *cli.Context) error {
34-
if err := c.cmdBlueprints.Before(cliCtx); err != nil {
35-
return err
36-
}
37-
38-
if cliCtx.Args().Get(0) == "" {
39-
return errBlueprintPathMissed
40-
}
41-
return nil
32+
func (c *cmdBlueprintsUpload) Flags() []cli.Flag {
33+
flags := c.cmdBlueprints.Flags()
34+
return append(flags, &cli.StringFlag{
35+
Name: "path",
36+
Aliases: []string{"p"},
37+
Usage: "blueprint path (zip file or directory)",
38+
Destination: &c.blueprintPath,
39+
Required: true,
40+
})
4241
}
4342

44-
func (c *cmdBlueprintsUpload) upload(ctx context.Context, blueprintPath string) error {
45-
fi, err := os.Stat(blueprintPath)
43+
func (c *cmdBlueprintsUpload) upload(ctx context.Context) error {
44+
fi, err := os.Stat(c.blueprintPath)
4645
if err != nil {
4746
return fmt.Errorf("check blueprint path: %w", err)
4847
}
4948

5049
var data []byte
5150
if fi.IsDir() {
52-
data, err = zipDir(blueprintPath)
51+
data, err = zipDir(c.blueprintPath)
5352
if err != nil {
5453
return fmt.Errorf("zip blueprint directory: %w", err)
5554
}
5655
} else {
57-
data, err = os.ReadFile(blueprintPath)
56+
data, err = os.ReadFile(c.blueprintPath)
5857
if err != nil {
5958
return fmt.Errorf("read blueprint zip file: %w", err)
6059
}

internal/app/enaptercli/errors.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,5 @@ import "errors"
55
var (
66
errAPITokenMissed = errors.New("API token missing. Set it up using environment " +
77
"variable ENAPTER3_API_TOKEN")
8-
errBlueprintIDMissed = errors.New("blueprint ID is missed")
9-
errBlueprintPathMissed = errors.New("blueprint path is missed")
108
errUnsupportedFlagValue = errors.New("unsupported flag value")
11-
errProfilesPathMissed = errors.New("profiles path is missed")
129
)

internal/app/enaptercli/testdata/helps/enapter blueprint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ USAGE:
66

77
COMMANDS:
88
profiles Manage blueprints profiles
9-
upload Upload blueprint directory into Platform
9+
upload Upload blueprint into Platform
1010
download Download blueprint zip from Platform
1111
inspect Get blueprint metainfo
1212
help, h Shows a list of commands or help for one command

internal/app/enaptercli/testdata/helps/enapter blueprint inspect

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ NAME:
22
enaptercli.test blueprint inspect - Get blueprint metainfo
33

44
USAGE:
5-
enaptercli.test blueprint inspect [command options] <blueprint id or name>
5+
enaptercli.test blueprint inspect [command options]
66

77
OPTIONS:
8-
--verbose log extra details about operation (default: false)
9-
--help, -h show help
8+
--verbose log extra details about operation (default: false)
9+
--blueprint-id value, -b value blueprint name or ID to inspect
10+
--help, -h show help
1011

1112
ENVIRONMENT VARIABLES:
1213
ENAPTER3_API_TOKEN Enapter API access token

internal/app/enaptercli/testdata/helps/enapter blueprint profiles upload

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ USAGE:
55
enaptercli.test blueprint profiles upload [command options] profiles zip file path
66

77
OPTIONS:
8-
--verbose log extra details about operation (default: false)
9-
--help, -h show help
8+
--verbose log extra details about operation (default: false)
9+
--profiles-path value, -p value profiles zip file path
10+
--help, -h show help
1011

1112
ENVIRONMENT VARIABLES:
1213
ENAPTER3_API_TOKEN Enapter API access token

internal/app/enaptercli/testdata/helps/enapter blueprint upload

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
NAME:
2-
enaptercli.test blueprint upload - Upload blueprint directory into Platform
2+
enaptercli.test blueprint upload - Upload blueprint into Platform
33

44
USAGE:
5-
enaptercli.test blueprint upload [command options] <blueprint path (zip file or directory)>
5+
enaptercli.test blueprint upload [command options]
66

77
OPTIONS:
8-
--verbose log extra details about operation (default: false)
9-
--help, -h show help
8+
--verbose log extra details about operation (default: false)
9+
--path value, -p value blueprint path (zip file or directory)
10+
--help, -h show help
1011

1112
ENVIRONMENT VARIABLES:
1213
ENAPTER3_API_TOKEN Enapter API access token
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
enapter3 blueprint inspect {{.BaseFlags}} cdd82438-dda8-4f69-aad1-0be9adeab964
1+
enapter3 blueprint inspect {{.BaseFlags}} --blueprint-id cdd82438-dda8-4f69-aad1-0be9adeab964
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
enapter3 blueprint inspect {{.BaseFlags}} test_blueprint_name
1+
enapter3 blueprint inspect {{.BaseFlags}} --blueprint-id test_blueprint_name

0 commit comments

Comments
 (0)