starting on tui enhancements; zrok status (#124)

This commit is contained in:
Michael Quigley 2023-01-06 14:19:00 -05:00
parent bd0212ba09
commit 5a0c109937
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
4 changed files with 61 additions and 16 deletions

View File

@ -2,16 +2,13 @@ package main
import (
"fmt"
"github.com/charmbracelet/lipgloss"
httptransport "github.com/go-openapi/runtime/client"
"github.com/openziti-test-kitchen/zrok/rest_client_zrok/environment"
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
"github.com/openziti-test-kitchen/zrok/zrokdir"
"github.com/shirou/gopsutil/v3/host"
"github.com/spf13/cobra"
"os"
user2 "os/user"
"strings"
)
func init() {
@ -98,15 +95,3 @@ func getHost() (string, string, error) {
info.Hostname, info.OS, info.Platform, info.PlatformFamily, info.PlatformVersion, info.KernelVersion, info.KernelArch)
return info.Hostname, thisHost, nil
}
var errorStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#D90166")).Background(lipgloss.Color("0"))
func showError(msg string, err error) {
errorLabel := errorStyle.Render("ERROR:")
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "%v %v (%v)\n", errorLabel, msg, strings.TrimSpace(err.Error()))
} else {
_, _ = fmt.Fprintf(os.Stderr, "%v %v\n", errorLabel, msg)
}
os.Exit(1)
}

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

@ -0,0 +1,40 @@
package main
import (
"fmt"
"github.com/openziti-test-kitchen/zrok/zrokdir"
"github.com/spf13/cobra"
"os"
)
func init() {
rootCmd.AddCommand(newStatusCommand().cmd)
}
type statusCommand struct {
cmd *cobra.Command
}
func newStatusCommand() *statusCommand {
cmd := &cobra.Command{
Use: "status",
Short: "Show the current environment status",
Aliases: []string{"st"},
Args: cobra.ExactArgs(0),
}
command := &statusCommand{cmd: cmd}
cmd.Run = command.run
return command
}
func (cmd *statusCommand) run(_ *cobra.Command, _ []string) {
_, _ = fmt.Fprintf(os.Stderr, "\n")
_, err := zrokdir.LoadEnvironment()
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "%v: Unable to load your local environment! (%v)\n\n", warningLabel, err)
_, _ = fmt.Fprintf(os.Stderr, "To create a local environment use the %v command.\n", codeStyle.Render("zrok enable"))
}
_, _ = fmt.Fprintf(os.Stderr, "\n")
}

View File

@ -1,9 +1,12 @@
package main
import (
"fmt"
"github.com/charmbracelet/lipgloss"
"github.com/go-openapi/runtime"
httptransport "github.com/go-openapi/runtime/client"
"os"
"strings"
)
type backendHandler interface {
@ -17,3 +20,18 @@ func mustGetAdminAuth() runtime.ClientAuthInfoWriter {
}
return httptransport.APIKeyAuth("X-TOKEN", "header", adminToken)
}
var errorStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#D90166")).Background(lipgloss.Color("0"))
var errorLabel = errorStyle.Render("ERROR")
var warningStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#FFA500")).Background(lipgloss.Color("0"))
var warningLabel = warningStyle.Render("WARNING")
var codeStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#00FFFF")).Background(lipgloss.Color("0"))
func showError(msg string, err error) {
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "%v: %v (%v)\n", errorLabel, msg, strings.TrimSpace(err.Error()))
} else {
_, _ = fmt.Fprintf(os.Stderr, "%v %v\n", errorLabel, msg)
}
os.Exit(1)
}

View File

@ -2,6 +2,7 @@ package main
import (
"fmt"
"github.com/charmbracelet/lipgloss"
"github.com/openziti-test-kitchen/zrok/build"
"github.com/spf13/cobra"
)
@ -25,5 +26,6 @@ func newVersionCommand() *versionCommand {
}
func (cmd *versionCommand) run(_ *cobra.Command, _ []string) {
fmt.Println(" _ \n _____ __ ___ | | __\n|_ / '__/ _ \\| |/ /\n / /| | | (_) | < \n/___|_| \\___/|_|\\_\\\n\n" + build.String() + "\n")
zrokStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("#FF0080"))
fmt.Println(zrokStyle.Render(" _ \n _____ __ ___ | | __\n|_ / '__/ _ \\| |/ /\n / /| | | (_) | < \n/___|_| \\___/|_|\\_\\") + "\n\n" + codeStyle.Render(build.String()) + "\n")
}