doc.go 646 B

12345678910111213141516171819202122232425
  1. package shell
  2. // Example usage of the shell package:
  3. //
  4. // 1. For one-off commands:
  5. //
  6. // shell := shell.NewShell(nil)
  7. // stdout, stderr, err := shell.Exec(context.Background(), "echo hello")
  8. //
  9. // 2. For maintaining state across commands:
  10. //
  11. // shell := shell.NewShell(&shell.Options{
  12. // WorkingDir: "/tmp",
  13. // Logger: myLogger,
  14. // })
  15. // shell.Exec(ctx, "export FOO=bar")
  16. // shell.Exec(ctx, "echo $FOO") // Will print "bar"
  17. //
  18. // 3. Managing environment and working directory:
  19. //
  20. // shell := shell.NewShell(nil)
  21. // shell.SetEnv("MY_VAR", "value")
  22. // shell.SetWorkingDir("/tmp")
  23. // cwd := shell.GetWorkingDir()
  24. // env := shell.GetEnv()