From 40a5ca81c9d0f3468b1ac994290b624b859989a0 Mon Sep 17 00:00:00 2001 From: Greyh4t Date: Fri, 6 May 2022 00:28:49 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4about=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=20(#92)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 优化usage显示信息 * 更新版本信息显示功能,去除进程名显示 * 更新测试用例 * 调整about信息显示 * 调整about显示模板 --- clop_version_about_test.go | 12 +----------- help_tmpl.go | 13 +++---------- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/clop_version_about_test.go b/clop_version_about_test.go index 6aae097..970b875 100644 --- a/clop_version_about_test.go +++ b/clop_version_about_test.go @@ -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"` } @@ -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) { diff --git a/help_tmpl.go b/help_tmpl.go index 9d41d99..87b4acf 100644 --- a/help_tmpl.go +++ b/help_tmpl.go @@ -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}}