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 `yaml:"name"` Long string `yaml:"long"` Script string `yaml:"script"` Authors []string `yaml:"authors"` Version string `yaml:"version"` Example string `yaml:"example"` Params []*Schema `yaml:"params"` Returns []*Schema `yaml:"returns"` Commands []*Command `yaml:"commands"` Root string `yaml:"root"` PreRun RunE `yaml:"-"` Run RunE `yaml:"-"` PostRun RunE `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 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 execOptions := client.NewExecOptions() for _, opt := range opts { opt(execOptions) } command.Flags().VisitAll(func(flag *pflag.Flag) { value := ctx.Variables.GetDefault(PrefixFlag+flag.Name, flag.Value.String()) arg := "--" + flag.Name + "=" + value execOptions.Args = append(execOptions.Args, arg) }) 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 } script := path.Join(home, "modules", command.Root, command.Script) if goos == "windows" { script = strings.ReplaceAll(script, "/", "\\") } switch ext { case Tengo: repl = path.Join(home, "bin", repl) if goos == "windows" { repl = strings.ReplaceAll(repl, "/", "\\") } case Bash: options = append(options, client.ExecWithArgs("-c")) case Powershell: } options = append(options, client.ExecWithArgs(script)) options = append(options, client.ExecWithArgs(execOptions.Args...)) for key, value := range execOptions.Environments { options = append(options, client.ExecWithEnv(key, value)) } shell := fmt.Sprintf("%s %s %s", repl, script, strings.Join(execOptions.Args, " ")) lg.Debug("remote execute", zap.String("command", shell)) cmd, err := conn.Execute(ctx, repl, options...) if err != nil { return nil, err } data, err := cmd.CombinedOutput() if err != nil { return nil, &CommandErr{Err: err, Stderr: beautify(data)} } return beautify(data), nil }
type Schema ¶
type Schema struct { Name string `yaml:"name"` Type string `yaml:"type"` Short string `yaml:"short"` Description string `yaml:"description"` Default string `yaml:"default"` Example string `yaml:"example"` Value *SchemaValue `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.