Documentation ¶
Overview ¶
Package go-sh is intented to make shell call with golang more easily. Some usage is more similar to os/exec, eg: Run(), Output(), Command(name, args...)
But with these similar function, pipe is added in and this package also got shell-session support.
Why I love golang so much, because the usage of golang is simple, but the power is unlimited. I want to make this pakcage got the sample style like golang.
// just like os/exec sh.Command("echo", "hello").Run() // support pipe sh.Command("echo", "hello").Command("wc", "-c").Run() // create a session to store dir and env sh.NewSession().SetDir("/").Command("pwd") // shell buildin command - "test" sh.Test("dir", "mydir") // like shell call: (cd /; pwd) sh.Command("pwd", sh.Dir("/")) same with sh.Command(sh.Dir("/"), "pwd") // output to json and xml easily v := map[string] int {} err = sh.Command("echo", `{"nunber": 1}`).UnmarshalJSON(&v)
Index ¶
- func Test(exp string, arg string) bool
- type Dir
- type Session
- func (s *Session) Alias(alias, cmd string, args ...string)
- func (s *Session) Call(name string, a ...interface{}) error
- func (s *Session) Command(name string, a ...interface{}) *Session
- func (s *Session) Output() (out []byte, err error)
- func (s *Session) Run() (err error)
- func (s *Session) SetDir(dir string) *Session
- func (s *Session) SetEnv(key, value string) *Session
- func (s *Session) Start() (err error)
- func (s *Session) Test(expression string, argument string) bool
- func (s *Session) UnmarshalJSON(data interface{}) (err error)
- func (s *Session) UnmarshalXML(data interface{}) (err error)
- func (s *Session) Wait() (err error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Session ¶
type Session struct { Env map[string]string Stdout io.Writer Stderr io.Writer ShowCMD bool // enable for debug // contains filtered or unexported fields }
func Command ¶
Example ¶
out, err := sh.Command("echo", "hello").Output() fmt.Println(string(out), err)
Output:
func NewSession ¶
func NewSession() *Session
func (*Session) UnmarshalJSON ¶
unmarshal shell output to decode json
func (*Session) UnmarshalXML ¶
unmarshal command output into xml
Click to show internal directories.
Click to hide internal directories.