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 W3Security CLI.
Example ¶
package main
import (
"fmt"
"log"
"github.com/spf13/pflag"
"github.com/w3security/go-application-framework/pkg/devtools"
"github.com/w3security/go-application-framework/pkg/workflow"
)
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("w3security-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.