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