cli

package module
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2024 License: BSD-3-Clause Imports: 17 Imported by: 0

README

CLI Trigger

This trigger provides your flogo application the ability to run as a CLI app, that is, accept input via the CLI & run once till completion and return the results to stdout.

Installation

flogo install github.com/AiRISTAFlowInc/fs-trigger/cli

Configuration

Settings:
Name Type Description
singleCmd bool Indicates that this CLI runs only one command/handler
usage string The usage details of the CLI
long string The description of the CLI
Handler Settings:
Name Type Description
flags array List of flags
usage string The usage details of the command
short string A short description of the command
long string The description of the command
Output:
Name Type Description
args array An array of the command line arguments
flags map A map of the command line flags
Reply:
Name Type Description
data any The data that the command outputs
Flags

There is simple support for defining flags for a command. You can specify either a boolean or string flag.
Flags are defined using the following format: flagName||defaultValue||description

Note: if a flag has a default value of true or false it is considered a boolean flag

Sample Configuration

"triggers": [
  {
    "id": "cli",
    "ref": "#cli",
    "name": "simple",
    "description": "Simple CLI Utility",
    "settings": {
      "singleCmd": true
    },
    "handlers": [
      {
        "name": "commandName",
        "settings": {
          "usage": "[flags] [args]",
          "short": "short command description",
          "long": "the long command descriptoin",
          "flags": [
           "flag1||||string flag",
           "flag2||false||boolan flag"
          ]
        },
        "action": {
          "ref": "#flow",
          "settings": {
            "flowURI": "res://flow:commandName"
          },
          "input": {
            "flags": "=$.flags",
            "args": "=$.args"
          }
        }
      }
    ]
  }
]  

Note: Each CLI command maps to a handler, so in order to set your command a name, you must set the name of the handler.

Examples

Triggers are configured via the triggers section of your application. The following are some example configuration of the CLI Trigger.

Single command

An example can be found here.

Multi command

An example can be found here.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFlags

func GetFlags(fs *flag.FlagSet) []*flag.Flag

func Invoke

func Invoke() (string, error)

func RenderTemplate

func RenderTemplate(w io.Writer, text string, data interface{})

Types

type Factory

type Factory struct {
}

func (*Factory) Metadata

func (*Factory) Metadata() *trigger.Metadata

Metadata implements trigger.Factory.Metadata

func (*Factory) New

func (*Factory) New(config *trigger.Config) (trigger.Trigger, error)

New implements trigger.Factory.New

type HandlerSettings

type HandlerSettings struct {
	FlagDesc []interface{} `md:"flags"`
	Usage    string        `md:"usage"` // The usage details of the command
	Short    string        `md:"short"` // A short description of the command
	Long     string        `md:"long"`  // The description of the command
}

type Output

type Output struct {
	Args  []interface{}          `md:"args"`  // An array of the command line arguments
	Flags map[string]interface{} `md:"flags"` // A map of the command line flags
}

func (*Output) FromMap

func (o *Output) FromMap(values map[string]interface{}) error

func (*Output) ToMap

func (o *Output) ToMap() map[string]interface{}

type Reply

type Reply struct {
	Data interface{} `md:"data"` // The data that the command outputs
}

func (*Reply) FromMap

func (r *Reply) FromMap(values map[string]interface{}) error

func (*Reply) ToMap

func (r *Reply) ToMap() map[string]interface{}

type Settings

type Settings struct {
	SingleCmd bool   `md:"singleCmd"` // Indicates that this CLI runs only one command/handler
	Usage     string `md:"usage"`     // The usage details of the CLI
	Long      string `md:"long"`      // The description of the CLI
}

type Trigger

type Trigger struct {
	// contains filtered or unexported fields
}

Trigger CLI trigger struct

func (*Trigger) Initialize

func (t *Trigger) Initialize(ctx trigger.InitContext) error

func (*Trigger) Invoke

func (t *Trigger) Invoke(handler trigger.Handler, flags map[string]interface{}, args []string) (string, error)

func (*Trigger) Metadata

func (t *Trigger) Metadata() *trigger.Metadata

Metadata implements trigger.Trigger.Metadata

func (*Trigger) Start

func (t *Trigger) Start() error

func (*Trigger) Stop

func (t *Trigger) Stop() error

Stop implements util.Managed.Stop

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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