shell

package
v0.0.0-...-abf2cf9 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ShellAction = core.Action{
	Name: "shell",
	Doc:  "run shell commands",
	DefaultConf: ShellActionConf{
		Command: "echo \"hello world\"",
	},
	Run: func(conf interface{}) (interface{}, error) {
		c, ok := conf.(ShellActionConf)
		if !ok {
			return "", fmt.Errorf("conf type is not correct")
		}
		args := strings.Split(c.Command, " ")
		eCmd := exec.Command(args[0], args[1:]...)
		stdout := bytes.NewBuffer([]byte(""))
		stderr := bytes.NewBuffer([]byte(""))
		eCmd.Stdout = stdout
		eCmd.Stderr = stderr
		err := eCmd.Run()
		if err != nil {
			return nil, err
		}
		fmt.Printf("command: %s\n", eCmd.String())
		fmt.Printf("stdout: %s\n", stdout.String())
		fmt.Printf("stderr: %s\n", stderr.String())
		return map[string]string{
			"stdout": stdout.String(),
			"stderr": stderr.String(),
		}, nil
	},
}

Functions

This section is empty.

Types

type ShellActionConf

type ShellActionConf struct {
	Command string `yaml:"command" validate:"required"`
}

Jump to

Keyboard shortcuts

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