version/README.md

41 lines
1 KiB
Markdown
Raw Normal View History

2025-04-20 12:13:03 +03:00
### The "Version" package
2025-04-20 12:19:55 +03:00
2025-04-20 12:13:03 +03:00
This package provides --version flag feature to your cli.
It recognize both short and long flags. Version number is
2025-04-20 12:19:55 +03:00
automatically added from the latest tag in your git repository.
2025-04-20 12:22:52 +03:00
2025-04-20 12:13:03 +03:00
-------------
2025-04-20 12:19:55 +03:00
2025-04-20 12:13:03 +03:00
### Usage
1. Download the package by **go get** command:
```shell
go get code.foilhatguy.casa/pub/version
```
2025-04-20 12:17:36 +03:00
2. Add the package as a tool dependency to your project in
2025-04-20 12:13:03 +03:00
tools.go:
```go
// +build tools
package tools
import (
_ "code.foilhatguy.casa/pub/version"
)
```
3. In the main package add a go:generate directive:
```go
//go:generate go run code.foilhatguy.casa/pub/version
```
4. Run code generator by **go generate** command:
```shell
go generate ./...
```
The package will detect a version number from the latest git
tag from your project. Then it will generate a **version.go**
file as a part of the main package. It will contain a version
number as a constant and code for --version flag detection.
2025-04-20 12:17:36 +03:00
2025-04-20 12:13:03 +03:00
5. Build and run your application with the --version flag.
```shell
go run . --version
```