Skip to content

Commit

Permalink
change colors and add logout, support info, env section, update texts…
Browse files Browse the repository at this point in the history
… and ux
  • Loading branch information
krls committed Apr 23, 2024
1 parent 901c44b commit b08022b
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 104 deletions.
37 changes: 37 additions & 0 deletions src/cmd/env.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package cmd

import (
"context"
"fmt"

"github.com/zeropsio/zcli/src/cmdBuilder"
"github.com/zeropsio/zcli/src/i18n"
"github.com/zeropsio/zcli/src/constants"
"github.com/zeropsio/zcli/src/uxBlock"
"github.com/zeropsio/zcli/src/uxBlock/styles"
)

var env string

func envCmd() *cmdBuilder.Cmd {
return cmdBuilder.NewCmd().
Use("env").
Short(i18n.T(i18n.CmdDescEnv)).
HelpFlag(i18n.T(i18n.CmdHelpEnv)).
GuestRunFunc(func(ctx context.Context, cmdData *cmdBuilder.GuestCmdData) error {

fmt.Println(styles.CobraSectionColor().SetString("Global Env Variables:").String() + `
` + styles.CobraItemNameColor().SetString(constants.CliLogFilePathEnvVar).String() + ` ` + i18n.T(i18n.CliLogFilePathEnvVar) + `
` + styles.CobraItemNameColor().SetString(constants.CliDataFilePathEnvVar).String() + ` ` + i18n.T(i18n.CliDataFilePathEnvVar) + `
` + styles.CobraItemNameColor().SetString(constants.CliTerminalMode).String() + ` ` + i18n.T(i18n.CliTerminalModeEnvVar))

fmt.Println(styles.CobraSectionColor().SetString(`
Curently used variables:`).String())

body := &uxBlock.TableBody{}
guestInfoPart(body)
cmdData.UxBlocks.Table(body)

return nil
})
}
42 changes: 42 additions & 0 deletions src/cmd/logout.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package cmd

import (
"context"

"github.com/zeropsio/zcli/src/cmdBuilder"
"github.com/zeropsio/zcli/src/cliStorage"
"github.com/zeropsio/zcli/src/i18n"
"github.com/zeropsio/zcli/src/uxBlock/styles"
)

var logout string

