mirror of
https://github.com/Luzifer/expose.git
synced 2024-12-22 19:01:21 +00:00
Add json output for tunnels
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
d018404fba
commit
eca2addf6e
1 changed files with 9 additions and 2 deletions
11
cmd/list.go
11
cmd/list.go
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue