Skip to content

Commit

Permalink
Replace emoji with jest-style colors (#57)
Browse files Browse the repository at this point in the history
* Replace emoji with jest-style colors

I've experimented with some true-console experience
and tried to implement some jest-like badges.
That's not so distracting as more or less fits into
terminal color palette and resolution. I would say it
also feels a bit more like a professional tool, but that's for sure IMO only.

Just take a look and please tell me WDYT?

* rm emoji from tests

* remove bold which breaks the color

Co-authored-by: Sebastien Le Digabel <sledigabel@gmail.com>
  • Loading branch information
lanwen and sledigabel committed Jun 18, 2021
1 parent d219a92 commit 2a449f5
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 31 deletions.
10 changes: 6 additions & 4 deletions cmd/clone/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@ func run(c *cobra.Command, _ []string) {
}

if errorCount == 0 {
logger.Successf("turbolift clone completed (%d repos cloned, %d repos skipped)\n", doneCount, skippedCount)
logger.Successf("turbolift clone completed %s(%s repos cloned, %s repos skipped)\n", colors.Normal(), colors.Green(doneCount), colors.Yellow(skippedCount))
} else {
logger.Warnf("turbolift clone completed with errors (%d repos cloned, %d repos skipped, %d repos errored)\n", doneCount, skippedCount, errorCount)
logger.Warnf("turbolift clone completed with %s %s(%s repos cloned, %s repos skipped, %s repos errored)\n", colors.Red("errors"), colors.Normal(), colors.Green(doneCount), colors.Yellow(skippedCount), colors.Red(errorCount))
logger.Println("Please check errors above and fix if necessary")
}
logger.Println("To continue:")
logger.Println("1. Make your changes in the cloned repositories within the", colors.Cyan("work"), "directory")
logger.Println("2. Commit changes across all repos using", colors.Cyan("turbolift commit --message \"Your commit message\""))
logger.Println("\t1. Make your changes in the cloned repositories within the", colors.Cyan("work"), "directory")
logger.Println("\t2. Add new files across all repos using", colors.Cyan(`turbolift foreach -- git add -A`))
logger.Println("\t3. Commit changes across all repos using", colors.Cyan(`turbolift commit --message "Your commit message"`))
logger.Println("\t4. Change the PR title and description in the", colors.Cyan(`README.md`), "of a campaign")
}
10 changes: 5 additions & 5 deletions cmd/clone/clone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestItAbortsIfReposFileNotFound(t *testing.T) {

out, err := runCommand()
assert.NoError(t, err)
assert.Contains(t, out, "Reading campaign data")
assert.Contains(t, out, "Reading campaign data")

fakeGitHub.AssertCalledWith(t, [][]string{})
fakeGit.AssertCalledWith(t, [][]string{})
Expand All @@ -56,8 +56,8 @@ func TestItLogsCloneErrorsButContinuesToTryAll(t *testing.T) {

out, err := runCommand()
assert.NoError(t, err)
assert.Contains(t, out, "Forking and cloning org/repo1")
assert.Contains(t, out, "Forking and cloning org/repo2")
assert.Contains(t, out, "Forking and cloning org/repo1")
assert.Contains(t, out, "Forking and cloning org/repo2")
assert.Contains(t, out, "turbolift clone completed with errors")
assert.Contains(t, out, "2 repos errored")

Expand All @@ -78,7 +78,7 @@ func TestItLogsCheckoutErrorsButContinuesToTryAll(t *testing.T) {

out, err := runCommand()
assert.NoError(t, err)
assert.Contains(t, out, "Creating branch")
assert.Contains(t, out, "Creating branch")
assert.Contains(t, out, "turbolift clone completed with errors")
assert.Contains(t, out, "2 repos errored")

Expand Down Expand Up @@ -169,7 +169,7 @@ func TestItSkipsCloningIfAWorkingCopyAlreadyExists(t *testing.T) {

out, err := runCommand()
assert.NoError(t, err)
assert.Contains(t, out, "⚠️ Forking and cloning org/repo1")
assert.Contains(t, out, "Forking and cloning org/repo1")

fakeGitHub.AssertCalledWith(t, [][]string{
{"work/org", "org/repo2"},
Expand Down
5 changes: 3 additions & 2 deletions cmd/commit/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package commit

import (
"github.com/skyscanner/turbolift/internal/campaign"
"github.com/skyscanner/turbolift/internal/colors"
"github.com/skyscanner/turbolift/internal/git"
"github.com/skyscanner/turbolift/internal/logging"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -94,8 +95,8 @@ func run(c *cobra.Command, _ []string) {
}

if errorCount == 0 {
logger.Successf("turbolift commit completed (%d OK, %d skipped)\n", doneCount, skippedCount)
logger.Successf("turbolift commit completed %s(%s, %s)\n", colors.Normal(), colors.Green(doneCount, " OK"), colors.Yellow(skippedCount, " skipped"))
} else {
logger.Warnf("turbolift commit completed with errors (%d OK, %d skipped, %d errored)\n", doneCount, skippedCount, errorCount)
logger.Warnf("turbolift commit completed with %s %s(%s, %s, %s)\n", colors.Red("errors"), colors.Normal(), colors.Green(doneCount, " OK"), colors.Yellow(skippedCount, " skipped"), colors.Red(errorCount, " errored"))
}
}
4 changes: 2 additions & 2 deletions cmd/commit/commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestItSkipsReposWithoutChanges(t *testing.T) {

out, err := runCommand("some test message", []string{}...)
assert.NoError(t, err)
assert.Contains(t, out, "⚠️ Committing changes in org/repo1: No changes - skipping commit")
assert.Contains(t, out, "Committing changes in org/repo1: No changes - skipping commit")
assert.Contains(t, out, "1 OK, 1 skipped")

fakeGit.AssertCalledWith(t, [][]string{
Expand All @@ -82,7 +82,7 @@ func TestItSkipsReposWhichErrorOnStatusChekc(t *testing.T) {

out, err := runCommand("some test message", []string{}...)
assert.NoError(t, err)
assert.Contains(t, out, "Committing changes in org/repo1")
assert.Contains(t, out, "Committing changes in org/repo1")
assert.Contains(t, out, "1 OK, 0 skipped, 1 errored")

fakeGit.AssertCalledWith(t, [][]string{
Expand Down
5 changes: 3 additions & 2 deletions cmd/create_prs/create_prs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package create_prs

import (
"github.com/skyscanner/turbolift/internal/campaign"
"github.com/skyscanner/turbolift/internal/colors"
"github.com/skyscanner/turbolift/internal/git"
"github.com/skyscanner/turbolift/internal/github"
"github.com/skyscanner/turbolift/internal/logging"
Expand Down Expand Up @@ -103,8 +104,8 @@ func run(c *cobra.Command, _ []string) {
}

if errorCount == 0 {
logger.Successf("turbolift create-prs completed (%d OK, %d skipped)\n", doneCount, skippedCount)
logger.Successf("turbolift create-prs completed %s(%s, %s)\n", colors.Normal(), colors.Green(doneCount, " OK"), colors.Yellow(skippedCount, " skipped"))
} else {
logger.Warnf("turbolift create-prs completed with errors (%d OK, %d skipped, %d errored)\n", doneCount, skippedCount, errorCount)
logger.Warnf("turbolift create-prs completed with %s %s(%s, %s, %s)\n", colors.Red("errors"), colors.Normal(), colors.Green(doneCount, " OK"), colors.Yellow(skippedCount, " skipped"), colors.Red(errorCount, " errored"))
}
}
4 changes: 2 additions & 2 deletions cmd/create_prs/create_prs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func TestItLogsCreatePrErrorsButContinuesToTryAll(t *testing.T) {

out, err := runCommand()
assert.NoError(t, err)
assert.Contains(t, out, "Creating PR in org/repo1")
assert.Contains(t, out, "Creating PR in org/repo2")
assert.Contains(t, out, "Creating PR in org/repo1")
assert.Contains(t, out, "Creating PR in org/repo2")
assert.Contains(t, out, "turbolift create-prs completed with errors")
assert.Contains(t, out, "2 errored")

Expand Down
5 changes: 3 additions & 2 deletions cmd/foreach/foreach.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package foreach

import (
"github.com/skyscanner/turbolift/internal/campaign"
"github.com/skyscanner/turbolift/internal/colors"
"github.com/skyscanner/turbolift/internal/executor"
"github.com/skyscanner/turbolift/internal/logging"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -81,8 +82,8 @@ func run(c *cobra.Command, args []string) {
}

if errorCount == 0 {
logger.Successf("turbolift foreach completed (%d OK, %d skipped)\n", doneCount, skippedCount)
logger.Successf("turbolift foreach completed %s(%s, %s)\n", colors.Normal(), colors.Green(doneCount, " OK"), colors.Yellow(skippedCount, " skipped"))
} else {
logger.Warnf("turbolift foreach completed with errors (%d OK, %d skipped, %d errored)\n", doneCount, skippedCount, errorCount)
logger.Warnf("turbolift foreach completed with %s %s(%s, %s, %s)\n", colors.Red("errors"), colors.Normal(), colors.Green(doneCount, " OK"), colors.Yellow(skippedCount, " skipped"), colors.Red(errorCount, " errored"))
}
}
6 changes: 3 additions & 3 deletions cmd/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ func run(c *cobra.Command, _ []string) {
createFilesActivity.EndWithSuccess()

logger.Successf("turbolift init is done - next:\n")
logger.Println("1. Run", colors.Cyan("cd ", campaignName))
logger.Println("2. Update repos.txt with the names of the repos that need changing (either manually or using a tool to generate a list of repos)")
logger.Println("3. Run", colors.Cyan("turbolift clone"))
logger.Println("\t1. Run", colors.Cyan("cd ", campaignName))
logger.Println("\t2. Update", colors.Cyan("repos.txt"), "with the names of the repos that need changing (either manually or using a tool to generate a list of repos)")
logger.Println("\t3. Run", colors.Cyan("turbolift clone"))
}

// Applies a given template and data to produce a file with the outputFilename
Expand Down
5 changes: 5 additions & 0 deletions internal/colors/colors.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ var Cyan = color.New(color.FgCyan).SprintFunc()
var White = color.New(color.FgWhite).SprintFunc()
var Red = color.New(color.FgRed).SprintFunc()
var Yellow = color.New(color.FgYellow).SprintFunc()

var Normal = color.New(color.Reset).SprintFunc()
var Pass = color.New(color.BgGreen, color.FgBlack).SprintFunc()
var Warn = color.New(color.BgYellow, color.FgBlack).SprintFunc()
var Fail = color.New(color.BgRed, color.FgBlack).SprintFunc()
2 changes: 1 addition & 1 deletion internal/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (e *RealExecutor) Execute(output io.Writer, workingDir string, name string,
tailer(output)(command.StdoutPipe())
tailer(output)(command.StderrPipe())

_, err := fmt.Fprintln(output, "Executing:", name, summarizedArgs(args))
_, err := fmt.Fprintln(output, "Executing:", name, summarizedArgs(args), "in", workingDir)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions internal/logging/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (a *Activity) emitLogs(colourTransform func(...interface{}) string) {
}

func (a *Activity) EndWithSuccess() {
a.spinner.FinalMSG = fmt.Sprintf(" %s", a.name)
a.spinner.FinalMSG = fmt.Sprintf("%s %s", colors.Pass(" OK "), a.name)
a.spinner.Stop()
_, _ = fmt.Fprintln(a.writer)

Expand All @@ -62,15 +62,15 @@ func (a *Activity) EndWithSuccess() {
}

func (a *Activity) EndWithSuccessAndEmitLogs() {
a.spinner.FinalMSG = fmt.Sprintf(" %s", a.name)
a.spinner.FinalMSG = fmt.Sprintf("%s %s", colors.Pass(" OK "), a.name)
a.spinner.Stop()
_, _ = fmt.Fprintln(a.writer)

a.emitLogs(colors.White)
}

func (a *Activity) EndWithWarning(message interface{}) {
a.spinner.FinalMSG = fmt.Sprintf(colors.Yellow("⚠️ %s: %s"), a.name, message)
a.spinner.FinalMSG = fmt.Sprintf(colors.Warn(" WARN ")+colors.Yellow(" %s: %s"), a.name, message)
a.spinner.Stop()
_, _ = fmt.Fprintln(a.writer)

Expand All @@ -82,7 +82,7 @@ func (a *Activity) EndWithWarningf(format string, args ...interface{}) {
}

func (a *Activity) EndWithFailure(message interface{}) {
a.spinner.FinalMSG = fmt.Sprintf(colors.Red(" %s: %s"), a.name, message)
a.spinner.FinalMSG = fmt.Sprintf(colors.Fail(" FAIL ")+colors.Red(" %s: %s"), a.name, message)
a.spinner.Stop()
_, _ = fmt.Fprintln(a.writer)

Expand Down
8 changes: 4 additions & 4 deletions internal/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ func (log *Logger) Println(s ...interface{}) {
}

func (log *Logger) Successf(format string, args ...interface{}) {
prefixedFormat := fmt.Sprintf("✅ %s", format)
log.Printf(colors.Green(prefixedFormat), args...)
prefixedFormat := fmt.Sprint(colors.Pass(" OK "), " ", colors.Green(format))
log.Printf(prefixedFormat, args...)
}

func (log *Logger) Warnf(format string, args ...interface{}) {
prefixedFormat := fmt.Sprintf("⚠️ %s", format)
log.Printf(colors.Yellow(prefixedFormat), args...)
prefixedFormat := fmt.Sprint(colors.Warn(" WARN "), " ", colors.Yellow(format))
log.Printf(prefixedFormat, args...)
}

// StartActivity creates and starts an *Activity with an associated spinner.
Expand Down

0 comments on commit 2a449f5

Please sign in to comment.