netmaker/netclient/main.go

56 lines
1.4 KiB
Go
Raw Normal View History

2022-05-07 03:21:57 +08:00
//go:generate goversioninfo -icon=windowsdata/resource/netclient.ico -manifest=netclient.exe.manifest.xml -64=true -o=netclient.syso
2022-05-06 00:36:13 +08:00
// -build gui
2021-08-31 03:58:23 +08:00
2021-03-26 00:17:52 +08:00
package main
import (
2021-07-26 02:22:20 +08:00
"log"
"os"
2021-09-20 02:03:47 +08:00
"runtime/debug"
2021-12-09 05:52:32 +08:00
"github.com/gravitl/netmaker/netclient/cli_options"
2022-05-05 23:11:37 +08:00
"github.com/gravitl/netmaker/netclient/config"
2021-09-20 02:03:47 +08:00
"github.com/gravitl/netmaker/netclient/ncutils"
2021-08-31 03:58:23 +08:00
"github.com/gravitl/netmaker/netclient/ncwindows"
2021-07-26 02:22:20 +08:00
"github.com/urfave/cli/v2"
2021-03-26 00:17:52 +08:00
)
var version = "dev"
2021-03-26 00:17:52 +08:00
func main() {
2021-07-26 02:22:20 +08:00
app := cli.NewApp()
app.Name = "Netclient"
app.Version = version
ncutils.SetVersion(version)
2021-12-09 05:52:32 +08:00
cliFlags := cli_options.GetFlags(ncutils.GetHostname())
app.Commands = cli_options.GetCommands(cliFlags[:])
app.Description = "Used to perform interactions with Netmaker server and set local WireGuard config."
app.Usage = "Netmaker's netclient agent and CLI."
2022-03-25 01:50:35 +08:00
app.UsageText = "netclient [global options] command [command options] [arguments...]. Adjust verbosity of given command with -v, -vv or -vvv (max)."
setGarbageCollection()
2021-09-20 02:03:47 +08:00
if ncutils.IsWindows() {
2021-08-31 03:58:23 +08:00
ncwindows.InitWindows()
} else {
2021-12-09 05:52:32 +08:00
ncutils.CheckUID()
ncutils.CheckWG()
2021-08-31 03:58:23 +08:00
}
2022-02-02 13:18:02 +08:00
2022-05-05 23:11:37 +08:00
if len(os.Args) <= 1 && config.GuiActive {
config.GuiRun.(func())()
2022-05-05 21:48:02 +08:00
} else {
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
2021-07-26 02:22:20 +08:00
}
2021-03-26 00:17:52 +08:00
}
2021-09-20 02:03:47 +08:00
func setGarbageCollection() {
_, gcset := os.LookupEnv("GOGC")
if !gcset {
2021-09-20 02:03:47 +08:00
debug.SetGCPercent(ncutils.DEFAULT_GC_PERCENT)
}
2021-09-20 02:03:47 +08:00
}