Involve foreground mode switch for up cmd (#654)

Add new --deamon-off command line parameter
for 'up' cmd instead of existing log-file workaround

Split the up function and organize the code
This commit is contained in:
Zoltan Papp 2023-01-16 18:12:51 +01:00 committed by GitHub
parent afaf0660be
commit 2bc3d88af3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,10 +13,20 @@ import (
gstatus "google.golang.org/grpc/status" gstatus "google.golang.org/grpc/status"
) )
var upCmd = &cobra.Command{ var (
foregroundMode bool
upCmd = &cobra.Command{
Use: "up", Use: "up",
Short: "install, login and start Netbird client", Short: "install, login and start Netbird client",
RunE: func(cmd *cobra.Command, args []string) error { RunE: upFunc,
}
)
func init() {
upCmd.PersistentFlags().BoolVarP(&foregroundMode, "foreground-mode", "F", false, "start service in foreground")
}
func upFunc(cmd *cobra.Command, args []string) error {
SetFlagsFromEnvVars() SetFlagsFromEnvVars()
cmd.SetOut(cmd.OutOrStdout()) cmd.SetOut(cmd.OutOrStdout())
@ -28,9 +38,14 @@ var upCmd = &cobra.Command{
ctx := internal.CtxInitState(cmd.Context()) ctx := internal.CtxInitState(cmd.Context())
// workaround to run without service if foregroundMode {
if logFile == "console" { return runInForegroundMode(ctx, cmd)
err = handleRebrand(cmd) }
return runInDaemonMode(ctx, cmd)
}
func runInForegroundMode(ctx context.Context, cmd *cobra.Command) error {
err := handleRebrand(cmd)
if err != nil { if err != nil {
return err return err
} }
@ -56,7 +71,9 @@ var upCmd = &cobra.Command{
ctx, cancel = context.WithCancel(ctx) ctx, cancel = context.WithCancel(ctx)
SetupCloseHandler(ctx, cancel) SetupCloseHandler(ctx, cancel)
return internal.RunClient(ctx, config, nbStatus.NewRecorder()) return internal.RunClient(ctx, config, nbStatus.NewRecorder())
} }
func runInDaemonMode(ctx context.Context, cmd *cobra.Command) error {
conn, err := DialClientGRPCServer(ctx, daemonAddr) conn, err := DialClientGRPCServer(ctx, daemonAddr)
if err != nil { if err != nil {
@ -129,5 +146,4 @@ var upCmd = &cobra.Command{
} }
cmd.Println("Connected") cmd.Println("Connected")
return nil return nil
},
} }