Skip to content

Commit

Permalink
Add better quickstart and fancy gifs (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
FollowTheProcess authored Aug 4, 2024
1 parent e359385 commit cb9d74b
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 28 deletions.
44 changes: 23 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,15 @@

Tiny, simple, but powerful CLI framework for modern Go 🚀

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

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

- [CLI](#cli)
- [Project Description](#project-description)
- [Core Principles](#core-principles)
- [😱 Well behaved libraries don't panic](#-well-behaved-libraries-dont-panic)
- [🧘🏻 Keep it Simple](#-keep-it-simple)
- [👨🏻‍🔬 Use Modern Techniques](#-use-modern-techniques)
- [🥹 A Beautiful API](#-a-beautiful-api)
- [🔐 Immutable State](#-immutable-state)
- [🚧 Good Libraries are Hard to Misuse](#-good-libraries-are-hard-to-misuse)
- [Installation](#installation)
- [Quickstart](#quickstart)
- [Credits](#credits)

## 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.
Expand Down Expand Up @@ -149,11 +140,17 @@ func main() {
}

func run() error {
var count int
cmd, err := cli.New(
"quickstart",
cli.Allow(cli.AnyArgs()),
cli.Short("quick demo CLI to show the library"),
cli.Run(runQuickstart),
"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
Expand All @@ -162,13 +159,18 @@ func run() error {
return cmd.Execute()
}

func runQuickstart(cmd *cli.Command, args []string) error {
fmt.Fprintln(cmd.Stdout(), "Hello from quickstart!")
return nil
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
22 changes: 15 additions & 7 deletions examples/quickstart/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ func main() {
}

func run() error {
var count int
cmd, err := cli.New(
"quickstart",
cli.Allow(cli.AnyArgs()),
cli.Short("quick demo CLI to show the library"),
cli.Run(runQuickstart),
"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
Expand All @@ -28,7 +34,9 @@ func run() error {
return cmd.Execute()
}

func runQuickstart(cmd *cli.Command, args []string) error {
fmt.Fprintln(cmd.Stdout(), "Hello from quickstart!")
return nil
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
}
}
File renamed without changes.
File renamed without changes.
Binary file added img/demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 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.

0 comments on commit cb9d74b

Please sign in to comment.