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

show subcommand creation for review #115

Merged
merged 2 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
64 changes: 64 additions & 0 deletions internal/cmd/list.go
Original file line number Diff line number Diff line change
@@ -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 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 list subcommand
will provide the valid options for fields such as status or justification.

Examples:

# list the status options
%s list status

# list the justification options
%s list justification


`, appname, appname, appname),
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")
}
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'", v)
}
}
return nil
},
}

parentCmd.AddCommand(listCmd)
}
1 change: 1 addition & 0 deletions internal/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func init() {
addAttest(rootCmd)
addMerge(rootCmd)
addCreate(rootCmd)
addList(rootCmd)
rootCmd.AddCommand(version.WithFont("doom"))
}

Expand Down