1
0
Fork 0
mirror of https://github.com/Luzifer/expose.git synced 2024-12-23 03:11:21 +00:00

Add json output for tunnels

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2018-10-15 21:13:41 +02:00
parent d018404fba
commit eca2addf6e
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E

View file

@ -1,7 +1,8 @@
package cmd package cmd
import ( import (
"fmt" "encoding/json"
"log"
"os" "os"
"github.com/olekukonko/tablewriter" "github.com/olekukonko/tablewriter"
@ -18,8 +19,12 @@ var listCmd = &cobra.Command{
return err return err
} }
if j, _ := cmd.Flags().GetBool("json"); j {
return json.NewEncoder(os.Stdout).Encode(tunnels)
}
if len(tunnels) == 0 { if len(tunnels) == 0 {
fmt.Println("No tunnels are active right now.") log.Println("No tunnels are active right now.")
return nil return nil
} }
@ -45,6 +50,8 @@ var listCmd = &cobra.Command{
func init() { func init() {
RootCmd.AddCommand(listCmd) RootCmd.AddCommand(listCmd)
listCmd.Flags().Bool("json", false, "Give JSON output instead of table")
// Here you will define your flags and configuration settings. // Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command // Cobra supports Persistent Flags which will work for this command