From ea3043cdcb1585f8db7499d6df8fa47eae041b76 Mon Sep 17 00:00:00 2001 From: ohdearaugustin Date: Sun, 25 Jul 2021 16:26:15 +0200 Subject: [PATCH] cmd: Add error check for Persistent Flags --- cmd/headscale/cli/nodes.go | 5 ++++- cmd/headscale/cli/preauthkeys.go | 4 ++++ cmd/headscale/cli/routes.go | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cmd/headscale/cli/nodes.go b/cmd/headscale/cli/nodes.go index 7a773ce..4be706b 100644 --- a/cmd/headscale/cli/nodes.go +++ b/cmd/headscale/cli/nodes.go @@ -13,7 +13,10 @@ import ( func init () { nodeCmd.PersistentFlags().StringP("namespace", "n", "", "Namespace") - nodeCmd.MarkPersistentFlagRequired("namespace") + err := nodeCmd.MarkPersistentFlagRequired("namespace") + if err != nil { + log.Fatalf(err.Error()) + } nodeCmd.AddCommand(listNodesCmd) nodeCmd.AddCommand(registerNodeCmd) nodeCmd.AddCommand(deleteNodeCmd) diff --git a/cmd/headscale/cli/preauthkeys.go b/cmd/headscale/cli/preauthkeys.go index 8964bcf..881b5ca 100644 --- a/cmd/headscale/cli/preauthkeys.go +++ b/cmd/headscale/cli/preauthkeys.go @@ -13,6 +13,10 @@ import ( func init() { rootCmd.AddCommand(preauthkeysCmd) preauthkeysCmd.PersistentFlags().StringP("namespace", "n", "", "Namespace") + err := preauthkeysCmd.MarkPersistentFlagRequired("namespace") + if err != nil { + log.Fatalf(err.Error()) + } preauthkeysCmd.AddCommand(listPreAuthKeys) preauthkeysCmd.AddCommand(createPreAuthKeyCmd) createPreAuthKeyCmd.PersistentFlags().Bool("reusable", false, "Make the preauthkey reusable") diff --git a/cmd/headscale/cli/routes.go b/cmd/headscale/cli/routes.go index aa39281..98b653f 100644 --- a/cmd/headscale/cli/routes.go +++ b/cmd/headscale/cli/routes.go @@ -11,6 +11,10 @@ import ( func init() { rootCmd.AddCommand(routesCmd) routesCmd.PersistentFlags().StringP("namespace", "n", "", "Namespace") + err := routesCmd.MarkPersistentFlagRequired("namespace") + if err != nil { + log.Fatalf(err.Error()) + } routesCmd.AddCommand(listRoutesCmd) routesCmd.AddCommand(enableRouteCmd) }