Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cli usage info #55

Merged
merged 4 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions pkg/cli/cli_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type CLIHandleCommand struct {
flagDebug bool

// Run Cleanup instead of Do if true.
Cleanup bool
flagCleanup bool

// testCLI is used for testing only.
testCLI string
Expand All @@ -50,23 +50,21 @@ func (c *CLIHandleCommand) Help() string {
return `
Usage: {{ COMMAND }} [options]

Run "do" commands in the CLI request YAML file at the given path:
Handle "do" commands in the CLI request YAML file at the given path:

aod cli do -path "/path/to/file.yaml"
aod cli {{ COMMAND }} -path "/path/to/file.yaml"
sqin2019 marked this conversation as resolved.
Show resolved Hide resolved

Handle "do" commands in the CLI request YAML file at the given path in debug mode:

Run "do" commands in the CLI request YAML file at the given path in debug mode:
aod cli {{ COMMAND }} -path "/path/to/file.yaml" -debug

aod cli do -path "/path/to/file.yaml" -debug
Handle "cleanup" commands in the CLI request YAML file at the given path:

Run "cleanup" commands in the CLI request YAML file at the given path:
aod cli {{ COMMAND }} -path "/path/to/file.yaml" -cleanup

aod cli cleanup -path "/path/to/file.yaml"
Handle "cleanup" commands in the CLI request YAML file at the given path in debug mode:


Run "cleanup" commands in the CLI request YAML file at the given path in debug mode:

aod cli cleanup -path "/path/to/file.yaml" -debug
aod cli {{ COMMAND }} -path "/path/to/file.yaml" -cleanup -debug
`
}

Expand All @@ -84,6 +82,13 @@ func (c *CLIHandleCommand) Flags() *cli.FlagSet {
Usage: `The path of CLI request file, in YAML format.`,
})

f.BoolVar(&cli.BoolVar{
Name: "cleanup",
Target: &c.flagCleanup,
Default: false,
Usage: `Handle CLI request cleanup.`,
})

f.BoolVar(&cli.BoolVar{
Name: "debug",
Target: &c.flagDebug,
Expand Down Expand Up @@ -133,7 +138,7 @@ func (c *CLIHandleCommand) handle(ctx context.Context) error {
req.CLI = c.testCLI
}
var err error
if c.Cleanup {
if c.flagCleanup {
err = h.Cleanup(ctx, &req)
} else {
err = h.Do(ctx, &req)
Expand Down
11 changes: 3 additions & 8 deletions pkg/cli/cli_handle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ cleanup:
name string
args []string
testCLI string
cleanup bool
expOut string
expErr string
expStdErr string
Expand All @@ -83,16 +82,14 @@ Successfully completed commands`,
},
{
name: "success_cleanup",
args: []string{"-path", filepath.Join(dir, "valid.yaml")},
args: []string{"-path", filepath.Join(dir, "valid.yaml"), "-cleanup"},
testCLI: "echo",
cleanup: true,
expOut: `Successfully completed commands`,
},
{
name: "success_cleanup_with_debug",
args: []string{"-path", filepath.Join(dir, "valid.yaml"), "-debug"},
args: []string{"-path", filepath.Join(dir, "valid.yaml"), "-debug", "-cleanup"},
testCLI: "echo",
cleanup: true,
expOut: `
cleanup1
cleanup2
Expand Down Expand Up @@ -122,9 +119,8 @@ Successfully completed commands`,
},
{
name: "handler_cleanup_failure",
args: []string{"-path", filepath.Join(dir, "valid.yaml")},
args: []string{"-path", filepath.Join(dir, "valid.yaml"), "-cleanup"},
testCLI: "ls",
cleanup: true,
expErr: `failed to run command "cleanup1"`,
expStdErr: "ls: cannot access 'cleanup1': No such file or directory",
},
Expand All @@ -144,7 +140,6 @@ Successfully completed commands`,
ctx := logging.WithLogger(context.Background(), logging.TestLogger(t))

cmd := CLIHandleCommand{
Cleanup: tc.cleanup,
testCLI: tc.testCLI,
}
_, stdout, stderr := cmd.Pipe()
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/cli_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Usage: {{ COMMAND }} [options]

Validate the IAM request YAML file at the given path:

aod cli validate -path "/path/to/file.yaml"
aod cli {{ COMMAND }} -path "/path/to/file.yaml"
`
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/iam_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Usage: {{ COMMAND }} [options]

Handle the IAM request YAML file in the given path:

aod iam handle -path "/path/to/file.yaml" -duration "2h" -start-time "2009-11-10T23:00:00Z"
aod iam {{ COMMAND }} -path "/path/to/file.yaml" -duration "2h" -start-time "2009-11-10T23:00:00Z"
`
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/iam_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Usage: {{ COMMAND }} [options]

Validate the IAM request YAML file at the given path:

aod iam validate -path "/path/to/file.yaml"
aod iam {{ COMMAND }} -path "/path/to/file.yaml"
`
}

Expand Down
5 changes: 1 addition & 4 deletions pkg/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,9 @@ var rootCmd = func() cli.Command {
Name: "cli",
Description: "Perform operations related to the CLI request",
Commands: map[string]cli.CommandFactory{
"do": func() cli.Command {
"handle": func() cli.Command {
return &CLIHandleCommand{}
},
"cleanup": func() cli.Command {
return &CLIHandleCommand{Cleanup: true}
},
"validate": func() cli.Command {
return &CLIValidateCommand{}
},
Expand Down