help/README.md
2025-04-22 19:27:36 +03:00

44 lines
No EOL
1.1 KiB
Markdown

### The "Help" package
This package provides --help flag feature to your cli.
It recognize both short and long flags.
-------------
### Usage
1. Download the package by **go get** command:
```shell
go get code.foilhatguy.casa/pub/help
```
2. Add the package as a tool dependency to your project in
tools.go:
```go
// +build tools
package tools
import (
_ "code.foilhatguy.casa/pub/help"
)
```
3. In the main package add a go:generate directive:
```go
//go:generate go run code.foilhatguy.casa/pub/help HELP.md
```
The last part in this directive is a name of help file for
your application. It should be placed in the root directory
of your project along with **main.go** file. The help file
can be written ether in the MarkDown format, or in plain text.
MarkDown will be automatically converted in to plain text,
which is suitable for the console output.
4. Run code generator by **go generate** command:
```shell
go generate ./...
```
The package will generate a **help.go** file as a part of
the main package. It will contain code for --help flag detection.
5. Build and run your application with the --help flag.
```shell
go run . --help
```