Skip to content

Commit

Permalink
cleanup: Goodbye marmot! Hello banners!
Browse files Browse the repository at this point in the history
Given feedback, this removes the marmot. While it was cute, it was very
distracting!

Instead, this adds banners that now match with the table width. It also also
cleans up the output a little.
  • Loading branch information
JAORMX committed Oct 4, 2023
1 parent f82c0ba commit 145b226
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 63 deletions.
24 changes: 13 additions & 11 deletions cmd/cli/app/auth/auth_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ will be saved to $XDG_CONFIG_HOME/mediator/credentials.json`,
go func() {
_ = server.ListenAndServe()
}()

// get the OAuth authorization URL
loginUrl := fmt.Sprintf("http://localhost:%v/login", port)

Expand All @@ -146,7 +145,7 @@ will be saved to $XDG_CONFIG_HOME/mediator/credentials.json`,
fmt.Printf("You may login by pasting this URL into your browser: %s", loginUrl)
}

cli.PrintCmd(cmd, "Waiting for token...")
cli.PrintCmd(cmd, "Waiting for token...\n")

// wait for the token to be received
token := <-tokenChan
Expand All @@ -167,33 +166,36 @@ will be saved to $XDG_CONFIG_HOME/mediator/credentials.json`,
util.ExitNicelyOnError(err, "Error fetching user")

if !registered {
cli.PrintCmd(cmd, "First login, registering user.")
cli.PrintCmd(cmd, "First login, registering user...\n")
newUser, err := client.CreateUser(ctx, &pb.CreateUserRequest{})
util.ExitNicelyOnError(err, "Error registering user")

cli.PrintCmd(cmd, cli.CLIMarmot)
cli.PrintCmd(cmd, cli.WelcomeBannerText(
cli.PrintCmd(cmd, cli.SuccessBanner.Render(
"You have been successfully registered. Welcome!"))
cli.PrintCmd(cmd, "\nHere are your details:")
cli.PrintCmd(cmd, cli.WarningBanner.Render(
"Mediator is currently under active development and considered experimental, we therefore provide no data retention or service stability guarantees.",

Check failure on line 176 in cmd/cli/app/auth/auth_login.go

View workflow job for this annotation

GitHub Actions / golangci-lint / Go Lint

line is 154 characters (lll)
))
cli.PrintCmd(cmd, cli.Header.Render("Here are your details:"))

renderNewUser(cmd, newUser)
} else {
cli.PrintCmd(cmd, cli.SuccessBanner.Render(
"You have successfully logged in."))
}

fmt.Printf("You have been successfully logged in. Your access credentials saved to %s\n",
fmt.Printf("Your access credentials saved to %s\n",
filePath)

// shut down the HTTP server
err = server.Shutdown(context.Background())
util.ExitNicelyOnError(err, "Failed to shut down server")

fmt.Println("Authentication successful")
},
}

func renderNewUser(cmd *cobra.Command, newUser *pb.CreateUserResponse) {
columns := []table.Column{
{Title: "Key", Width: 30},
{Title: "Value", Width: 70},
{Title: "Key", Width: cli.KeyValTableWidths.Key},
{Title: "Value", Width: cli.KeyValTableWidths.Value},
}
rows := []table.Row{
{"Organization ID", newUser.OrganizationId},
Expand Down
20 changes: 19 additions & 1 deletion identity/import/stacklok-realm-with-user-and-client.json
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,25 @@
"enabledEventTypes" : [ ],
"adminEventsEnabled" : false,
"adminEventsDetailsEnabled" : false,
"identityProviders" : [ ],
"identityProviders": [
{
"alias": "github",
"internalId": "afb4fd44-b6d7-4cff-a4ff-12735ca09b02",
"providerId": "github",
"enabled": true,
"updateProfileFirstLoginMode": "on",
"trustEmail": false,
"storeToken": false,
"addReadTokenRoleOnCreate": false,
"authenticateByDefault": false,
"linkOnly": false,
"firstBrokerLoginFlowAlias": "first broker login",
"config": {
"clientSecret": "2f0fb624f00c8d2028a9932ea0004bdc17f0d1fe",
"clientId": "147466e592635695492c"
}
}
],
"identityProviderMappers" : [ ],
"components" : {
"org.keycloak.services.clientregistration.policy.ClientRegistrationPolicy" : [ {
Expand Down
37 changes: 0 additions & 37 deletions internal/util/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,43 +29,6 @@ import (
"github.com/spf13/cobra"
)

// CLIMarmot is an ascii-art marmot
var CLIMarmot = `
.
.. ...
... ...
. ......
.. ....
... ...
..
.. ... ..
...-+*==--+- ...
+-.:==-::::+: ...
::-==-::::-+ ...
.=++====:::- ...
:====-::::::. ...
:====-::::::::. .
::----::::::::::: .
:::::::---:::::::-:
.:::-::::=-::------: .
=---+:::-::-===+== ..
.====-::::====-=++.
:=+++:::=++-:----- .
.==-==-::..--::--:::: ..
:------:::.:::---:::: ..
.-------:::::::-----. ..
---===----::::-=--- ..
.-=+=:-::::::=*+=:.. .
.==-::......:.:.....::::::..
.................:::::...........::..
...::......::::::..........::.......:::::::..
.....:::...:::::.........................::::::-::.
.::::......::............................:::.:..:::::::.
.....::...................................::::::.::::::.::::.
...........................................:.::.::.:::::::::::::.
............................................:::....::::::::::::::::.
`

// PrintCmd prints a message using the output defined in the cobra Command
func PrintCmd(cmd *cobra.Command, msg string, args ...interface{}) {
Print(cmd.OutOrStdout(), msg, args...)
Expand Down
42 changes: 28 additions & 14 deletions internal/util/cli/style.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,42 @@ var (
BlackColor = lipgloss.Color("#000000")
)

const (
// DefaultBannerWidth is the default width for a banner
DefaultBannerWidth = 100
)

// Styles
var (
// Header is the style to use for headers
Header = lipgloss.NewStyle().
Bold(true).
Background(AccentColor).
Foreground(WhiteColor).
Foreground(PrimaryColor).
PaddingTop(1).
PaddingBottom(1).
PaddingLeft(4).
PaddingRight(4).
PaddingLeft(1).
PaddingRight(1).
MaxWidth(80)
// WelcomeBanner is the style to use for the welcome banner
WelcomeBanner = lipgloss.NewStyle().
WarningBanner = lipgloss.NewStyle().
Bold(true).
Background(BlackColor).
Foreground(WhiteColor).
BorderForeground(AccentColor).
PaddingTop(2).
PaddingBottom(2).
PaddingLeft(4).
PaddingRight(4).
Width(DefaultBannerWidth)
// SuccessBanner is the style to use for a success banner
SuccessBanner = lipgloss.NewStyle().
Bold(true).
Background(AccentColor).
Foreground(WhiteColor).
PaddingTop(1).
PaddingBottom(1).
PaddingLeft(4).
PaddingRight(4).
Width(70)
Width(DefaultBannerWidth)
// Table is the style to use for tables
Table = lipgloss.NewStyle().
BorderStyle(lipgloss.NormalBorder()).
Expand All @@ -79,14 +93,14 @@ var (
Cell: lipgloss.NewStyle().Padding(0, 1),
Selected: lipgloss.NewStyle(),
}
)

// Utility functions
var (
// HeaderText returns a header with the given text
HeaderText = Header.Render
// WelcomeBannerText returns a welcome banner with the given text
WelcomeBannerText = WelcomeBanner.Render
KeyValTableWidths = struct {
Key int
Value int
}{
Key: 27, // 30 - 3 for padding
Value: 67, // 70 - 3 for padding
}
)

// TableRender renders a table given a table model
Expand Down

0 comments on commit 145b226

Please sign in to comment.