diff --git a/README.md b/README.md index 247309d..56ce3dc 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,8 @@ clop (Command Line Option Parse)是一款基于struct的命令行解析器,麻 - [Parsing flag code to generate clop code](#Parsing-flag-code-to-generate-clop-code) - [Implementing linux command options](#Implementing-linux-command-options) - [cat](#cat) +- [faq](#faq) + - [The subcommand or option does not take effect](#The-subcommand-or-option-does-not-take-effect) ## Installation @@ -708,3 +710,8 @@ Args: */ ``` + +## faq +### The subcommand or option does not take effect +q: 关于子命令或者命令行命令没有生效 +a: 可以检查下结构体的字段是否是大写开头。 \ No newline at end of file diff --git a/clop.go b/clop.go index 8b76ecb..be4ab3c 100644 --- a/clop.go +++ b/clop.go @@ -15,7 +15,7 @@ import ( var ( ErrDuplicateOptions = errors.New("is already in use") //ErrUsageEmpty = errors.New("usage cannot be empty") - ErrUnsupported = errors.New("unsupported command") + ErrUnsupported = errors.New("unsupported clop command") ErrNotFoundName = errors.New("no command line options found") ErrOptionName = errors.New("Illegal option name") ) @@ -841,7 +841,7 @@ func (c *Clop) parseTagAndSetOption(clop string, usage string, def string, field c.envAndArgs = append(c.envAndArgs, option) default: - return fmt.Errorf("%s:(%s) clop(%s)", ErrUnsupported, opt, clop) + return fmt.Errorf(`%s:(%s) clop:"%s", Maybe you need to clop:"short;long"`, ErrUnsupported, opt, clop) } if strings.HasPrefix(opt, "-") && len(name) == 0 { diff --git a/clop_usage_must_have_value_test.go b/clop_usage_must_have_value_test.go index 9086e13..0dea07b 100644 --- a/clop_usage_must_have_value_test.go +++ b/clop_usage_must_have_value_test.go @@ -8,7 +8,10 @@ import ( "github.com/stretchr/testify/assert" ) -func Test_Issue(t *testing.T) { +// 该文件定位 +// 各种出错的提示信息自测函数 + +func Test_Usage_MustHaveValue(t *testing.T) { type test struct { Long int `clop:"short;long" valid:"required"` @@ -36,3 +39,15 @@ func Test_Issue(t *testing.T) { assert.NotEqual(t, strings.Index(tc, "must have a value!"), -1) } } + +func Test_Usage_UnknownCommand(t *testing.T) { + type cmd struct { + C string `clop:"C" usage:""` + } + + c0 := cmd{} + var b bytes.Buffer + c := New([]string{}).SetOutput(&b).SetExit(false) + c.Bind(&c0) + assert.NotEqual(t, strings.Index(b.String(), `clop:"short;long"`), -1) +}