mirror of
https://github.com/openziti/zrok.git
synced 2024-11-08 01:04:08 +01:00
zrok console (#362)
This commit is contained in:
parent
309b146fd8
commit
9a6e28f2b1
40
cmd/zrok/console.go
Normal file
40
cmd/zrok/console.go
Normal 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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user