From 8dadb045cfa0148bf7c8da8cf434f1535e889d14 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Thu, 26 Jan 2023 08:41:21 +0100 Subject: [PATCH] Mark -n and --namespace as deprecated Signed-off-by: Kristoffer Dalby --- CHANGELOG.md | 1 + cmd/headscale/cli/debug.go | 8 +++++++- cmd/headscale/cli/nodes.go | 23 ++++++++++++++++++++--- cmd/headscale/cli/preauthkeys.go | 8 +++++++- cmd/headscale/cli/root.go | 7 ++++++- cmd/headscale/cli/users.go | 2 +- 6 files changed, 42 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca01e74f..77e89aef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Rename Namespace to User [#1144](https://github.com/juanfont/headscale/pull/1144) - **BACKUP your database before upgrading** +- Command line flags previously taking `--namespace` or `-n` will now require `--user` or `-u` ## 0.18.0 (2022-01-14) diff --git a/cmd/headscale/cli/debug.go b/cmd/headscale/cli/debug.go index d149de29..383ed13c 100644 --- a/cmd/headscale/cli/debug.go +++ b/cmd/headscale/cli/debug.go @@ -27,7 +27,13 @@ func init() { if err != nil { log.Fatal().Err(err).Msg("") } - createNodeCmd.Flags().StringP("user", "n", "", "User") + createNodeCmd.Flags().StringP("user", "u", "", "User") + + createNodeCmd.Flags().StringP("namespace", "n", "", "User") + createNodeNamespaceFlag := createNodeCmd.Flags().Lookup("namespace") + createNodeNamespaceFlag.Deprecated = deprecateNamespaceMessage + createNodeNamespaceFlag.Hidden = true + err = createNodeCmd.MarkFlagRequired("user") if err != nil { log.Fatal().Err(err).Msg("") diff --git a/cmd/headscale/cli/nodes.go b/cmd/headscale/cli/nodes.go index e5d35fc9..5d8babd8 100644 --- a/cmd/headscale/cli/nodes.go +++ b/cmd/headscale/cli/nodes.go @@ -19,11 +19,23 @@ import ( func init() { rootCmd.AddCommand(nodeCmd) - listNodesCmd.Flags().StringP("user", "n", "", "Filter by user") + listNodesCmd.Flags().StringP("user", "u", "", "Filter by user") listNodesCmd.Flags().BoolP("tags", "t", false, "Show tags") + + listNodesCmd.Flags().StringP("namespace", "n", "", "User") + listNodesNamespaceFlag := listNodesCmd.Flags().Lookup("namespace") + listNodesNamespaceFlag.Deprecated = deprecateNamespaceMessage + listNodesNamespaceFlag.Hidden = true + nodeCmd.AddCommand(listNodesCmd) - registerNodeCmd.Flags().StringP("user", "n", "", "User") + registerNodeCmd.Flags().StringP("user", "u", "", "User") + + registerNodeCmd.Flags().StringP("namespace", "n", "", "User") + registerNodeNamespaceFlag := registerNodeCmd.Flags().Lookup("namespace") + registerNodeNamespaceFlag.Deprecated = deprecateNamespaceMessage + registerNodeNamespaceFlag.Hidden = true + err := registerNodeCmd.MarkFlagRequired("user") if err != nil { log.Fatalf(err.Error()) @@ -63,7 +75,12 @@ func init() { log.Fatalf(err.Error()) } - moveNodeCmd.Flags().StringP("user", "n", "", "New user") + moveNodeCmd.Flags().StringP("user", "u", "", "New user") + + moveNodeCmd.Flags().StringP("namespace", "n", "", "User") + moveNodeNamespaceFlag := moveNodeCmd.Flags().Lookup("namespace") + moveNodeNamespaceFlag.Deprecated = deprecateNamespaceMessage + moveNodeNamespaceFlag.Hidden = true err = moveNodeCmd.MarkFlagRequired("user") if err != nil { diff --git a/cmd/headscale/cli/preauthkeys.go b/cmd/headscale/cli/preauthkeys.go index c08b4637..7eb19560 100644 --- a/cmd/headscale/cli/preauthkeys.go +++ b/cmd/headscale/cli/preauthkeys.go @@ -20,7 +20,13 @@ const ( func init() { rootCmd.AddCommand(preauthkeysCmd) - preauthkeysCmd.PersistentFlags().StringP("user", "n", "", "User") + preauthkeysCmd.PersistentFlags().StringP("user", "u", "", "User") + + preauthkeysCmd.PersistentFlags().StringP("namespace", "n", "", "User") + pakNamespaceFlag := preauthkeysCmd.PersistentFlags().Lookup("namespace") + pakNamespaceFlag.Deprecated = deprecateNamespaceMessage + pakNamespaceFlag.Hidden = true + err := preauthkeysCmd.MarkPersistentFlagRequired("user") if err != nil { log.Fatal().Err(err).Msg("") diff --git a/cmd/headscale/cli/root.go b/cmd/headscale/cli/root.go index 411eaed8..cf173f56 100644 --- a/cmd/headscale/cli/root.go +++ b/cmd/headscale/cli/root.go @@ -12,10 +12,15 @@ import ( "github.com/tcnksm/go-latest" ) +const ( + deprecateNamespaceMessage = "use --user" +) + var cfgFile string = "" func init() { - if len(os.Args) > 1 && (os.Args[1] == "version" || os.Args[1] == "mockoidc" || os.Args[1] == "completion") { + if len(os.Args) > 1 && + (os.Args[1] == "version" || os.Args[1] == "mockoidc" || os.Args[1] == "completion") { return } diff --git a/cmd/headscale/cli/users.go b/cmd/headscale/cli/users.go index c3ec90b4..653ab537 100644 --- a/cmd/headscale/cli/users.go +++ b/cmd/headscale/cli/users.go @@ -27,7 +27,7 @@ const ( var userCmd = &cobra.Command{ Use: "users", Short: "Manage the users of Headscale", - Aliases: []string{"user", "namespace", "ns"}, + Aliases: []string{"user", "namespace", "namespaces", "ns"}, } var createUserCmd = &cobra.Command{