main.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. }
  32. if len(os.Args) <= 1 && config.GuiActive {
  33. config.GuiRun.(func())()
  34. } else {
  35. err := app.Run(os.Args)
  36. if err != nil {
  37. log.Fatal(err)
  38. }
  39. }
  40. }
  41. func setGarbageCollection() {
  42. _, gcset := os.LookupEnv("GOGC")
  43. if !gcset {
  44. debug.SetGCPercent(ncutils.DEFAULT_GC_PERCENT)
  45. }
  46. }