2023-06-29 19:03:30 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-07-13 20:26:35 +02:00
|
|
|
"github.com/openziti/zrok/environment"
|
2023-06-29 19:03:30 +02:00
|
|
|
"github.com/openziti/zrok/tui"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
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) {
|
2023-07-13 20:26:35 +02:00
|
|
|
env, err := environment.LoadRoot()
|
2023-06-29 19:03:30 +02:00
|
|
|
if err != nil {
|
2023-07-10 22:41:16 +02:00
|
|
|
tui.Error("unable to load environment", err)
|
2023-06-29 19:03:30 +02:00
|
|
|
}
|
|
|
|
|
2023-07-10 22:41:16 +02:00
|
|
|
apiEndpoint, _ := env.ApiEndpoint()
|
2023-06-29 19:18:30 +02:00
|
|
|
if err := openBrowser(apiEndpoint); err != nil {
|
2023-06-29 19:03:30 +02:00
|
|
|
tui.Error(fmt.Sprintf("unable to open '%v'", apiEndpoint), err)
|
|
|
|
}
|
|
|
|
}
|