Skip to content

Commit

Permalink
cmd: color and emoji (#595)
Browse files Browse the repository at this point in the history
* rename `output` to just `out`

* add `decor.go` with print wrappers and colour primitives (see `cmd/core/utils/out/decor.go`)

* prettified a few common commands (notably `init`, `${remote} init`, `remote add`, etc.)

Closes #147
  • Loading branch information
bobheadxi authored Mar 2, 2019
1 parent 6fb9e48 commit 275f47b
Show file tree
Hide file tree
Showing 71 changed files with 757 additions and 354 deletions.
56 changes: 42 additions & 14 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 51 additions & 19 deletions client/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"fmt"
"io"

"github.com/fatih/color"
"github.com/kyokomi/emoji"

"github.com/ubclaunchpad/inertia/client"
"github.com/ubclaunchpad/inertia/common"
)
Expand All @@ -12,12 +15,29 @@ import (
// RepoName is optional, and only used for generating printed links.
// Out is where output will be written.
type Options struct {
RepoName string
Out io.Writer
RepoName string
DisableColor bool
DisableEmoji bool
Out io.Writer
}

// Bootstrap bootstraps the given remote
func Bootstrap(c *client.Client, opts Options) error {
// The bootstrap script is a bit of an outlier, as it is separated from cmd/...
// but it does a lot of printing. we use emoji and color directly in this
// script to avoid introducing a direct dependency on cmd/...
color.Output = opts.Out
var highlight = color.New(color.FgYellow, color.Bold)
var blue = color.New(color.FgBlue, color.Bold)
if opts.DisableColor {
highlight.DisableColor()
blue.DisableColor()
}
var fprintf = emoji.Fprintf
if opts.DisableEmoji {
fprintf = fmt.Fprintf
}

var out = opts.Out
if out == nil {
out = &common.DevNull{}
Expand All @@ -27,26 +47,30 @@ func Bootstrap(c *client.Client, opts Options) error {
return err
}

fmt.Fprintf(out, "Setting up remote at %s\n", c.Remote.IP)
fmt.Fprint(out, ">> Step 1/4: Installing docker...\n")
fprintf(out, "Setting up remote '%s' at %s\n", c.Remote.Name, c.Remote.IP)
emoji.Fprint(out, ":whale: ")
blue.Fprint(out, "Step 1/4: Installing docker...\n")
if err := sshc.InstallDocker(); err != nil {
return err
}

fmt.Fprint(out, ">> Step 2/4: Building deploy key...\n")
emoji.Fprint(out, ":hammer_and_wrench: ")
blue.Fprint(out, "Step 2/4: Building deploy key...\n")
pub, err := sshc.GenerateKeys()
if err != nil {
return err
}

// This step needs to run before any other commands that rely on
// the daemon image, since the daemon is loaded here.
fmt.Fprint(out, ">> Step 3/4: Starting daemon...\n")
emoji.Fprint(out, ":robot: ")
blue.Fprint(out, "Step 3/4: Starting daemon...\n")
if err = sshc.DaemonUp(); err != nil {
return err
}

fmt.Fprint(out, ">> Step 4/4: Fetching daemon API token...\n")
emoji.Fprint(out, ":lock: ")
blue.Fprint(out, "Step 4/4: Fetching daemon API token...\n")
if err := sshc.AssignAPIToken(); err != nil {
return err
}
Expand All @@ -58,28 +82,36 @@ Use 'inertia %s logs' to check on the daemon's setup progress.
`, c.Remote.Name)

// pretty divider
fmt.Fprint(out, "=============================\n\n")
fmt.Fprint(out, "\n==========================================================\n\n")

// Output deploy key to user
fmt.Fprintf(out, ">> GitHub Deploy Key (add to https://www.github.com/%s/settings/keys/new):\n",
c.Remote.Name)
fprintf(out, ":star: ")
highlight.Fprintf(out,
"GitHub Deploy Key (add to https://www.github.com/%s/settings/keys/new):\n",
opts.RepoName)
fmt.Fprint(out, pub+"\n")

// Output Webhook url to user
var addr, _ = c.Remote.DaemonAddr()
fmt.Fprintf(out, `
>> GitHub WebHook URL (add to https://www.github.com/%s/settings/hooks/new):
Address: https://%s/webhook
Secret: %s
fprintf(out, ":star: ")
highlight.Fprintf(out,
"GitHub WebHook URL (add to https://www.github.com/%s/settings/hooks/new)\n",
opts.RepoName)
fprintf(out, `:globe_with_meridians: Address: %s/webhook
:key: Secret: %s
Note that by default, you will have to disable SSL verification in your webhook
settings - Inertia uses self-signed certificates that GitHub won't be able to
verify.`, opts.RepoName, addr, c.Remote.Daemon.WebHookSecret)
verify. Read more about it here: https://inertia.ubclaunchpad.com/#custom-ssl-certificate
`, addr, c.Remote.Daemon.WebHookSecret)

// pretty divider
fmt.Fprint(out, "\n==========================================================\n")

fmt.Fprintf(out, `
Inertia daemon successfully deployed! Add your webhook url and deploy key to
your repository to enable continuous deployment.
fprintf(out, `
Your Inertia daemon has been successfully deployed! Add your webhook url and
deploy key to your repository to enable continuous deployment. :rocket:
Then run 'inertia %s up' to deploy your application.
Then run 'inertia %s up' to deploy your application!
`, c.Remote.Name)
return nil
}
6 changes: 3 additions & 3 deletions cmd/contrib.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/spf13/cobra"
"github.com/ubclaunchpad/inertia/cmd/core"
"github.com/ubclaunchpad/inertia/cmd/core/utils/output"
"github.com/ubclaunchpad/inertia/cmd/core/utils/out"
)

func attachContribPlugins(inertia *core.Cmd) {
Expand Down Expand Up @@ -44,7 +44,7 @@ Use $INERTIA_PLUGINSPATH to configure where Inertia should look for plugins.`,

// check if plugin is installed
if _, err := os.Stat(tool); os.IsNotExist(err) {
output.Fatalf("could not find plugin '%s' - please make sure it is installed",
out.Fatalf("could not find plugin '%s' - please make sure it is installed",
tool)
}

Expand All @@ -53,7 +53,7 @@ Use $INERTIA_PLUGINSPATH to configure where Inertia should look for plugins.`,
plugin.Stdout = os.Stdout
plugin.Stdin = os.Stdin
if err := plugin.Run(); err != nil {
output.Fatal(err.Error())
out.Fatal(err.Error())
}
},
}
Expand Down
Loading

0 comments on commit 275f47b

Please sign in to comment.