File size: 815 Bytes
3b67767 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
package shell
// Example usage of the shell package:
//
// 1. For one-off commands:
//
// shell := shell.NewShell(nil)
// stdout, stderr, err := shell.Exec(context.Background(), "echo hello")
//
// 2. For maintaining state across commands:
//
// shell := shell.NewShell(&shell.Options{
// WorkingDir: "/tmp",
// Logger: myLogger,
// })
// shell.Exec(ctx, "export FOO=bar")
// shell.Exec(ctx, "echo $FOO") // Will print "bar"
//
// 3. For the singleton persistent shell (used by tools):
//
// shell := shell.GetPersistentShell("/path/to/cwd")
// stdout, stderr, err := shell.Exec(ctx, "ls -la")
//
// 4. Managing environment and working directory:
//
// shell := shell.NewShell(nil)
// shell.SetEnv("MY_VAR", "value")
// shell.SetWorkingDir("/tmp")
// cwd := shell.GetWorkingDir()
// env := shell.GetEnv()
|