Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/superpaintman/nice

Highly customizable and idiomatic Go CLI app framework 👌
https://github.com/superpaintman/nice

cli command-line commandline framework go golang golang-library nice

Last synced: about 2 months ago
JSON representation

Highly customizable and idiomatic Go CLI app framework 👌

Awesome Lists containing this project

README

        

# Nice 👌

**Nice** is a highly customizable and lightweight framework for crafting CLI
apps.

Nice respects idiomatic [Go](https://golang.org/) code and focuses to be clear,
efficient and easy to write and maintain.

You can use it as a full-featured non-opinionated framework or use any nice
packages as stand-alone libraries.

I hope you'll enjoy your nice CLI app!

![Banner](./assets/banner.png)

---

## Table of Contents

- [Hello, Nice!](#hello-nice)
- [Examples](#examples)
- [Packages](#packages)
- [🖥️ nice/cli](#package-nice-cli)
- [🖌️ nice/colors](#package-nice-colors)

---

## Hello, Nice!

Let's start with your first Nice CLI app.

First, install the framework:

```sh
$ go get github.com/SuperPaintman/nice/cli
```

Then put this code into a file (`hello.go` for example):

```go
package main

import "github.com/SuperPaintman/nice/cli"

func main() {
app := cli.App{
Name: "hello",
Usage: cli.Usage("Print a friendly greeting"),
Action: cli.ActionFunc(func(cmd *cli.Command) cli.ActionRunner {
name := cli.StringArg(cmd, "name",
cli.Usage("Who we say hello to"),
cli.Optional,
)
*name = "Nice" // Default value.

return func(cmd *cli.Command) error {
cmd.Printf("Hello, %s!\n", *name)

return nil
}
}),
CommandFlags: []cli.CommandFlag{
cli.HelpCommandFlag(),
cli.VersionCommandFlag("0.0.0"),
},
}

app.HandleError(app.Run())
}
```

Now you can run it!

```sh
$ go run . world
```

Or print the help for your app:

```sh
$ go run . -h
```

![Help example](./assets/help.png)

---

## Examples

You can find [more examples in the `./examples` directory](./examples).

---

## Packages

🖥️ `github.com/SuperPaintman/nice/cli`

[Documentation](https://pkg.go.dev/github.com/SuperPaintman/nice/cli) • [Source](./cli)

```go
import "github.com/SuperPaintman/nice/cli"
```

🖌️ `github.com/SuperPaintman/nice/colors`

[Documentation](https://pkg.go.dev/github.com/SuperPaintman/nice/colors) • [Source](./colors)

```go
import "github.com/SuperPaintman/nice/colors"
```

---

## Tests

```sh
$ go test -race ./...
```

```sh
$ go test ./... -bench=. -benchmem -run='^Benckmark'
```

---

## Similar projects

- [flag](https://pkg.go.dev/flag) Go
- [github.com/spf13/cobra](https://github.com/spf13/cobra) Go
- [github.com/urfave/cli](https://github.com/urfave/cli) Go
- [github.com/fatih/color](https://github.com/fatih/color) Go
- [github.com/c-bata/go-prompt](https://github.com/c-bata/go-prompt) Go
- [github.com/muesli/termenv](https://github.com/muesli/termenv) Go
- [github.com/alecthomas/kingpin](https://github.com/alecthomas/kingpin) Go
- [npmjs.com/package/ervy](https://www.npmjs.com/package/ervy) JavaScript
- [npmjs.com/package/commander](https://www.npmjs.com/package/commander) JavaScript
- [npmjs.com/package/chalk](https://www.npmjs.com/package/chalk) JavaScript
- [npmjs.com/package/inquirer](https://www.npmjs.com/package/inquirer) JavaScript
- [npmjs.com/package/prompts](https://www.npmjs.com/package/prompts) JavaScript
- [npmjs.com/package/ora](https://www.npmjs.com/package/ora) JavaScript
- [npmjs.com/package/clui](https://www.npmjs.com/package/clui) JavaScript

---

#### License

[MIT](./LICENSE)

---

With 🫀 by [Aleksandr Krivoshchekov (@SuperPaintman)](https://github.com/SuperPaintman)