cmds.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package cli_options
  2. import (
  3. "github.com/gravitl/netmaker/logger"
  4. "github.com/gravitl/netmaker/netclient/command"
  5. "github.com/gravitl/netmaker/netclient/config"
  6. "github.com/urfave/cli/v2"
  7. )
  8. // GetCommands - return commands that CLI uses
  9. func GetCommands(cliFlags []cli.Flag) []*cli.Command {
  10. return []*cli.Command{
  11. {
  12. Name: "join",
  13. Usage: "Join a Netmaker network.",
  14. Flags: cliFlags,
  15. Action: func(c *cli.Context) error {
  16. parseVerbosity(c)
  17. cfg, pvtKey, err := config.GetCLIConfig(c)
  18. if err != nil {
  19. return err
  20. }
  21. err = command.Join(&cfg, pvtKey)
  22. return err
  23. },
  24. },
  25. {
  26. Name: "leave",
  27. Usage: "Leave a Netmaker network.",
  28. Flags: cliFlags,
  29. // the action, or code that will be executed when
  30. // we execute our `ns` command
  31. Action: func(c *cli.Context) error {
  32. parseVerbosity(c)
  33. cfg, _, err := config.GetCLIConfig(c)
  34. if err != nil {
  35. return err
  36. }
  37. err = command.Leave(&cfg)
  38. return err
  39. },
  40. },
  41. {
  42. Name: "pull",
  43. Usage: "Pull latest configuration and peers from server.",
  44. Flags: cliFlags,
  45. // the action, or code that will be executed when
  46. // we execute our `ns` command
  47. Action: func(c *cli.Context) error {
  48. parseVerbosity(c)
  49. cfg, _, err := config.GetCLIConfig(c)
  50. if err != nil {
  51. return err
  52. }
  53. err = command.Pull(&cfg)
  54. return err
  55. },
  56. },
  57. {
  58. Name: "list",
  59. Usage: "Get list of networks.",
  60. Flags: cliFlags,
  61. // the action, or code that will be executed when
  62. // we execute our `ns` command
  63. Action: func(c *cli.Context) error {
  64. parseVerbosity(c)
  65. cfg, _, err := config.GetCLIConfig(c)
  66. if err != nil {
  67. return err
  68. }
  69. err = command.List(cfg)
  70. return err
  71. },
  72. },
  73. {
  74. Name: "uninstall",
  75. Usage: "Uninstall the netclient system service.",
  76. Flags: cliFlags,
  77. // the action, or code that will be executed when
  78. // we execute our `ns` command
  79. Action: func(c *cli.Context) error {
  80. parseVerbosity(c)
  81. err := command.Uninstall()
  82. return err
  83. },
  84. },
  85. {
  86. Name: "daemon",
  87. Usage: "run netclient as daemon",
  88. Flags: cliFlags,
  89. Action: func(c *cli.Context) error {
  90. // set max verbosity for daemon regardless
  91. logger.Verbosity = 4
  92. err := command.Daemon()
  93. return err
  94. },
  95. },
  96. {
  97. Name: "install",
  98. Usage: "install binary and daemon",
  99. Flags: cliFlags,
  100. Action: func(c *cli.Context) error {
  101. parseVerbosity(c)
  102. return command.Install()
  103. },
  104. },
  105. }
  106. }
  107. // == Private funcs ==
  108. func parseVerbosity(c *cli.Context) {
  109. if c.Bool("v") {
  110. logger.Verbosity = 1
  111. } else if c.Bool("vv") {
  112. logger.Verbosity = 2
  113. } else if c.Bool("vvv") {
  114. logger.Verbosity = 3
  115. } else if c.Bool("vvvv") {
  116. logger.Verbosity = 4
  117. }
  118. }