Skip to content

Commit

Permalink
Add a vhs produced gif showing the quickstart (#71)
Browse files Browse the repository at this point in the history
* Add a vhs produced gif showing the quickstart

* Add a task to make the gif
  • Loading branch information
FollowTheProcess authored Aug 5, 2024
1 parent 2bff85d commit 23f5ae3
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 66 deletions.
122 changes: 60 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,75 @@
Tiny, simple, but powerful CLI framework for modern Go 🚀

<p align="center">
<img src="./img/demo.png" alt="demo">
<img src="./docs/img/demo.png" alt="demo">
</p>

> [!WARNING]
> **CLI is in early development and is not yet ready for use**
![caution](img/caution.png)

## Project Description

`cli` is a simple, minimalist, yet functional and powerful CLI framework for Go. Inspired by things like [spf13/cobra] and [urfave/cli], but building on lessons learned and using modern Go techniques and idioms.

## Installation

```shell
go get github.com/FollowTheProcess/cli@latest
```

## Quickstart

```go
package main

import (
"fmt"
"os"

"github.com/FollowTheProcess/cli"
)

func main() {
if err := run(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
}

func run() error {
var count int
cmd, err := cli.New(
"quickstart",
cli.Short("Short description of your command"),
cli.Long("Much longer text..."),
cli.Version("v1.2.3"),
cli.Allow(cli.MinArgs(1)), // Must have at least one argument
cli.Stdout(os.Stdout),
cli.Example("Do a thing", "quickstart something"),
cli.Example("Count the things", "quickstart something --count 3"),
cli.Flag(&count, "count", 'c', 0, "Count the things"),
cli.Run(runQuickstart(&count)),
)
if err != nil {
return err
}

return cmd.Execute()
}

func runQuickstart(count *int) func(cmd *cli.Command, args []string) error {
return func(cmd *cli.Command, args []string) error {
fmt.Fprintf(cmd.Stdout(), "Hello from quickstart!, my args were: %v, count was %d\n", args, *count)
return nil
}
}

```

Will get you the following:

![quickstart](./docs/img/quickstart.gif)

### Core Principles

#### 😱 Well behaved libraries don't panic
Expand Down Expand Up @@ -112,65 +169,6 @@ var delete bool
cli.New("demo", cli.Flag(&delete, "delete", cli.NoShortHand, false, "Delete something"))
```

## Installation

Convinced? I hope so...

```shell
go get github.com/FollowTheProcess/cli@latest
```

## Quickstart

```go
package main

import (
"fmt"
"os"

"github.com/FollowTheProcess/cli"
)

func main() {
if err := run(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
}

func run() error {
var count int
cmd, err := cli.New(
"demo",
cli.Short("Short description of your command"),
cli.Long("Much longer text..."),
cli.Version("v1.2.3"),
cli.Allow(cli.MinArgs(1)), // Must have at least one argument
cli.Stdout(os.Stdout),
cli.Example("Do a thing", "test run thing --now"),
cli.Flag(&count, "count", 'c', 0, "Count the things"),
cli.Run(runQuickstart(&count)),
)
if err != nil {
return err
}

return cmd.Execute()
}

func runQuickstart(count *int) func(cmd *cli.Command, args []string) error {
return func(cmd *cli.Command, args []string) error {
fmt.Fprintf(cmd.Stdout(), "Hello from quickstart!, count was %d\n", *count)
return nil
}
}
```

Will get you the following:

![quickstart](./img/quickstart.gif)

### Credits

This package was created with [copier] and the [FollowTheProcess/go_copier] project template.
Expand Down
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Things I want to do to make this library as good as it can be and a better, simp
- [x] Thin wrapper around tabwriter to keep it consistent
- [ ] Try this on some of my CLI tools to work out the bugs in real world programs
- [ ] Test that shuffles the order of options and ensures the command we get is the same every time
- [ ] Use [vhs] to make a nice demo gif
- [x] Use [vhs] to make a nice demo gif

## Ideas

Expand Down
10 changes: 10 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ tasks:
- sh: command -v pkgsite
msg: pkgsite not installed, run go install golang.org/x/pkgsite/cmd/pkgsite@latest

demo:
desc: Render the demo gifs
sources:
- ./docs/src/*.tape
preconditions:
- sh: command -v vhs
msg: vhs not installed, see https://github.com/charmbracelet/vhs
cmds:
- vhs ./docs/src/quickstart.tape

cov:
desc: Calculate test coverage and render the html
cmds:
Expand Down
File renamed without changes
Binary file added docs/img/quickstart.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
101 changes: 101 additions & 0 deletions docs/src/quickstart.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# VHS documentation
#
# Output:
# Output <path>.gif Create a GIF output at the given <path>
# Output <path>.mp4 Create an MP4 output at the given <path>
# Output <path>.webm Create a WebM output at the given <path>
#
# Require:
# Require <string> Ensure a program is on the $PATH to proceed
#
# Settings:
# Set FontSize <number> Set the font size of the terminal
# Set FontFamily <string> Set the font family of the terminal
# Set Height <number> Set the height of the terminal
# Set Width <number> Set the width of the terminal
# Set LetterSpacing <float> Set the font letter spacing (tracking)
# Set LineHeight <float> Set the font line height
# Set LoopOffset <float>% Set the starting frame offset for the GIF loop
# Set Theme <json|string> Set the theme of the terminal
# Set Padding <number> Set the padding of the terminal
# Set Framerate <number> Set the framerate of the recording
# Set PlaybackSpeed <float> Set the playback speed of the recording
# Set MarginFill <file|#000000> Set the file or color the margin will be filled with.
# Set Margin <number> Set the size of the margin. Has no effect if MarginFill isn't set.
# Set BorderRadius <number> Set terminal border radius, in pixels.
# Set WindowBar <string> Set window bar type. (one of: Rings, RingsRight, Colorful, ColorfulRight)
# Set WindowBarSize <number> Set window bar size, in pixels. Default is 40.
# Set TypingSpeed <time> Set the typing speed of the terminal. Default is 50ms.
#
# Sleep:
# Sleep <time> Sleep for a set amount of <time> in seconds
#
# Type:
# Type[@<time>] "<characters>" Type <characters> into the terminal with a
# <time> delay between each character
#
# Keys:
# Escape[@<time>] [number] Press the Escape key
# Backspace[@<time>] [number] Press the Backspace key
# Delete[@<time>] [number] Press the Delete key
# Insert[@<time>] [number] Press the Insert key
# Down[@<time>] [number] Press the Down key
# Enter[@<time>] [number] Press the Enter key
# Space[@<time>] [number] Press the Space key
# Tab[@<time>] [number] Press the Tab key
# Left[@<time>] [number] Press the Left Arrow key
# Right[@<time>] [number] Press the Right Arrow key
# Up[@<time>] [number] Press the Up Arrow key
# Down[@<time>] [number] Press the Down Arrow key
# PageUp[@<time>] [number] Press the Page Up key
# PageDown[@<time>] [number] Press the Page Down key
# Ctrl+<key> Press the Control key + <key> (e.g. Ctrl+C)
#
# Display:
# Hide Hide the subsequent commands from the output
# Show Show the subsequent commands in the output

# Run from the repo root
Output ./docs/img/quickstart.gif

Set Shell fish
Set FontSize 18
Set FontFamily "SFMono Nerd Font"
Set Theme "Catppuccin Mocha"
Set WindowBar Colorful
Set Padding 5
Set Height 800
Set Width 1200
Set Margin 40
Set MarginFill "#7983FF"
Set BorderRadius 10
Set TypingSpeed 100ms

# Setup
Hide
Type "go build -o ./quickstart ./examples/quickstart && clear" Sleep 2s
Enter
Sleep 2s
Show
Sleep 1s

Type "./quickstart --help" Sleep 500ms Enter

Sleep 2s

Type "./quickstart --version" Sleep 500ms Enter

Sleep 2s

Type "./quickstart something --count 3" Sleep 500ms Enter

Sleep 2s

Type "./quickstart" Sleep 500ms Enter

Sleep 4s

# Cleanup
Hide
Type "rm -f ./quickstart"
Enter
7 changes: 4 additions & 3 deletions examples/quickstart/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ func main() {
func run() error {
var count int
cmd, err := cli.New(
"demo",
"quickstart",
cli.Short("Short description of your command"),
cli.Long("Much longer text..."),
cli.Version("v1.2.3"),
cli.Allow(cli.MinArgs(1)), // Must have at least one argument
cli.Stdout(os.Stdout),
cli.Example("Do a thing", "test run thing --now"),
cli.Example("Do a thing", "quickstart something"),
cli.Example("Count the things", "quickstart something --count 3"),
cli.Flag(&count, "count", 'c', 0, "Count the things"),
cli.Run(runQuickstart(&count)),
)
Expand All @@ -36,7 +37,7 @@ func run() error {

func runQuickstart(count *int) func(cmd *cli.Command, args []string) error {
return func(cmd *cli.Command, args []string) error {
fmt.Fprintf(cmd.Stdout(), "Hello from quickstart!, count was %d\n", *count)
fmt.Fprintf(cmd.Stdout(), "Hello from quickstart!, my args were: %v, count was %d\n", args, *count)
return nil
}
}
Binary file removed img/caution.png
Binary file not shown.
Binary file removed img/quickstart.gif
Binary file not shown.

0 comments on commit 23f5ae3

Please sign in to comment.