From ea791cfa42198828343fa6dda6b3426070e985ab Mon Sep 17 00:00:00 2001 From: harakeishi Date: Sat, 26 Feb 2022 17:16:05 +0900 Subject: [PATCH] =?UTF-8?q?=E8=AA=AC=E6=98=8E=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e8612b5..117f462 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ ![logo](logo.png) -[![GitHub release](https://img.shields.io/github/release/harakeishi/curver.svg)](https://github.com/harakeishi/curver/releases) [![Go Report Card](https://goreportcard.com/badge/github.com/harakeishi/curver)](https://goreportcard.com/report/github.com/harakeishi/curver) [![Test](https://github.com/harakeishi/curver/actions/workflows/test.yml/badge.svg)](https://github.com/harakeishi/curver/actions/workflows/test.yml) +[![GitHub release](https://img.shields.io/github/release/harakeishi/curver.svg)](https://github.com/harakeishi/curver/releases) [![Go Report Card](https://goreportcard.com/badge/github.com/harakeishi/curver)](https://goreportcard.com/report/github.com/harakeishi/curver) `curver` is a simple way to display the version of a CUI tool made with go. `curver` was named as an abbreviation for `current version`. @@ -9,8 +9,9 @@ - [Importing](#importing) - [Documentation](#documentation) - [usage](#usage) - - [normal](#normal) + - [use go build](#use-go-build) - [use goreleaser](#use-goreleaser) + - [If you only want the version](#if-you-only-want-the-version) - [License](#license) # Installation @@ -32,7 +33,7 @@ Visit the docs on [GoDoc](https://pkg.go.dev/github.com/harakeishi/curver) If the value using ldflag is stored in the variable Version, that value will be displayed. Otherwise, it will display the build information embedded in the running binary. -## normal +## use go build ```go // main.go package main @@ -60,7 +61,7 @@ version: v0.1.0 If you want to embed the result of 'git tag', you can do the following ``` -$ go build -ldflags "-X github.com/harakeishi/curver.Version=$(git describe --tags)" -o ./cmds +$ go build -ldflags "-X github.com/harakeishi/curver.Version=$(git describe --tags)" -o ./main ``` ## use goreleaser If you are using [goreleaser](https://goreleaser.com/) to do the release, do the following @@ -72,6 +73,22 @@ builds: ``` +## If you only want the version +The following will return the version as a string. + +```go +// main.go +package main + +import ( + "github.com/harakeishi/curver" +) + +func main () { + version := curver.GetVersion() +} +``` + # License Copyright (c) 2022 harakeishi Licensed under [MIT](LICENSE)