mirror of
https://github.com/juanfont/headscale.git
synced 2024-12-20 19:09:07 +01:00
More json output
This commit is contained in:
parent
3b34f715ce
commit
abde7dddb7
@ -49,12 +49,18 @@ var ListNodesCmd = &cobra.Command{
|
||||
if err != nil {
|
||||
log.Fatalf("Error getting namespace: %s", err)
|
||||
}
|
||||
o, _ := cmd.Flags().GetString("output")
|
||||
|
||||
h, err := getHeadscaleApp()
|
||||
if err != nil {
|
||||
log.Fatalf("Error initializing: %s", err)
|
||||
}
|
||||
machines, err := h.ListMachinesInNamespace(n)
|
||||
if strings.HasPrefix(o, "json") {
|
||||
jsonOutput(machines, err, o)
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("Error getting nodes: %s", err)
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package cli
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/hako/durafmt"
|
||||
@ -22,14 +23,20 @@ var ListPreAuthKeys = &cobra.Command{
|
||||
if err != nil {
|
||||
log.Fatalf("Error getting namespace: %s", err)
|
||||
}
|
||||
o, _ := cmd.Flags().GetString("output")
|
||||
|
||||
h, err := getHeadscaleApp()
|
||||
if err != nil {
|
||||
log.Fatalf("Error initializing: %s", err)
|
||||
}
|
||||
keys, err := h.GetPreAuthKeys(n)
|
||||
if strings.HasPrefix(o, "json") {
|
||||
jsonOutput(keys, err, o)
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
fmt.Printf("Error getting the list of keys: %s\n", err)
|
||||
return
|
||||
}
|
||||
for _, k := range *keys {
|
||||
@ -57,6 +64,7 @@ var CreatePreAuthKeyCmd = &cobra.Command{
|
||||
if err != nil {
|
||||
log.Fatalf("Error getting namespace: %s", err)
|
||||
}
|
||||
o, _ := cmd.Flags().GetString("output")
|
||||
|
||||
h, err := getHeadscaleApp()
|
||||
if err != nil {
|
||||
@ -75,11 +83,15 @@ var CreatePreAuthKeyCmd = &cobra.Command{
|
||||
expiration = &exp
|
||||
}
|
||||
|
||||
_, err = h.CreatePreAuthKey(n, reusable, expiration)
|
||||
k, err := h.CreatePreAuthKey(n, reusable, expiration)
|
||||
if strings.HasPrefix(o, "json") {
|
||||
jsonOutput(k, err, o)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("Ook.\n")
|
||||
fmt.Printf("Key: %s\n", k.Key)
|
||||
},
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package cli
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@ -26,16 +27,24 @@ var ListRoutesCmd = &cobra.Command{
|
||||
if err != nil {
|
||||
log.Fatalf("Error getting namespace: %s", err)
|
||||
}
|
||||
o, _ := cmd.Flags().GetString("output")
|
||||
|
||||
h, err := getHeadscaleApp()
|
||||
if err != nil {
|
||||
log.Fatalf("Error initializing: %s", err)
|
||||
}
|
||||
routes, err := h.GetNodeRoutes(n, args[0])
|
||||
|
||||
if strings.HasPrefix(o, "json") {
|
||||
jsonOutput(routes, err, o)
|
||||
return
|
||||
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println(routes)
|
||||
},
|
||||
}
|
||||
@ -54,15 +63,22 @@ var EnableRouteCmd = &cobra.Command{
|
||||
if err != nil {
|
||||
log.Fatalf("Error getting namespace: %s", err)
|
||||
}
|
||||
o, _ := cmd.Flags().GetString("output")
|
||||
|
||||
h, err := getHeadscaleApp()
|
||||
if err != nil {
|
||||
log.Fatalf("Error initializing: %s", err)
|
||||
}
|
||||
err = h.EnableNodeRoute(n, args[0], args[1])
|
||||
route, err := h.EnableNodeRoute(n, args[0], args[1])
|
||||
if strings.HasPrefix(o, "json") {
|
||||
jsonOutput(route, err, o)
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("Enabled route %s\n", route)
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user