From 04dffcc4ae79c1e12e78cc4f19fef7303e459500 Mon Sep 17 00:00:00 2001 From: ohdearaugustin Date: Sun, 25 Jul 2021 15:14:09 +0200 Subject: [PATCH] Refactor cli commands --- cmd/headscale/headscale.go | 63 +------------------------------------- 1 file changed, 1 insertion(+), 62 deletions(-) diff --git a/cmd/headscale/headscale.go b/cmd/headscale/headscale.go index c6e56fa..c7b834c 100644 --- a/cmd/headscale/headscale.go +++ b/cmd/headscale/headscale.go @@ -1,77 +1,16 @@ package main import ( - "fmt" "log" - "os" "github.com/juanfont/headscale/cmd/headscale/cli" - "github.com/spf13/cobra" ) -var headscaleCmd = &cobra.Command{ - Use: "headscale", - Short: "headscale - a Tailscale control server", - Long: ` -headscale is an open source implementation of the Tailscale control server - -Juan Font Alonso - 2021 -https://gitlab.com/juanfont/headscale`, -} - func main() { err := cli.LoadConfig("") if err != nil { log.Fatalf(err.Error()) } - headscaleCmd.AddCommand(cli.NamespaceCmd) - headscaleCmd.AddCommand(cli.NodeCmd) - headscaleCmd.AddCommand(cli.PreauthkeysCmd) - headscaleCmd.AddCommand(cli.RoutesCmd) - headscaleCmd.AddCommand(cli.ServeCmd) - headscaleCmd.AddCommand(cli.VersionCmd) - - cli.NodeCmd.PersistentFlags().StringP("namespace", "n", "", "Namespace") - err = cli.NodeCmd.MarkPersistentFlagRequired("namespace") - if err != nil { - log.Fatalf(err.Error()) - } - - cli.PreauthkeysCmd.PersistentFlags().StringP("namespace", "n", "", "Namespace") - err = cli.PreauthkeysCmd.MarkPersistentFlagRequired("namespace") - if err != nil { - log.Fatalf(err.Error()) - } - - cli.RoutesCmd.PersistentFlags().StringP("namespace", "n", "", "Namespace") - err = cli.RoutesCmd.MarkPersistentFlagRequired("namespace") - if err != nil { - log.Fatalf(err.Error()) - } - - cli.NamespaceCmd.AddCommand(cli.CreateNamespaceCmd) - cli.NamespaceCmd.AddCommand(cli.ListNamespacesCmd) - cli.NamespaceCmd.AddCommand(cli.DestroyNamespaceCmd) - - cli.NodeCmd.AddCommand(cli.ListNodesCmd) - cli.NodeCmd.AddCommand(cli.RegisterCmd) - cli.NodeCmd.AddCommand(cli.DeleteCmd) - - cli.RoutesCmd.AddCommand(cli.ListRoutesCmd) - cli.RoutesCmd.AddCommand(cli.EnableRouteCmd) - - cli.PreauthkeysCmd.AddCommand(cli.ListPreAuthKeys) - cli.PreauthkeysCmd.AddCommand(cli.CreatePreAuthKeyCmd) - - cli.CreatePreAuthKeyCmd.PersistentFlags().Bool("reusable", false, "Make the preauthkey reusable") - cli.CreatePreAuthKeyCmd.PersistentFlags().Bool("ephemeral", false, "Preauthkey for ephemeral nodes") - cli.CreatePreAuthKeyCmd.Flags().StringP("expiration", "e", "", "Human-readable expiration of the key (30m, 24h, 365d...)") - - headscaleCmd.PersistentFlags().StringP("output", "o", "", "Output format. Empty for human-readable, 'json' or 'json-line'") - - if err := headscaleCmd.Execute(); err != nil { - fmt.Println(err) - os.Exit(-1) - } + cli.Execute() }