cmds.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package cli_options
  2. import (
  3. "errors"
  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. cfg, pvtKey, err := config.GetCLIConfig(c)
  17. if err != nil {
  18. return err
  19. }
  20. if cfg.Network == "all" {
  21. err = errors.New("no network provided")
  22. return err
  23. }
  24. if cfg.Server.GRPCAddress == "" {
  25. err = errors.New("no server address provided")
  26. return err
  27. }
  28. err = command.Join(cfg, pvtKey)
  29. return err
  30. },
  31. },
  32. {
  33. Name: "leave",
  34. Usage: "Leave a Netmaker network.",
  35. Flags: cliFlags,
  36. // the action, or code that will be executed when
  37. // we execute our `ns` command
  38. Action: func(c *cli.Context) error {
  39. cfg, _, err := config.GetCLIConfig(c)
  40. if err != nil {
  41. return err
  42. }
  43. err = command.Leave(cfg)
  44. return err
  45. },
  46. },
  47. {
  48. Name: "pull",
  49. Usage: "Pull latest configuration and peers from server.",
  50. Flags: cliFlags,
  51. // the action, or code that will be executed when
  52. // we execute our `ns` command
  53. Action: func(c *cli.Context) error {
  54. cfg, _, err := config.GetCLIConfig(c)
  55. if err != nil {
  56. return err
  57. }
  58. err = command.Pull(cfg)
  59. return err
  60. },
  61. },
  62. {
  63. Name: "list",
  64. Usage: "Get list of networks.",
  65. Flags: cliFlags,
  66. // the action, or code that will be executed when
  67. // we execute our `ns` command
  68. Action: func(c *cli.Context) error {
  69. cfg, _, err := config.GetCLIConfig(c)
  70. if err != nil {
  71. return err
  72. }
  73. err = command.List(cfg)
  74. return err
  75. },
  76. },
  77. {
  78. Name: "uninstall",
  79. Usage: "Uninstall the netclient system service.",
  80. Flags: cliFlags,
  81. // the action, or code that will be executed when
  82. // we execute our `ns` command
  83. Action: func(c *cli.Context) error {
  84. err := command.Uninstall()
  85. return err
  86. },
  87. },
  88. {
  89. Name: "daemon",
  90. Usage: "run netclient as daemon",
  91. Flags: cliFlags,
  92. Action: func(c *cli.Context) error {
  93. err := command.Daemon()
  94. return err
  95. },
  96. },
  97. }
  98. }