devtools

package
v0.0.0-...-470703e Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

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.

Jump to

Keyboard shortcuts

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