Namespace is now a flag for all the commands
This commit is contained in:
parent
7646bd8fd4
commit
b83318bfb3
5 changed files with 69 additions and 33 deletions
|
@ -7,21 +7,31 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var RoutesCmd = &cobra.Command{
|
||||
Use: "routes",
|
||||
Short: "Manage the routes of Headscale",
|
||||
}
|
||||
|
||||
var ListRoutesCmd = &cobra.Command{
|
||||
Use: "list-routes NAMESPACE NODE",
|
||||
Use: "list NODE",
|
||||
Short: "List the routes exposed by this node",
|
||||
Args: func(cmd *cobra.Command, args []string) error {
|
||||
if len(args) < 2 {
|
||||
if len(args) < 1 {
|
||||
return fmt.Errorf("Missing parameters")
|
||||
}
|
||||
return nil
|
||||
},
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
n, err := cmd.Flags().GetString("namespace")
|
||||
if err != nil {
|
||||
log.Fatalf("Error getting namespace: %s", err)
|
||||
}
|
||||
|
||||
h, err := getHeadscaleApp()
|
||||
if err != nil {
|
||||
log.Fatalf("Error initializing: %s", err)
|
||||
}
|
||||
routes, err := h.GetNodeRoutes(args[0], args[1])
|
||||
routes, err := h.GetNodeRoutes(n, args[0])
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
|
@ -31,20 +41,25 @@ var ListRoutesCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
var EnableRouteCmd = &cobra.Command{
|
||||
Use: "enable-route",
|
||||
Use: "enable node-name route",
|
||||
Short: "Allows exposing a route declared by this node to the rest of the nodes",
|
||||
Args: func(cmd *cobra.Command, args []string) error {
|
||||
if len(args) < 3 {
|
||||
if len(args) < 2 {
|
||||
return fmt.Errorf("Missing parameters")
|
||||
}
|
||||
return nil
|
||||
},
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
n, err := cmd.Flags().GetString("namespace")
|
||||
if err != nil {
|
||||
log.Fatalf("Error getting namespace: %s", err)
|
||||
}
|
||||
|
||||
h, err := getHeadscaleApp()
|
||||
if err != nil {
|
||||
log.Fatalf("Error initializing: %s", err)
|
||||
}
|
||||
err = h.EnableNodeRoute(args[0], args[1], args[2])
|
||||
err = h.EnableNodeRoute(n, args[0], args[1])
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue