Skip to content

Commit

Permalink
CR feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Pritesh Bandi <[email protected]>
  • Loading branch information
priteshbandi committed Aug 21, 2023
1 parent bb55b5a commit 307a563
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func New(executableName string, pl plugin.Plugin) *CLI {

// Execute is main controller that reads/validates commands, parses input, executes relevant plugin functions
// and returns corresponding output.
func (c CLI) Execute(ctx context.Context, args []string) {
func (c *CLI) Execute(ctx context.Context, args []string) {
c.validateArgs(ctx, args)

rescueStdOut := deferStdout()
Expand Down Expand Up @@ -95,23 +95,23 @@ func (c CLI) Execute(ctx context.Context, args []string) {
}

// printVersion prints version of executable
func (c CLI) printVersion(ctx context.Context) {
func (c *CLI) printVersion(ctx context.Context) {
md := getMetadata(ctx, c.pl)

fmt.Printf("%s - %s\nVersion: %s", md.Name, md.Description, md.Version)
os.Exit(0)
}

// validateArgs validate commands/arguments passed to executable.
func (c CLI) validateArgs(ctx context.Context, args []string) {
func (c *CLI) validateArgs(ctx context.Context, args []string) {
md := getMetadata(ctx, c.pl)
if !(len(args) == 2 && slices.Contains(getValidArgs(md), args[1])) {
deliverError(fmt.Sprintf("Invalid command, valid choices are: %s %s", c.name, getValidArgsString(md)))
}
}

// deferStdout is used to make sure that nothing get emitted to stdout and stderr until intentionally rescued.
// This is required to make sure that the plugin or its dependency doesn't interferes with notation <-> plugin communication
// This is required to make sure that the plugin or its dependency doesn't interfere with notation <-> plugin communication
func deferStdout() func() {
null, _ := os.Open(os.DevNull)
sout := os.Stdout
Expand Down

0 comments on commit 307a563

Please sign in to comment.