Skip to content

Commit e7b17fb

Browse files
committed
update readme & adjust eg with parse error type check
1 parent 6ce49eb commit e7b17fb

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ About object __parser__ :
8282

8383
1. `NewParser` first argument is the name of your program, but it's ok __not to fill__ , when it's empty string, program name will be `os.Args[0]` , which can be wired when using `go run`, but it will be the executable file's name when you release the code(using `go build`). It can be convinient where the release name is uncertain
8484
2. `help` function is auto injected, but you can disable it when using `NewParser`, with `&ParserConfig{DisableHelp: true}`. then you can use any way to define the `help` function, or whether to `help`
85-
3. When `help` showed up, the program will default __exit with code 1__ , this is stoppable by setting `ParserConfig.ContinueOnHelp` to be `true`, you can use your own help function instead
85+
3. When `help` showed up, the program will default __exit with code 1 (version < v1.5.0)__ or __return error type BreakAfterHelp (version >= 1.5.0)__ , this is stoppable by setting `ParserConfig.ContinueOnHelp` to be `true`, you can use your own help function instead
8686

8787
About __parse__ action:
8888

docs/cn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ hello hellflame
7676

7777
1. `NewParser` 第一个参数是程序的名字, 但__可以为空__ , 如果程序名为空, 则会使用 `os.Args[0]` 作为程序名 , 只是用 `go run` 时会有点怪怪的,但当发布为可执行文件,在运行时就会是可执行文件的名字(通过 `go build` 生成),所以在发布名称不确定的时候会比较方便
7878
2. `help` 方法会自动注入, 但也可以在 `NewParser` 时设定 `&ParserConfig{DisableHelp: true}` 来取消这个帮助入口,然后就可以用自己的帮助函数,甚至不给出帮助函数
79-
3. 帮助信息显示后,程序会以状态码 1 退出程序。可以设置 `ParserConfig.ContinueOnHelp``true`, 阻止这种退出
79+
3. 帮助信息显示后,程序会以状态码 1 退出程序(verison < v1.5.0),或者返回错误类型 `BreakAfterHelp` (version >= 1.5.0)。可以设置 `ParserConfig.ContinueOnHelp``true`, 阻止这种退出
8080

8181
关于 __parse__ 动作执行:
8282

examples/shell-completion/main.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package main
77
import (
88
"fmt"
99
"github.com/hellflame/argparse"
10+
"os"
1011
)
1112

1213
func main() {
@@ -21,7 +22,13 @@ func main() {
2122
install := p.AddCommand("install", "", nil)
2223
install.Strings("i", "in", nil)
2324
if e := p.Parse(nil); e != nil {
24-
fmt.Println(e.Error())
25+
switch e.(type) {
26+
case argparse.BreakAfterHelp:
27+
os.Exit(1)
28+
case argparse.BreakAfterShellScript:
29+
default:
30+
fmt.Printf(e.Error())
31+
}
2532
return
2633
}
2734
}

0 commit comments

Comments
 (0)