Documentation
¶
Overview ¶
Copyright 2025 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Copyright 2025 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Copyright 2025 The Joe-cli Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Index ¶
- Constants
- func AddExpr(e *Expr) cli.Action
- func AddExprs(exprs ...*Expr) cli.Action
- func SetEvaluator(e Evaluator) cli.Action
- type Binding
- type Evaluator
- type EvaluatorFunc
- type Expr
- func (e *Expr) Arg(name any) (*cli.Arg, bool)
- func (e *Expr) LocalArgs() []*cli.Arg
- func (e *Expr) LookupData(name string) (any, bool)
- func (e *Expr) Names() []string
- func (e *Expr) SetAliases(a []string)
- func (e *Expr) SetCategory(name string)
- func (e *Expr) SetData(name string, v any)
- func (e *Expr) SetDescription(value string)
- func (e *Expr) SetHelpText(name string)
- func (e *Expr) SetHidden(value bool)
- func (e *Expr) SetLocalArgs(args []*cli.Arg) error
- func (e *Expr) SetManualText(name string)
- func (e *Expr) SetName(name string)
- func (e *Expr) SetUsageText(value string)
- func (e *Expr) Synopsis() string
- type Expression
- func (e *Expression) Append(expr Binding)
- func (e *Expression) Bindings() iter.Seq[Binding]
- func (e *Expression) Evaluate(ctx context.Context, items ...any) error
- func (e *Expression) Initializer() cli.Action
- func (e *Expression) Prepend(expr Binding)
- func (e *Expression) Set(arg string) error
- func (e *Expression) String() string
- func (e *Expression) VisibleExprs() []*Expr
- func (e *Expression) Walk(fn func(Binding) error) error
- type Invariant
- type Predicate
- type Yielder
Constants ¶
const ( AlwaysTrue = Invariant(true) AlwaysFalse = Invariant(false) )
Always or never yield the input value
Variables ¶
This section is empty.
Functions ¶
func AddExpr ¶
func AddExpr(e *Expr) cli.Action
AddExpr will add an expression operator to the containing Expression
func AddExprs ¶
func AddExprs(exprs ...*Expr) cli.Action
AddExprs will add multiple expression operators to the containing Expression
func SetEvaluator ¶
func SetEvaluator(e Evaluator) cli.Action
SetEvaluator provides an action used in the Uses pipeline of the Expr which updates its evaluator
Types ¶
type Binding ¶
type Binding interface { Evaluator cli.Lookup // Expr retrieves the expression operator if it is available Expr() *Expr }
Binding provides the relationship between an evaluator and the evaluation context. Optionally, the original Expr is made available. A binding can support being reset if it exposes a method Reset(). Resetting a binding occurs when an expression is evaluated multiple times.
func NewBinding ¶
NewBinding creates an expression binding. The ev parameter is how the expression is evaluated. The remaining arguments specify the *Expr expression operator to use and optionally a Lookup. The main use case for this function is to create a custom evaluation step that is appended to the expression pipeline
type Evaluator ¶
type Evaluator interface { // Evaluate performs the evaluation. The v argument is the value of the prior // expression operator. The yield argument is used to pass one or more additional // values to the next expression operator. Evaluate(c context.Context, v any, yield func(any) error) error }
Evaluator provides the evaluation function for an expression operator.
func ComposeEvaluator ¶
ComposeEvaluator produces an evaluator which considers each evaluator in turn. If any evaluator yields the value, evaluation stops. If any evaluator returns an error, the evaluation stops and returns the error. This evaluator can be thought of as a logical conjunction in the case where evaluators work like Boolean predicates. Indeed, Predicate is often the type of the evaluators passed this function.
func Error ¶
Error provides an evaluator which yields an error. The zero value is also useful, returning a generic error
func EvaluatorOf ¶
EvaluatorOf creates an expression evaluator for a given value. The value must be bool or a function. If a bool, then it works as a predicate for the corresponding invariant (i.e. false filters out all values, and true includes all values). If an error value, then it always returns such an error. If a function, the signature must match either the Evaluator.Evaluate function signature or a variation that excludes the context and/or yielder. You can also use bool as a return type as in the same signature used by Predicate. These are valid signatures:
- func(*cli.Context, any, func(any)error) error
- func(*cli.Context, any) error
- func(*cli.Context, any) bool
- func(*cli.Context, any)
- func(*cli.Context) error
- func(*cli.Context) bool
- func(*cli.Context)
- func(context.Context, any, func(any)error) error
- func(context.Context, any) error
- func(context.Context, any) bool
- func(context.Context, any)
- func(context.Context) error
- func(context.Context) bool
- func(context.Context)
- func(any, func(any)error) error
- func(any) bool
- func(any) error
- func(any)
- func() bool
- func() error
- func()
type EvaluatorFunc ¶
EvaluatorFunc provides the basic function for an Evaluator
type Expr ¶
type Expr struct { // Name provides the name of the expression operator. This value must be set, and it is used to access // the expression operator's value via the context Name string // Aliases provides a list of alternative names for the expression operator. In general, Name should // be used for the long name of the expression operator, and Aliases should contain the short name. // If there are additional names for compatibility reasons, they should be included // with Aliases but listed after the preferred names. Note that only one short name // and one long name is displayed on help screens by default. Aliases []string // Args contains each of the arguments that are processed for the expression operators. Expression // operators don't contain values directly; they process one or more arguments. Args []*cli.Arg // HelpText contains text which briefly describes the usage of the expression operator. // For style, generally the usage text should be limited to about 40 characters. // Sentence case is recommended for the usage text. Uppercase is recommended for the // text of placeholders. The placeholder is used in the synopsis for the expression operator as well // as error messages. HelpText string // ManualText provides the text shown in the manual. The default templates don't use this value ManualText string // UsageText provides the usage for the expression operator. If left blank, a succinct synopsis // is generated from the type of the expression operator's arguments UsageText string // Category specifies the expression operator category. When categories are used, operators are grouped // together on the help screen Category string // Description provides a long description. The long description is // not used in any templates by default. The type of Description should be string or // fmt.Stringer. Refer to func Description for details. Description any // Evaluate provides the evaluation behavior for the expression. The value should // implement Evaluator or support runtime conversion to that interface via // the rules provided by the cli.EvaluatorOf function. Evaluate any // Before executes before the expression is evaluated. Refer to cli.Action about the correct // function signature to use. Before any // After executes after the expression is evaluated. Refer to cli.Action about the correct // function signature to use. After any // Uses provides an action handler that is always executed during the initialization phase // of the app. Typically, hooks and other configuration actions are added to this handler. Uses any // Data provides an arbitrary mapping of additional data. This data can be used by // middleware and it is made available to templates Data map[string]any // Options sets various options about how to treat the expression operator. For example, options can // hide the expression operator. Options cli.Option // contains filtered or unexported fields }
Expr represents an operator in an expression. An expression is composed of an ordered series of operators meant to describe how to process one or more values. A well-known implementation of an expression is in the Unix `find` command where each file is processed through a series of operands to filter a list of files.
func (*Expr) LookupData ¶
LookupData obtains the data if it exists
func (*Expr) SetAliases ¶
func (*Expr) SetCategory ¶
func (*Expr) SetDescription ¶
func (*Expr) SetHelpText ¶
func (*Expr) SetLocalArgs ¶
SetLocalArgs sets arguments
func (*Expr) SetManualText ¶
func (*Expr) SetUsageText ¶
type Expression ¶
type Expression struct { // Exprs identifies the expression operators that are allowed Exprs []*Expr // contains filtered or unexported fields }
Expression provides the parsed result of the expression that can be evaluated with the given inputs.
func FromContext ¶
func FromContext(c *cli.Context, name string) *Expression
FromContext obtains the expression from the context
func (*Expression) Append ¶
func (e *Expression) Append(expr Binding)
func (*Expression) Bindings ¶
func (e *Expression) Bindings() iter.Seq[Binding]
Bindings enumerates all the bindings on the expression
func (*Expression) Evaluate ¶
func (e *Expression) Evaluate(ctx context.Context, items ...any) error
func (*Expression) Initializer ¶
func (e *Expression) Initializer() cli.Action
Initializer is an action that binds expression handling to an argument. This is set up automatically when a command defines any expression operators. The exprFunc argument is used to determine which expressions to used. If nil, the default behavior is used which is to lookup Command.Exprs from the context
func (*Expression) Prepend ¶
func (e *Expression) Prepend(expr Binding)
func (*Expression) Set ¶
func (e *Expression) Set(arg string) error
func (*Expression) String ¶
func (e *Expression) String() string
func (*Expression) VisibleExprs ¶
func (e *Expression) VisibleExprs() []*Expr
VisibleExprs filters all expression operators by whether they are not hidden
type Invariant ¶
type Invariant bool
Invariant provides an evaluator which either always or never yields the input value