Skip to content

Commit

Permalink
调整about信息显示 (#92)
Browse files Browse the repository at this point in the history
* 优化usage显示信息

* 更新版本信息显示功能,去除进程名显示

* 更新测试用例

* 调整about信息显示

* 调整about显示模板
  • Loading branch information
Greyh4t authored May 5, 2022
1 parent b425ece commit 40a5ca8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 21 deletions.
12 changes: 1 addition & 11 deletions clop_version_about_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

// 测试显示信息, 普通命令
func Test_Version_Show2(t *testing.T) {
func Test_Version_Show(t *testing.T) {
type show struct {
Max int `clop:"short;long" usage:"max threads"`
}
Expand All @@ -19,20 +19,10 @@ func Test_Version_Show2(t *testing.T) {
cmd := New([]string{"-h"}).SetProcName("Test_Version_Show").SetVersion("v0.0.2").SetExit(false).SetOutput(&buf)
cmd.MustBind(&show{})

assert.NotEqual(t, strings.Index(buf.String(), "v0.0.2"), -1)
assert.NotEqual(t, strings.Index(buf.String(), "print version information"), -1)
assert.NotEqual(t, strings.Index(buf.String(), "print the help information"), -1)
}

// 测试显示信息
func Test_Version_Show(t *testing.T) {
var buf bytes.Buffer
cmd := New([]string{"-h"}).SetProcName("Test_Version_Show").SetVersion("v0.0.2").SetExit(false).SetOutput(&buf)
cmd.MustBind(&git{})

assert.NotEqual(t, strings.Index(buf.String(), "v0.0.2"), -1)
}

// 测试about信息
func Test_About_Show(t *testing.T) {

Expand Down
13 changes: 3 additions & 10 deletions help_tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,11 @@ func (h *Help) output(w io.Writer) error {
return tmpl.Execute(w, *h)
}

var usageDefaultTmpl = `
{{- $ShowUsageDefault := .ShowUsageDefault}}
{{- if gt (len .Version) 0}}
{{- .ProcessName}} {{.Version}}
{{end}}
var usageDefaultTmpl = `{{- $ShowUsageDefault := .ShowUsageDefault}}{{- if gt (len .About) 0}}
{{- .About}}
{{- if gt (len .About) 0}}
{{- .About}}
{{end}}
{{- if or (gt (len .Flags) 0) (gt (len .Options) 0) (gt (len .Args) 0) (gt (len .Subcommand) 0)}}
Usage:
{{- if or (gt (len .Flags) 0) (gt (len .Options) 0) (gt (len .Args) 0) (gt (len .Subcommand) 0)}}Usage:
{{if gt (len .ProcessName) 0}}{{.ProcessName}} {{end}}
{{- if gt (len .Flags) 0}}[Flags] {{end}}
{{- if gt (len .Options) 0}}[Options] {{end}}
Expand Down

0 comments on commit 40a5ca8

Please sign in to comment.