1
0
mirror of https://github.com/Luzifer/expose.git synced 2024-09-20 08:02:57 +00:00
expose/cmd/list.go
Knut Ahlers 1d35b0988e
Initial version
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2017-04-14 02:45:38 +02:00

59 lines
1.2 KiB
Go

package cmd
import (
"fmt"
"os"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
)
// listCmd represents the list command
var listCmd = &cobra.Command{
Use: "list",
Short: "List all currently active tunnels",
RunE: func(cmd *cobra.Command, args []string) error {
tunnels, err := client.ListTunnels()
if err != nil {
return err
}
if len(tunnels) == 0 {
fmt.Println("No tunnels are active right now.")
return nil
}
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Name", "Type", "Address", "Public URL"})
table.SetBorder(false)
for _, tun := range tunnels {
table.Append([]string{
tun.Name,
tun.Proto,
tun.Config.Addr,
tun.PublicURL,
})
}
table.Render()
return nil
},
}
func init() {
RootCmd.AddCommand(listCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// listCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// listCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}