cli.go 952 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package nsinit
  2. import (
  3. "log"
  4. "os"
  5. "github.com/codegangsta/cli"
  6. )
  7. var (
  8. logPath = os.Getenv("log")
  9. argvs = make(map[string]func())
  10. )
  11. func init() {
  12. argvs["nsenter"] = nsenter
  13. }
  14. func preload(context *cli.Context) error {
  15. if logPath != "" {
  16. if err := openLog(logPath); err != nil {
  17. return err
  18. }
  19. }
  20. return nil
  21. }
  22. func NsInit() {
  23. // we need to check our argv 0 for any registred functions to run instead of the
  24. // normal cli code path
  25. action, exists := argvs[os.Args[0]]
  26. if exists {
  27. action()
  28. return
  29. }
  30. app := cli.NewApp()
  31. app.Name = "nsinit"
  32. app.Version = "0.1"
  33. app.Author = "libcontainer maintainers"
  34. app.Flags = []cli.Flag{
  35. cli.StringFlag{Name: "nspid"},
  36. cli.StringFlag{Name: "console"},
  37. }
  38. app.Before = preload
  39. app.Commands = []cli.Command{
  40. execCommand,
  41. initCommand,
  42. statsCommand,
  43. configCommand,
  44. pauseCommand,
  45. unpauseCommand,
  46. }
  47. if err := app.Run(os.Args); err != nil {
  48. log.Fatal(err)
  49. }
  50. }