func logoutCmd() *cmdBuilder.Cmd {
return cmdBuilder.NewCmd().
Use("logout").
Short(i18n.T(i18n.CmdDescLogout)).
HelpFlag(i18n.T(i18n.CmdHelpLogout)).
LoggedUserRunFunc(func(ctx context.Context, cmdData *cmdBuilder.LoggedUserCmdData) error {

uxBlocks := cmdData.UxBlocks

_, err := cmdData.RestApiClient.PostAuthLogout(ctx)
if err != nil {
return err
}

_, err = cmdData.CliStorage.Update(func(data cliStorage.Data) cliStorage.Data {
return cliStorage.Data{}
})
if err != nil {
return err
}

uxBlocks.PrintInfo(styles.InfoLine(i18n.T(i18n.LogoutVpnDisconnecting)))
disconnectVpn(ctx, cmdData.UxBlocks) // TODO: ask - there is no need for any declaration - i can just call this function from anywhere?
uxBlocks.PrintInfo(styles.SuccessLine(i18n.T(i18n.LogoutSuccess)))

return nil

})
}
52 changes: 27 additions & 25 deletions src/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,37 @@ func rootCmd() *cmdBuilder.Cmd {
SetHelpTemplate(getRootTemplate()).
SilenceError(true).
AddChildrenCmd(loginCmd()).
AddChildrenCmd(logoutCmd()).
AddChildrenCmd(versionCmd()).
AddChildrenCmd(scopeCmd()).
AddChildrenCmd(projectCmd()).
AddChildrenCmd(serviceCmd()).
AddChildrenCmd(vpnCmd()).
AddChildrenCmd(statusShowDebugLogsCmd()).
AddChildrenCmd(servicePushCmd()).
AddChildrenCmd(envCmd()).
AddChildrenCmd(supportCmd()).
GuestRunFunc(func(ctx context.Context, cmdData *cmdBuilder.GuestCmdData) error {
body := &uxBlock.TableBody{}
fmt.Println(`Welcome to zCli by Zerops!

Check failure on line 39 in src/cmd/root.go

View workflow job for this annotation

GitHub Actions / Build && tests for linux amd64

fmt.Println arg list ends with redundant newline

Check failure on line 39 in src/cmd/root.go

View workflow job for this annotation

GitHub Actions / Build && tests for linux 386

fmt.Println arg list ends with redundant newline
body.AddStringsRow(i18n.T(i18n.StatusInfoLoggedUser), "-")
To unlock the full potential of zCLI, you need to log in using your Zerops account.
Logging in enables you to access various features and interact with Zerops services seamlessly.
guestInfoPart(body)
To log in, simply use the following command: zcli login <your_token>
Replace <your_token> with the authentication token generated from your Zerops account.
Once logged in, you'll be able to manage projects, deploy applications, configure VPN,
and much more directly from the command line interface.
cmdData.UxBlocks.Table(body)
If you encounter any issues during the login process or have any questions,
feel free to find out how to contact our support team by running 'zcli support'.
`)

// print the default command help
cmdData.PrintHelp()

return nil
}).
LoggedUserRunFunc(func(ctx context.Context, cmdData *cmdBuilder.LoggedUserCmdData) error {
body := &uxBlock.TableBody{}

var loggedUser string
if info, err := cmdData.RestApiClient.GetUserInfo(ctx); err != nil {
Expand All @@ -60,10 +68,8 @@ func rootCmd() *cmdBuilder.Cmd {
}
}

body.AddStringsRow(i18n.T(i18n.StatusInfoLoggedUser), loggedUser)

guestInfoPart(body)

// TODO: krls - check whole block
if cmdData.CliStorage.Data().ScopeProjectId.Filled() {
// project scope is set
projectId, _ := cmdData.CliStorage.Data().ScopeProjectId.Get()
Expand All @@ -75,20 +81,21 @@ func rootCmd() *cmdBuilder.Cmd {
return err
}
} else {
body.AddStringsRow(i18n.T(i18n.ScopedProject), err.Error())
fmt.Print(i18n.T(i18n.ScopedProject), err.Error())
}
} else {
body.AddStringsRow(i18n.T(i18n.ScopedProject), fmt.Sprintf("%s [%s]", project.Name.String(), project.ID.Native()))
fmt.Print(i18n.T(i18n.ScopedProject), fmt.Sprintf("%s [%s]", project.Name.String(), project.ID.Native()))
}
}

var vpnStatusText string
if isVpnUp(ctx, cmdData.UxBlocks, 1) {
body.AddStringsRow(i18n.T(i18n.StatusInfoVpnStatus), i18n.T(i18n.VpnCheckingConnectionIsActive))
vpnStatusText = i18n.T(i18n.VpnCheckingConnectionIsActive)
} else {
body.AddStringsRow(i18n.T(i18n.StatusInfoVpnStatus), i18n.T(i18n.VpnCheckingConnectionIsNotActive))
vpnStatusText = i18n.T(i18n.VpnCheckingConnectionIsNotActive)
}

cmdData.UxBlocks.Table(body)
fmt.Printf("Welcome in Zerops!\nYou are loged as %s \nand your %s.\n\n", loggedUser, vpnStatusText)

// print the default command help
cmdData.PrintHelp()
Expand Down Expand Up @@ -119,23 +126,23 @@ func guestInfoPart(tableBody *uxBlock.TableBody) {

func getRootTemplate() string {
return styles.CobraSectionColor().SetString("Usage:").String() + `{{if .Runnable}}
{{.UseLine}}{{end}}{{if .HasAvailableSubCommands}}
{{.CommandPath}} [command]{{end}}{{if gt (len .Aliases) 0}}
{{.UseLine}}{{end}}{{if .HasAvailableSubCommands}}
{{.CommandPath}} [command]{{end}}{{if gt (len .Aliases) 0}}
` + styles.CobraSectionColor().SetString("Aliases:").String() + `
{{.NameAndAliases}}{{end}}{{if .HasExample}}
{{.NameAndAliases}}{{end}}{{if .HasExample}}
` + styles.CobraSectionColor().SetString("Examples:").String() + `
{{.Example}}{{end}}{{if .HasAvailableSubCommands}}{{$cmds := .Commands}}{{if eq (len .Groups) 0}}
` + styles.CobraSectionColor().SetString("Available Commands:").String() + `{{range $cmds}}{{if (or .IsAvailableCommand (eq .Name "help"))}}
` + styles.CobraItemNameColor().SetString("{{rpad .Name .NamePadding }}").String() + ` {{.Short}}{{end}}{{end}}{{else}}{{range $group := .Groups}}
` + styles.CobraItemNameColor().SetString("{{rpad .Name .NamePadding }}").String() + ` {{.Short}}{{end}}{{end}}{{else}}{{range $group := .Groups}}
{{.Title}}{{range $cmds}}{{if (and (eq .GroupID $group.ID) (or .IsAvailableCommand (eq .Name "help")))}}
` + styles.CobraItemNameColor().SetString("{{rpad .Name .NamePadding }}").String() + ` {{.Short}}{{end}}{{end}}{{end}}{{if not .AllChildCommandsHaveGroup}}
` + styles.CobraItemNameColor().SetString("{{rpad .Name .NamePadding }}").String() + ` {{.Short}}{{end}}{{end}}{{end}}{{if not .AllChildCommandsHaveGroup}}
` + styles.CobraSectionColor().SetString("Additional Commands:").String() + `{{range $cmds}}{{if (and (eq .GroupID "") (or .IsAvailableCommand (eq .Name "help")))}}
` + styles.CobraItemNameColor().SetString("{{rpad .Name .NamePadding }}").String() + ` {{.Short}}{{end}}{{end}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}}
` + styles.CobraItemNameColor().SetString("{{rpad .Name .NamePadding }}").String() + ` {{.Short}}{{end}}{{end}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}}
` + styles.CobraSectionColor().SetString("Flags:").String() + `
{{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasAvailableInheritedFlags}}
Expand All @@ -144,12 +151,7 @@ func getRootTemplate() string {
{{.InheritedFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasHelpSubCommands}}
` + styles.CobraSectionColor().SetString("Additional help topics:").String() + `{{range .Commands}}{{if .IsAdditionalHelpTopicCommand}}
` + styles.CobraItemNameColor().SetString("{{rpad .CommandPath .CommandPathPadding}}").String() + ` {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableSubCommands}}
` + styles.CobraSectionColor().SetString("Global Env Variables:").String() + `
` + styles.CobraItemNameColor().SetString(constants.CliLogFilePathEnvVar).String() + ` ` + i18n.T(i18n.CliLogFilePathEnvVar) + `
` + styles.CobraItemNameColor().SetString(constants.CliDataFilePathEnvVar).String() + ` ` + i18n.T(i18n.CliDataFilePathEnvVar) + `
` + styles.CobraItemNameColor().SetString(constants.CliTerminalMode).String() + ` ` + i18n.T(i18n.CliTerminalModeEnvVar) + `
` + styles.CobraItemNameColor().SetString("{{rpad .CommandPath .CommandPathPadding}}").String() + ` {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableSubCommands}}
Use "{{.CommandPath}} [command] --help" for more information about a command.{{end}}
`
Expand Down
33 changes: 33 additions & 0 deletions src/cmd/support.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package cmd

import (
"context"
"fmt"

"github.com/zeropsio/zcli/src/cmdBuilder"
"github.com/zeropsio/zcli/src/i18n"
)

var support string

func supportCmd() *cmdBuilder.Cmd {
return cmdBuilder.NewCmd().
Use("support").
Short(i18n.T(i18n.CmdDescSupport)).
HelpFlag(i18n.T(i18n.CmdHelpSupport)).
GuestRunFunc(func(ctx context.Context, cmdData *cmdBuilder.GuestCmdData) error {


fmt.Println("You can contact Zerops support via:")
fmt.Println("- E-mail: [email protected]")
fmt.Println("- Discord: https://discord.com/invite/WDvCZ54")
fmt.Println(`
Additionally, you can explore our documentation
at https://docs.zerops.io/references/cli for further details.
`)
return nil

return nil
})
}

2 changes: 1 addition & 1 deletion src/cmd/vpnDown.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func disconnectVpn(ctx context.Context, uxBlocks uxBlock.UxBlocks) error {
return err
}

uxBlocks.PrintInfo(styles.InfoLine(i18n.T(i18n.VpnDown)))
uxBlocks.PrintInfo(styles.SuccessLine(i18n.T(i18n.VpnDown)))

return nil
}
4 changes: 3 additions & 1 deletion src/cmd/vpnUp.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,15 @@ func vpnUpCmd() *cmdBuilder.Cmd {
return err
}


// wait for the vpn to be up
if isVpnUp(ctx, uxBlocks, 6) {
uxBlocks.PrintInfo(styles.InfoLine(i18n.T(i18n.VpnUp)))
uxBlocks.PrintInfo(styles.SuccessLine(i18n.T(i18n.VpnUp)))
} else {
uxBlocks.PrintWarning(styles.WarningLine(i18n.T(i18n.VpnPingFailed)))
}


return nil
})
}
Expand Down
26 changes: 20 additions & 6 deletions src/i18n/en.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ import "fmt"
var en = map[string]string{
// login
CmdHelpLogin: "the login command.",
CmdDescLogin: "Logs you into Zerops. Use a generated Zerops token or your login e-mail and password.",
CmdDescLogin: "Login into Zerops with generated Zerops token",
LoginSuccess: "You are logged as %s <%s>",
RegionNotFound: "Selected region %s not found",
RegionTableColumnName: "Name",

// logout
CmdHelpLogout: "the logout command.",
CmdDescLogout: "Disconnect from VPN and log out from your Zerops account",
LogoutVpnDisconnecting: "Disconnecting from VPN. Please provide your password if prompted.",
LogoutSuccess: "Successfully logged out. You are now disconnected from Zerops services.",

// scope
CmdHelpScope: "the scope command.",
CmdDescScope: "Scope commands group",
Expand All @@ -24,7 +30,7 @@ var en = map[string]string{

// project
CmdHelpProject: "the project command.",
CmdDescProject: "Project commands group.",
CmdDescProject: "Project commands group",

// project lit
CmdHelpProjectList: "the project list command.",
Expand Down Expand Up @@ -52,7 +58,7 @@ var en = map[string]string{

// service
CmdHelpService: "the service command.",
CmdDescService: "Zerops service commands group.",
CmdDescService: "Zerops service commands group",

// service start
CmdHelpServiceStart: "the service start command.",
Expand Down Expand Up @@ -109,7 +115,7 @@ var en = map[string]string{

// push
CmdHelpPush: "the service push command.",
CmdDescPush: "Builds your application in Zerops and deploys it.",
CmdDescPush: "Builds your application in Zerops and deploys it",
CmdDescPushLong: "Builds your application in Zerops and deploys it. \n\n" +
"The command triggers the build pipeline defined in zerops.yml. Zerops.yml must be in the working\n" +
"directory. The working directory is by default the current directory and can be changed\n" +
Expand Down Expand Up @@ -150,12 +156,20 @@ var en = map[string]string{

// status show debug logs
CmdHelpStatusShowDebugLogs: "the status show debug logs command.",
CmdDescStatusShowDebugLogs: "Shows zCLI debug logs.",
CmdDescStatusShowDebugLogs: "Shows zCLI debug logs",
DebugLogsNotFound: "Debug logs not found",

// version
CmdHelpVersion: "the version command.",
CmdDescVersion: "Shows the current zCLI version.",
CmdDescVersion: "Shows the current zCLI version",

// support
CmdHelpSupport: "the support command.",
CmdDescSupport: "How to contact Zerops support for assistance",

// env
CmdHelpEnv: "the support command.",
CmdDescEnv: "Displays global environment variables, their paths and additional options",

// vpn
CmdHelpVpn: "the vpn command.",
Expand Down
14 changes: 14 additions & 0 deletions src/i18n/i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ const (
RegionNotFound = "RegionNotFound"
RegionTableColumnName = "RegionTableColumnName"

// logout
CmdHelpLogout = "CmdHelpLogout"
CmdDescLogout = "CmdDescLogout"
LogoutVpnDisconnecting = "LogoutVpnDisconnecting"
LogoutSuccess = "LogoutSuccess"

// scope
CmdHelpScope = "CmdHelpScope"
CmdDescScope = "CmdDescScope"
Expand Down Expand Up @@ -153,6 +159,14 @@ const (
CmdHelpVersion = "CmdHelpVersion"
CmdDescVersion = "CmdDescVersion"

// support
CmdHelpSupport = "CmdHelpSupport"
CmdDescSupport = "CmdDescSupport"

// support
CmdHelpEnv = "CmdHelpEnv"
CmdDescEnv = "CmdDescEnv"

// vpn
CmdHelpVpn = "CmdHelpVpn"
CmdDescVpn = "CmdDescVpn"
Expand Down
Loading

0 comments on commit b08022b

Please sign in to comment.