From 805a26090f6a2eba7c70209adbb4166370bc67fe Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Thu, 27 Aug 2020 18:07:22 -0400 Subject: [PATCH] Format help and add examples to stash command --- formatting.go | 15 +++++++++++++++ main.go | 2 ++ stash_cmd.go | 14 ++++++++------ 3 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 formatting.go diff --git a/formatting.go b/formatting.go new file mode 100644 index 0000000..6e3dffa --- /dev/null +++ b/formatting.go @@ -0,0 +1,15 @@ +package main + +import ( + "github.com/muesli/reflow/indent" + "github.com/muesli/reflow/wordwrap" +) + +const ( + wrapAt = 78 + indentAmount = 2 +) + +func formatBlock(s string) string { + return indent.String(wordwrap.String(s, wrapAt-indentAmount), indentAmount) +} diff --git a/main.go b/main.go index b0bf5e5..8774a71 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,7 @@ import ( "golang.org/x/crypto/ssh/terminal" tea "github.com/charmbracelet/bubbletea" + "github.com/charmbracelet/charm/ui/common" "github.com/charmbracelet/glamour" "github.com/charmbracelet/glow/ui" ) @@ -33,6 +34,7 @@ var ( rootCmd = &cobra.Command{ Use: "glow SOURCE", Short: "Render markdown on the CLI, with pizzazz!", + Long: formatBlock(fmt.Sprintf("\nRender markdown on the CLI, %s!", common.Keyword("with pizzazz"))), SilenceErrors: false, SilenceUsage: false, TraverseChildren: true, diff --git a/stash_cmd.go b/stash_cmd.go index addf5cb..43ab6c2 100644 --- a/stash_cmd.go +++ b/stash_cmd.go @@ -23,11 +23,12 @@ var ( memo string stashCmd = &cobra.Command{ - Use: "stash SOURCE", - Hidden: false, - Short: "stash a markdown", - Long: "", - Args: cobra.ExactArgs(1), + Use: "stash SOURCE", + Hidden: false, + Short: "stash a markdown", + Long: formatBlock(fmt.Sprintf("\nSave a mardkdown file to your %s.", common.Keyword("stash"))), + Example: formatBlock("glow stash README.md\nglow stash -m \"secret notes\" path/to/notes.md"), + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { filePath := args[0] @@ -82,7 +83,8 @@ func initCharmClient() *charm.Client { cfg := getCharmConfig() cc, err := charm.NewClient(cfg) if err == charm.ErrMissingSSHAuth { - log.Fatal("Missing ssh key. Run `ssh-keygen` to make one or set the `CHARM_SSH_KEY_PATH` env var to your private key path.") + fmt.Println(formatBlock("We had some trouble authenticating via SSH. If this continues to happen the Charm tool may be able to help you. More info at https://github.com/charmbracelet/charm.")) + os.Exit(1) } else if err != nil { fmt.Println(err) os.Exit(1)