Refactor nodes cmd

This commit is contained in:
ohdearaugustin 2021-07-25 15:04:06 +02:00
parent 53185eaa9e
commit 2862c2034b

View File

@ -11,12 +11,20 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var NodeCmd = &cobra.Command{ func init () {
nodeCmd.PersistentFlags().StringP("namespace", "n", "", "Namespace")
nodeCmd.MarkPersistentFlagRequired("namespace")
nodeCmd.AddCommand(listNodesCmd)
nodeCmd.AddCommand(registerNodeCmd)
nodeCmd.AddCommand(deleteNodeCmd)
}
var nodeCmd = &cobra.Command{
Use: "nodes", Use: "nodes",
Short: "Manage the nodes of Headscale", Short: "Manage the nodes of Headscale",
} }
var RegisterCmd = &cobra.Command{ var registerNodeCmd = &cobra.Command{
Use: "register machineID", Use: "register machineID",
Short: "Registers a machine to your network", Short: "Registers a machine to your network",
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {
@ -49,7 +57,7 @@ var RegisterCmd = &cobra.Command{
}, },
} }
var ListNodesCmd = &cobra.Command{ var listNodesCmd = &cobra.Command{
Use: "list", Use: "list",
Short: "List the nodes in a given namespace", Short: "List the nodes in a given namespace",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
@ -89,7 +97,7 @@ var ListNodesCmd = &cobra.Command{
}, },
} }
var DeleteCmd = &cobra.Command{ var deleteNodeCmd = &cobra.Command{
Use: "delete ID", Use: "delete ID",
Short: "Delete a node", Short: "Delete a node",
Args: func(cmd *cobra.Command, args []string) error { Args: func(cmd *cobra.Command, args []string) error {