Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Cmd ¶
func Cmd(initializers ...workflow.ExtensionInit) (*cobra.Command, error)
Cmd is a helper utility for extension authors to define a lightweight CLI to test their extensions outside of the main Snyk CLI.
Example ¶
package main import ( "fmt" "log" "github.com/snyk/go-application-framework/pkg/devtools" "github.com/snyk/go-application-framework/pkg/workflow" "github.com/spf13/pflag" ) var helloWorkflowID = workflow.NewWorkflowIdentifier("hello") func helloWorkflow( ictx workflow.InvocationContext, _ []workflow.Data, ) ([]workflow.Data, error) { fmt.Println("Hello, workflow!") return []workflow.Data{}, nil } func initHelloWorkflow(e workflow.Engine) error { flagset := pflag.NewFlagSet("snyk-cli-extension-hello", pflag.ExitOnError) c := workflow.ConfigurationOptionsFromFlagset(flagset) if _, err := e.Register(helloWorkflowID, c, helloWorkflow); err != nil { return fmt.Errorf("error while registering 'hello' workflow: %w", err) } return nil } func main() { // Initialize the command with one or more workflows root, err := devtools.Cmd(initHelloWorkflow) if err != nil { log.Fatal(err) } // This is just for testing. In normal usage, args are set automatically // from os.Args. root.SetArgs([]string{"hello"}) // Execute the command. if err := root.Execute(); err != nil { log.Fatal(err) } }
Output: Hello, workflow!
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.