devtools

package
v0.0.0-...-a5f9fc7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2023 License: Apache-2.0 Imports: 9 Imported by: 1

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 Vulnmap CLI.

Example
package main

import (
	"fmt"
	"log"

	"github.com/khulnasoft-lab/go-application-framework/pkg/devtools"
	"github.com/khulnasoft-lab/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("vulnmap-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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL