Skip to content

Commit

Permalink
support flags on both up and service commands families
Browse files Browse the repository at this point in the history
  • Loading branch information
nazarewk committed Mar 2, 2023
1 parent a6080bd commit 65d74d3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
45 changes: 26 additions & 19 deletions client/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"time"

"github.com/cenkalti/backoff/v4"
"github.com/netbirdio/netbird/iface"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -105,25 +106,31 @@ func init() {
rootCmd.AddCommand(sshCmd)
serviceCmd.AddCommand(runCmd, startCmd, stopCmd, restartCmd) // service control commands are subcommands of service
serviceCmd.AddCommand(installCmd, uninstallCmd) // service installer commands are subcommands of service
upCmd.PersistentFlags().StringSliceVar(&natExternalIPs, externalIPMapFlag, nil,
`Sets external IPs maps between local addresses and interfaces.`+
`You can specify a comma-separated list with a single IP and IP/IP or IP/Interface Name. `+
`An empty string "" clears the previous configuration. `+
`E.g. --external-ip-map 12.34.56.78/10.0.0.1 or --external-ip-map 12.34.56.200,12.34.56.78/10.0.0.1,12.34.56.80/eth1 `+
`or --external-ip-map ""`,
)
upCmd.PersistentFlags().StringVar(&customDNSAddress, dnsResolverAddress, "",
`Sets a custom address for NetBird's local DNS resolver. `+
`If set, the agent won't attempt to discover the best ip and port to listen on. `+
`An empty string "" clears the previous configuration. `+
`E.g. --dns-resolver-address 127.0.0.1:5053 or --dns-resolver-address ""`,
)
// do not set default, because it will override whatever custom value was set
upCmd.PersistentFlags().StringVar(&wgIface, "wg-iface", "",
`WireGuard interface name to use for Netbird client instance. `+
`MacOS restricts the tun interface name to utun[0-9]+ pattern. e.g., utun100`)
// do not set default, because it will override whatever custom value was set
upCmd.PersistentFlags().IntVar(&wgPort, "wg-port", 0, "WireGuard port number to use for Netbird client instance")

for _, cmd := range []*cobra.Command{upCmd, serviceCmd} {
cmd.PersistentFlags().StringSliceVar(&natExternalIPs, externalIPMapFlag, nil,
`Sets external IPs maps between local addresses and interfaces.`+
`You can specify a comma-separated list with a single IP and IP/IP or IP/Interface Name. `+
`An empty string "" clears the previous configuration. `+
`E.g. --external-ip-map 12.34.56.78/10.0.0.1 or --external-ip-map 12.34.56.200,12.34.56.78/10.0.0.1,12.34.56.80/eth1 `+
`or --external-ip-map ""`,
)
cmd.PersistentFlags().StringVar(&customDNSAddress, dnsResolverAddress, "",
`Sets a custom address for NetBird's local DNS resolver. `+
`If set, the agent won't attempt to discover the best ip and port to listen on. `+
`An empty string "" clears the previous configuration. `+
`E.g. --dns-resolver-address 127.0.0.1:5053 or --dns-resolver-address ""`,
)
// do not set default, because it will override whatever custom value was set
cmd.PersistentFlags().StringVar(&wgIface, "wg-iface", "",
`WireGuard interface name to use for Netbird client instance. `+
fmt.Sprintf("Defaults to %s", iface.WgInterfaceDefault)+
`MacOS restricts the tun interface name to utun[0-9]+ pattern. e.g., utun100`)
// do not set default, because it will override whatever custom value was set
cmd.PersistentFlags().IntVar(&wgPort, "wg-port", 0,
"WireGuard port number to use for Netbird client instance. "+
fmt.Sprintf("Defaults to %s", iface.WgInterfaceDefault))
}

}

Expand Down
8 changes: 8 additions & 0 deletions client/cmd/service_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ var runCmd = &cobra.Command{
Short: "runs Netbird as service",
RunE: func(cmd *cobra.Command, args []string) error {
SetFlagsFromEnvVars(rootCmd)
SetFlagsFromEnvVars(serviceCmd)
SetFlagsFromEnvVars(cmd)

cmd.SetOut(cmd.OutOrStdout())

Expand Down Expand Up @@ -119,6 +121,8 @@ var startCmd = &cobra.Command{
Short: "starts Netbird service",
RunE: func(cmd *cobra.Command, args []string) error {
SetFlagsFromEnvVars(rootCmd)
SetFlagsFromEnvVars(serviceCmd)
SetFlagsFromEnvVars(cmd)

cmd.SetOut(cmd.OutOrStdout())

Expand Down Expand Up @@ -154,6 +158,8 @@ var stopCmd = &cobra.Command{
Short: "stops Netbird service",
RunE: func(cmd *cobra.Command, args []string) error {
SetFlagsFromEnvVars(rootCmd)
SetFlagsFromEnvVars(serviceCmd)
SetFlagsFromEnvVars(cmd)

cmd.SetOut(cmd.OutOrStdout())

Expand Down Expand Up @@ -187,6 +193,8 @@ var restartCmd = &cobra.Command{
Short: "restarts Netbird service",
RunE: func(cmd *cobra.Command, args []string) error {
SetFlagsFromEnvVars(rootCmd)
SetFlagsFromEnvVars(serviceCmd)
SetFlagsFromEnvVars(cmd)

cmd.SetOut(cmd.OutOrStdout())

Expand Down

0 comments on commit 65d74d3

Please sign in to comment.