Documentation
¶
Index ¶
Constants ¶
View Source
const (
PrefixFlag = "__flag_"
)
Variables ¶
View Source
var (
ErrConflict = errors.New("runtime conflict")
)
View Source
var (
ErrEmptyDir = errors.New("empty directory")
)
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command struct {
Name string `json:"name,omitempty" yaml:"name,omitempty"`
Alias string `json:"alias,omitempty" yaml:"alias,omitempty"`
Long string `json:"long,omitempty" yaml:"long,omitempty"`
Script string `json:"script,omitempty" yaml:"script,omitempty"`
Authors []string `json:"authors,omitempty" yaml:"authors,omitempty"`
Version string `json:"version,omitempty" yaml:"version,omitempty"`
Example string `json:"example,omitempty" yaml:"example,omitempty"`
Params []*Schema `json:"params,omitempty" yaml:"params,omitempty"`
Returns []*Schema `json:"returns,omitempty" yaml:"returns,omitempty"`
Commands []*Command `json:"commands,omitempty" yaml:"commands,omitempty"`
Mutable bool `json:"mutable,omitempty" yaml:"mutable,omitempty"`
Hide bool `json:"hide,omitempty" yaml:"hide,omitempty"`
Root string `json:"root,omitempty" yaml:"root,omitempty"`
PreRun RunE `json:"-" yaml:"-"`
Run RunE `json:"-" yaml:"-"`
PostRun RunE `json:"-" yaml:"-"`
// contains filtered or unexported fields
}
func (*Command) NewContext ¶
type CommandErr ¶ added in v0.2.0
func (*CommandErr) Error ¶ added in v0.2.0
func (e *CommandErr) Error() string
type Module ¶
type RunContext ¶
type RunE ¶
type RunE func(ctx *RunContext, options ...client.ExecOption) ([]byte, error)
var DefaultRunCommand RunE = func(ctx *RunContext, opts ...client.ExecOption) ([]byte, error) { command := ctx.Cmd lg := ctx.Logger conn := ctx.Conn eOpts := client.NewExecOptions() for _, opt := range opts { opt(eOpts) } args := make([]string, 0) command.Flags().VisitAll(func(flag *pflag.Flag) { value := ctx.Variables.GetDefault(PrefixFlag+flag.Name, flag.Value.String()) arg := "--" + flag.Name + "=" + value args = append(args, arg) }) args = append(args, eOpts.Args...) options := make([]client.ExecOption, 0) ext, ok := KnownExt(path.Ext(command.Script)) if !ok { ext = Tengo } home := ctx.Variables.GetDefault(vars.BeeHome, ".bee") goos := ctx.Variables.GetDefault(vars.BeePlatformVars, "linux") var repl string var err error if repl, err = checkRepl(goos, ext); err != nil { return nil, err } resolve := path.Join(home, "modules") root := path.Join(resolve, eOpts.Root) script := path.Join(home, "modules", command.Root, command.Script) if goos == "windows" { resolve = strings.ReplaceAll(resolve, "/", "\\") root = strings.ReplaceAll(root, "/", "\\") script = strings.ReplaceAll(script, "/", "\\") } switch ext { case Tengo: repl = path.Join(home, "bin", repl) if goos == "windows" { repl = strings.ReplaceAll(repl, "/", "\\") } options = append(options, client.ExecWithArgs("-import="+resolve)) case Bash: repl = "/bin/bash" options = append(options, client.ExecWithArgs("-c")) case Powershell: repl = "powershell.exe" } options = append(options, client.ExecWithArgs(script)) options = append(options, client.ExecWithArgs(args...)) options = append(options, client.ExecWithRootDir(root)) for key, value := range eOpts.Environments { options = append(options, client.ExecWithEnv(key, value)) } shell := fmt.Sprintf("%s -import %s %s %s", repl, resolve, script, strings.Join(args, " ")) start := time.Now() cmd, err := conn.Execute(ctx, repl, options...) if err != nil { return nil, err } data, err := cmd.CombinedOutput() lg.Debug("remote execute", zap.String("command", shell), zap.Duration("took", time.Now().Sub(start))) if err != nil { return nil, &CommandErr{Err: err, Stderr: beautify(data)} } return beautify(data), nil }
type Schema ¶
type Schema struct {
Name string `json:"name,omitempty" yaml:"name,omitempty"`
Type string `json:"type,omitempty" yaml:"type,omitempty"`
Short string `json:"short,omitempty" yaml:"short,omitempty"`
Desc string `json:"desc,omitempty" yaml:"desc,omitempty"`
Default string `json:"default,omitempty" yaml:"default,omitempty"`
Example string `json:"example,omitempty" yaml:"example,omitempty"`
Value *SchemaValue `json:"-" yaml:"-"`
}
func (*Schema) InitValue ¶
func (s *Schema) InitValue() *SchemaValue
type SchemaValue ¶
type SchemaValue struct {
IntP *int64
UintP *uint64
StringP *string
FloatP *float64
DurationP *time.Duration
}
func (*SchemaValue) Set ¶
func (sv *SchemaValue) Set(text string) error
func (*SchemaValue) String ¶
func (sv *SchemaValue) String() string
func (*SchemaValue) Type ¶
func (sv *SchemaValue) Type() string
type StableMap ¶
type StableMap struct {
// contains filtered or unexported fields
}
func NewVariables ¶
func NewVariables() *StableMap
Click to show internal directories.
Click to hide internal directories.