From 6d05f85cdf47a0ee11b1bf5afbf6c8b18375d591 Mon Sep 17 00:00:00 2001 From: Brandt Keller Date: Wed, 30 Aug 2023 11:28:48 -0700 Subject: [PATCH 1/2] show subcommand creation for review Signed-off-by: Brandt Keller --- internal/cmd/main.go | 1 + internal/cmd/show.go | 64 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 internal/cmd/show.go diff --git a/internal/cmd/main.go b/internal/cmd/main.go index 2adfa02..055c08f 100644 --- a/internal/cmd/main.go +++ b/internal/cmd/main.go @@ -53,6 +53,7 @@ func init() { addAttest(rootCmd) addMerge(rootCmd) addCreate(rootCmd) + addShow(rootCmd) rootCmd.AddCommand(version.WithFont("doom")) } diff --git a/internal/cmd/show.go b/internal/cmd/show.go new file mode 100644 index 0000000..6b248c6 --- /dev/null +++ b/internal/cmd/show.go @@ -0,0 +1,64 @@ +/* +Copyright 2022 The OpenVEX Authors +SPDX-License-Identifier: Apache-2.0 +*/ + +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" + + "github.com/openvex/go-vex/pkg/vex" +) + +func addShow(parentCmd *cobra.Command) { + showCmd := &cobra.Command{ + Short: fmt.Sprintf("%s show: shows valid status or justification options", appname), + Long: fmt.Sprintf(`%s show: show the valid input options according to the OpenVEX spec + +When composing VEX documents it is important to ensure the VEX specification +is being adhered to for fields that require specific values. The show subcommand +will provide the valid options for fields such as status or justification. + +Examples: + +# Show the status options +%s show status + +# show the justification options +%s show justification + + +`, appname, appname, appname), + Use: "show", + SilenceUsage: false, + SilenceErrors: false, + PersistentPreRunE: initLogging, + RunE: func(cmd *cobra.Command, args []string) error { + if len(args) == 0 { + return fmt.Errorf("Selection of 'status' or 'justification' is required") + } + for _, v := range args { + switch v { + case "status": + fmt.Printf("Valid Statuses:\n") + for _, status := range vex.Statuses() { + fmt.Printf("\t%s\n", status) + } + case "justification": + fmt.Printf("Valid Justifications:\n") + for _, justification := range vex.Justifications() { + fmt.Printf("\t%s\n", justification) + } + default: + return fmt.Errorf("%s is not a valid selection - available options are 'status' and 'justification' \n", v) + } + } + return nil + }, + } + + parentCmd.AddCommand(showCmd) +} From 59db73f04854bd6f2a2a2d9d0e3dc31965ddb71b Mon Sep 17 00:00:00 2001 From: Brandt Keller Date: Wed, 30 Aug 2023 13:13:17 -0700 Subject: [PATCH 2/2] Update show to list Signed-off-by: Brandt Keller --- internal/cmd/{show.go => list.go} | 26 +++++++++++++------------- internal/cmd/main.go | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) rename internal/cmd/{show.go => list.go} (70%) diff --git a/internal/cmd/show.go b/internal/cmd/list.go similarity index 70% rename from internal/cmd/show.go rename to internal/cmd/list.go index 6b248c6..ef67bec 100644 --- a/internal/cmd/show.go +++ b/internal/cmd/list.go @@ -13,32 +13,32 @@ import ( "github.com/openvex/go-vex/pkg/vex" ) -func addShow(parentCmd *cobra.Command) { - showCmd := &cobra.Command{ - Short: fmt.Sprintf("%s show: shows valid status or justification options", appname), - Long: fmt.Sprintf(`%s show: show the valid input options according to the OpenVEX spec +func addList(parentCmd *cobra.Command) { + listCmd := &cobra.Command{ + Short: fmt.Sprintf("%s list: lists valid status or justification options", appname), + Long: fmt.Sprintf(`%s list: list the valid input options according to the OpenVEX spec When composing VEX documents it is important to ensure the VEX specification -is being adhered to for fields that require specific values. The show subcommand +is being adhered to for fields that require specific values. The list subcommand will provide the valid options for fields such as status or justification. Examples: -# Show the status options -%s show status +# list the status options +%s list status -# show the justification options -%s show justification +# list the justification options +%s list justification `, appname, appname, appname), - Use: "show", + Use: "list", SilenceUsage: false, SilenceErrors: false, PersistentPreRunE: initLogging, RunE: func(cmd *cobra.Command, args []string) error { if len(args) == 0 { - return fmt.Errorf("Selection of 'status' or 'justification' is required") + return fmt.Errorf("selection of 'status' or 'justification' is required") } for _, v := range args { switch v { @@ -53,12 +53,12 @@ Examples: fmt.Printf("\t%s\n", justification) } default: - return fmt.Errorf("%s is not a valid selection - available options are 'status' and 'justification' \n", v) + return fmt.Errorf("%s is not a valid selection - available options are 'status' and 'justification'", v) } } return nil }, } - parentCmd.AddCommand(showCmd) + parentCmd.AddCommand(listCmd) } diff --git a/internal/cmd/main.go b/internal/cmd/main.go index 055c08f..a125e9c 100644 --- a/internal/cmd/main.go +++ b/internal/cmd/main.go @@ -53,7 +53,7 @@ func init() { addAttest(rootCmd) addMerge(rootCmd) addCreate(rootCmd) - addShow(rootCmd) + addList(rootCmd) rootCmd.AddCommand(version.WithFont("doom")) }