zrok console (#362)

This commit is contained in:
Michael Quigley 2023-06-29 13:03:30 -04:00
parent 309b146fd8
commit 9a6e28f2b1
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62

40
cmd/zrok/console.go Normal file
View File

@ -0,0 +1,40 @@
package main
import (
"fmt"
"github.com/openziti/zrok/tui"
"github.com/openziti/zrok/zrokdir"
"github.com/spf13/cobra"
"os/exec"
)
func init() {
rootCmd.AddCommand(newConsoleCommand().cmd)
}
type consoleCommand struct {
cmd *cobra.Command
}
func newConsoleCommand() *consoleCommand {
cmd := &cobra.Command{
Use: "console",
Short: "Open the web console",
Args: cobra.ExactArgs(0),
}
command := &consoleCommand{cmd}
cmd.Run = command.run
return command
}
func (cmd *consoleCommand) run(_ *cobra.Command, _ []string) {
zrd, err := zrokdir.Load()
if err != nil {
tui.Error("unable to load zrokdir", err)
}
apiEndpoint, _ := zrd.ApiEndpoint()
if err := exec.Command("open", apiEndpoint).Run(); err != nil {
tui.Error(fmt.Sprintf("unable to open '%v'", apiEndpoint), err)
}
}