Skip to content

Commit

Permalink
Modify feature: 修订帮助信息。
Browse files Browse the repository at this point in the history
  • Loading branch information
voidint committed May 4, 2019
1 parent f76cfac commit df4dc7a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
6 changes: 3 additions & 3 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package build
import "strings"

const (
// VersionNumber 版本号
VersionNumber = "0.1.0"
// ShortVersion 短版本号
ShortVersion = "0.1.0"
)

// The value of variables come form `gb build -ldflags '-X "build.Build=xxxxx" -X "build.CommitID=xxxx"' `
Expand All @@ -20,7 +20,7 @@ var (
// Version 生成版本信息
func Version() string {
var buf strings.Builder
buf.WriteString(VersionNumber)
buf.WriteString(ShortVersion)

if Build != "" {
buf.WriteByte('\n')
Expand Down
26 changes: 26 additions & 0 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,29 @@ func Run() {
os.Exit(1)
}
}

func init() {
cli.AppHelpTemplate = fmt.Sprintf(`NAME:
{{.Name}}{{if .Usage}} - {{.Usage}}{{end}}
USAGE:
{{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Version}}{{if not .HideVersion}}
VERSION:
%s{{end}}{{end}}{{if .Description}}
DESCRIPTION:
{{.Description}}{{end}}{{if len .Authors}}
AUTHOR{{with $length := len .Authors}}{{if ne 1 $length}}S{{end}}{{end}}:
{{range $index, $author := .Authors}}{{if $index}}
{{end}}{{$author}}{{end}}{{end}}{{if .VisibleFlags}}
OPTIONS:
{{range $index, $option := .VisibleFlags}}{{if $index}}
{{end}}{{$option}}{{end}}{{end}}{{if .Copyright}}
COPYRIGHT:
{{.Copyright}}{{end}}
`, build.ShortVersion)
}

0 comments on commit df4dc7a

Please sign in to comment.