help/README.md

38 lines
804 B
Markdown
Raw Normal View History

2025-04-21 22:47:04 +03:00
### The "Help" package
2025-04-21 21:37:03 +03:00
2025-04-21 22:47:04 +03:00
This package provides --help flag feature to your cli.
It recognize both short and long flags.
2025-04-21 21:37:03 +03:00
-------------
### Usage
1. Download the package by **go get** command:
```shell
2025-04-21 22:47:04 +03:00
go get code.foilhatguy.casa/pub/help
2025-04-21 21:37:03 +03:00
```
2. Add the package as a tool dependency to your project in
tools.go:
```go
// +build tools
package tools
import (
2025-04-21 22:47:04 +03:00
_ "code.foilhatguy.casa/pub/help"
2025-04-21 21:37:03 +03:00
)
```
3. In the main package add a go:generate directive:
```go
2025-04-21 22:47:04 +03:00
//go:generate go run code.foilhatguy.casa/pub/help
2025-04-21 21:37:03 +03:00
```
4. Run code generator by **go generate** command:
```shell
go generate ./...
```
2025-04-21 22:47:04 +03:00
The package will generate a **help.go** file as a part of
the main package. It will contain code for --help flag detection.
2025-04-21 21:37:03 +03:00
2025-04-21 22:47:04 +03:00
5. Build and run your application with the --help flag.
2025-04-21 21:37:03 +03:00
```shell
2025-04-21 22:47:04 +03:00
go run . --help
2025-04-21 21:37:03 +03:00
```