cmds.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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: "checkin",
  49. Usage: "Checks for local changes and then checks into the specified Netmaker network to ask about remote changes.",
  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.CheckIn(cfg)
  59. return err
  60. },
  61. },
  62. {
  63. Name: "push",
  64. Usage: "Push configuration changes to server.",
  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.Push(cfg)
  74. return err
  75. },
  76. },
  77. {
  78. Name: "pull",
  79. Usage: "Pull latest configuration and peers from server.",
  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. cfg, _, err := config.GetCLIConfig(c)
  85. if err != nil {
  86. return err
  87. }
  88. err = command.Pull(cfg)
  89. return err
  90. },
  91. },
  92. {
  93. Name: "list",
  94. Usage: "Get list of networks.",
  95. Flags: cliFlags,
  96. // the action, or code that will be executed when
  97. // we execute our `ns` command
  98. Action: func(c *cli.Context) error {
  99. cfg, _, err := config.GetCLIConfig(c)
  100. if err != nil {
  101. return err
  102. }
  103. err = command.List(cfg)
  104. return err
  105. },
  106. },
  107. {
  108. Name: "uninstall",
  109. Usage: "Uninstall the netclient system service.",
  110. Flags: cliFlags,
  111. // the action, or code that will be executed when
  112. // we execute our `ns` command
  113. Action: func(c *cli.Context) error {
  114. err := command.Uninstall()
  115. return err
  116. },
  117. },
  118. {
  119. Name: "daemon",
  120. Usage: "run netclient as daemon",
  121. Flags: cliFlags,
  122. Action: func(c *cli.Context) error {
  123. err := command.Daemon()
  124. return err
  125. },
  126. },
  127. }
  128. }