flow

package
v0.0.0-...-3196316 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2020 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const NoCommitErrMsg = "" /* 219-byte string literal not displayed */

TODO(waigani) this should live under the VCS domain, not Flows

Variables

View Source
var CLIAPPHELPTMP = `

 --- {{.Tagline}} - https://codelingo.io/flows/codelingo/{{.Name}} ---


  FLOW HELP
  =========

   {{.Usage}}


   USAGE
   -----
 
    $ lingo run {{.Name}} [options] 
 

   OPTIONS
   -------
    {{range .VisibleFlags}}
    {{.}}
    {{end}}
`[1:]
View Source
var DECAPPHELPTMP = `

  DECORATOR HELP
  ==============

   USAGE
   -----
  
    @{{.Name}} {{.DecoratorUsage}}
    
   {{if len .VisibleFlags}}
   OPTIONS
   -------
    {{range .VisibleFlags}}
    {{.}}
    {{end}}
   {{end}}
   EXAMPLE
   -------
 
    # codelingo.yaml file
    tenets:
      - name: example-tenet
        flows:
          codelingo/{{.Name}}:
        query:
          import codelingo/ast/go

          @{{.Name}} {{.DecoratorExample}}
          go.func_decl(depth := any)


`[1:]
View Source
var INFOTMP = `
  FLOW APP INFO
  =============
   
   Version
   -------

    {{.Version}} - last compiled {{.Compiled}}
   {{if len .Authors}}
   AUTHOR
   ------
   {{range .Authors}}{{ . }}{{end}}
   {{end}}

`[1:]

Functions

func DecoratorArgs

func DecoratorArgs(decStr string) []string

DecoratorArgs parses a decorator string and returns the CLI arguments

func ErrFanIn

func ErrFanIn(err1c, err2c chan error) chan error

Repeated code in platform TODO: variadic fan in - read only

func GitCMD

func GitCMD(args ...string) (out string, err error)

func HandleErr

func HandleErr(err error)

TODO(waigani) move this to codelingo/sdk/flow

func MarshalChan

func MarshalChan(replyc chan *grpcflow.Reply, newItem func() proto.Message, setDefaults func(proto.Message) proto.Message) (chan proto.Message, chan error)

func NewCtx

func NewCtx(app *cli.App, input ...string) (*cli.Context, error)

func NewFlow

func NewFlow(cliApp *CLIApp, decoratorApp *DecoratorApp) *flowRunner

NewFlow creates a flowRunner from a CLIApp. For flows that query the flow server it overrides the action with command function, which runs the cliApp's Request function and listens on the channels it returns. TODO: move away from flowRunner model by explicitly defining the command function as the action in the flow.

func NoCommitErr

func NoCommitErr(err error) bool

TODO(waigani) use typed error

func OpenFileConfirmAction

func OpenFileConfirmAction(filename string, line int64) (bool, bool, error)

func ParseArgs

func ParseArgs(args []string) string

ParseArgs formats args for urfave/cli urfave/cli doesn't distinguish between literal and variable args e.g. "this arg" vs thisArg. "this arg" gets parsed as two args. The function below takes all args as the input. The cli lib pads {} chars which we undo below. A better cli lib should be used.

func ReadDotLingo

func ReadDotLingo(ctx *cli.Context) (string, error)

Read a codelingo.yaml file from a filepath argument

func Request

func Request(ctx context.Context, reqC <-chan *grpcflow.Request) (chan *grpcflow.Reply, chan error, error)

func RunFlow

func RunFlow(flowName string, req proto.Message, newItem func() proto.Message, setDefaults func(proto.Message) proto.Message) (chan proto.Message, <-chan *UserVar, chan error, func(), error)

RunFlow calls a given flow on the flow server and marshalls replies as a given type

Types

type CLIApp

type CLIApp struct {
	cli.App
	Request func(*cli.Context) (chan proto.Message, <-chan *UserVar, chan error, func(), error)

	// Help data
	Tagline string
}

type ConfirmerItem

type ConfirmerItem struct {
	Preview func() string

	// Options is a map of option keys to confirm functions. Each confirm function returns: <keep>bool, <retry>bool, <err>error
	Options map[string]func() (bool, bool, error)

	// OptionKeyMap maps an option key to aliases e.g. "[k]eep" => "k", "keep", "K"
	OptionKeyMap map[string][]string

	// FlagOptions is a map of flags to options show if that flag is present.
	// "_all" is a builtin flag for those options that don't require a flag.
	FlagOptions map[string][]string
	// contains filtered or unexported fields
}

func (*ConfirmerItem) Confirm

func (item *ConfirmerItem) Confirm(ctx *cli.Context) (bool, error)

confirm returns true if the msg should be kept or false if it should be dropped.

type DecoratedResult

type DecoratedResult struct {

	// Ctx are the flags and args parsed from the decorated fact
	Ctx *cli.Context

	// Payload is the struct returned form the flow server for the matched
	// fact.
	Payload proto.Message
}

type DecoratorApp

type DecoratorApp struct {
	cli.App
	ConfirmDecorated func(*cli.Context, proto.Message) (bool, error)
	SetUserVar       func(*UserVar)

	// Help info
	DecoratorUsage   string
	DecoratorExample string
}

type UserVar

type UserVar struct {
	VarC         chan<- string
	Name         string
	DefaultValue string
}

A UserVar allows users and other external agents to set variable values while a query is being executed. TODO: UserVar code is copied from the Platform

func (*UserVar) Set

func (s *UserVar) Set()

Set sets a variable from user input

func (*UserVar) SetAsDefault

func (s *UserVar) SetAsDefault()

SetAsDefault sets the variable to its default value

Jump to

Keyboard shortcuts

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