From 02bc34de6550e2c4c6dc582a89d7ee1e0b7d4c9d Mon Sep 17 00:00:00 2001 From: Pritesh Bandi Date: Sun, 20 Aug 2023 22:15:35 -0700 Subject: [PATCH] CR feedback Signed-off-by: Pritesh Bandi --- cli/cli.go | 30 ++++++++++++------------------ example/go.mod | 4 ++-- example/main.go | 2 +- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/cli/cli.go b/cli/cli.go index 99038ab..1e09c54 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -19,19 +19,21 @@ import ( "github.com/notaryproject/notation-plugin-framework-go/plugin" ) -type Cli struct { - syntax string - pl plugin.Plugin +type CLI struct { + name string + pl plugin.Plugin } -// New creates a new Cli using given plugin -func New(pl plugin.Plugin) *Cli { - return &Cli{pl: pl} +// New creates a new CLI using given plugin +func New(executableName string, pl plugin.Plugin) *CLI { + return &CLI{ + name: executableName, + pl: pl} } // 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() @@ -92,16 +94,8 @@ func (c Cli) Execute(ctx context.Context, args []string) { fmt.Println(op) } -// printHelp prints help text for executable -func (c Cli) printHelp(ctx context.Context) { - md := getMetadata(ctx, c.pl) - args := getValidArgsString(md) - - fmt.Printf("%s - %s\n Usage:%s %s", md.Name, md.Description, c.syntax, args) -} - // 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) @@ -109,10 +103,10 @@ func (c Cli) printVersion(ctx context.Context) { } // 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.syntax, getValidArgsString(md))) + deliverError(fmt.Sprintf("Invalid command, valid choices are: %s %s", c.name, getValidArgsString(md))) } } diff --git a/example/go.mod b/example/go.mod index e89db1a..05eb11f 100644 --- a/example/go.mod +++ b/example/go.mod @@ -1,7 +1,7 @@ -module github.com/priteshbandi/notation-plugin-base/exampleplugin +module github.com/priteshbandi/notation-plugin-base/example go 1.20 require github.com/notaryproject/notation-plugin-framework-go v0.0.0-20230715005059-b8e1fc36cd93 -replace github.com/notaryproject/notation-plugin-framework-go => .. +replace github.com/notaryproject/notation-plugin-framework-go => ../ diff --git a/example/main.go b/example/main.go index 0b6518b..76df3cb 100644 --- a/example/main.go +++ b/example/main.go @@ -18,5 +18,5 @@ func main() { } // Create executable - cli.New(plugin).Execute(ctx, os.Args) + cli.New("example", plugin).Execute(ctx, os.Args) }