cliver

command module
v0.0.0-...-c13fd1b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2020 License: Apache-2.0 Imports: 1 Imported by: 0

README

cliver(CLI version demo)

展示如何通过go build时动态的指定版本信息。

  1. 设置环境变量。
VERSION=0.1
GIT_COMMIT=$(shell git rev-list -1 HEAD)
BUILD_DATE=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
  1. go build时通过ldflags传递变量pkg的具体变量。
go build -ldflags "-X github.com/shitaibin/cliver/version.Version=$(VERSION)  -X github.com/shitaibin/cliver/version.GitCommit=$(GIT_COMMIT) -X github.com/shitaibin/cliver/version.BuildDate=$(BUILD_DATE)" .

注意: i. 当前项目的完整名称已在go.mod中设置,所以-X pkg.Var中的pkg应当使用完整的包名称,否则无法设置成功。 ii. version包中提供了生成版本的函数version.Get()cliver version命令调用。

  1. 运行程序
$ ./cliver version
{Version: 0.1, GitCommit: 3977697acc47be3bc56f323847327ac7a13ad568, BuildDate: 2020-11-17T08:30:28Z, GoVersion: go1.15, Platform: darwin/amd64}

Documentation

Overview

Copyright © 2020 NAME HERE <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL