🌱🏠🧑‍💻 command line greenhouse client application: an interface to the greenhouse daemon https://greenhouse.server.garden/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.5 KiB

package main
import (
"encoding/json"
"fmt"
"os"
"strings"
)
func ls(args []string) {
if len(args) > 1 {
fmt.Printf("\nError: unknown extra arguments '%s' provided to the ls command\n", strings.Join(args[1:], " "))
displayHelpAndExit("ls")
return
}
status, err := getStatus(false)
if err != nil {
fmt.Printf("\nError: %s\n\n", err)
os.Exit(1)
return
}
if status.NeedsAPIToken {
fmt.Print("\nGreenhouse Daemon is not registered to a Greenhouse account yet. Run the following command to register your account:\n\ngreenhouse register GREENHOUSE_API_TOKEN [SERVER_NAME]\n\n")
os.Exit(0)
return
} else {
if len(args) == 1 {
if args[0] == "--json" {
bytez, err := json.MarshalIndent(status.GUITunnels, "", " ")
if err != nil {
fmt.Print("\nJSON serialization error: %s\n", err)
os.Exit(1)
return
}
fmt.Printf("%s\n", string(bytez))
} else {
fmt.Print("\nError: unknown argument '%s' provided to the ls command. expected --json\n", args[0])
os.Exit(1)
return
}
} else {
fmt.Print("\nTunnels:\n")
for _, tunnel := range status.GUITunnels {
destHost := "localhost"
if tunnel.DestinationType == "host_port" {
destHost = tunnel.DestinationHostname
}
dest := fmt.Sprintf("tcp://%s:%d", destHost, tunnel.DestinationPort)
if tunnel.DestinationType == "folder" {
dest = fmt.Sprintf("file://%s", tunnel.DestinationFolderPath)
}
fmt.Printf(" %s to %s\n", tunnelListenURL(&tunnel), dest)
}
fmt.Print("\n")
}
}
}