main.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //go:generate goversioninfo -icon=windowsdata/resource/netclient.ico -manifest=netclient.exe.manifest.xml -64=true -o=netclient.syso
  2. // -build gui
  3. package main
  4. import (
  5. "log"
  6. "os"
  7. "runtime/debug"
  8. "github.com/gravitl/netmaker/netclient/cli_options"
  9. "github.com/gravitl/netmaker/netclient/config"
  10. "github.com/gravitl/netmaker/netclient/ncutils"
  11. "github.com/gravitl/netmaker/netclient/ncwindows"
  12. "github.com/urfave/cli/v2"
  13. )
  14. var version = "dev"
  15. func main() {
  16. app := cli.NewApp()
  17. app.Name = "Netclient"
  18. app.Version = version
  19. ncutils.SetVersion(version)
  20. cliFlags := cli_options.GetFlags(ncutils.GetHostname())
  21. app.Commands = cli_options.GetCommands(cliFlags[:])
  22. app.Description = "Used to perform interactions with Netmaker server and set local WireGuard config."
  23. app.Usage = "Netmaker's netclient agent and CLI."
  24. app.UsageText = "netclient [global options] command [command options] [arguments...]. Adjust verbosity of given command with -v, -vv or -vvv (max)."
  25. setGarbageCollection()
  26. if ncutils.IsWindows() {
  27. ncwindows.InitWindows()
  28. } else {
  29. ncutils.CheckUID()
  30. ncutils.CheckWG()
  31. if ncutils.IsLinux() {
  32. ncutils.CheckFirewall()
  33. }
  34. }
  35. if len(os.Args) <= 1 && config.GuiActive {
  36. config.GuiRun.(func())()
  37. } else {
  38. err := app.Run(os.Args)
  39. if err != nil {
  40. log.Fatal(err)
  41. }
  42. }
  43. }
  44. func setGarbageCollection() {
  45. _, gcset := os.LookupEnv("GOGC")
  46. if !gcset {
  47. debug.SetGCPercent(ncutils.DEFAULT_GC_PERCENT)
  48. }
  49. }