Allow "--version" to be used as the argument to --query, --header, et al.

But why?
This commit is contained in:
Junegunn Choi 2022-08-01 10:42:16 +09:00
parent 475469a2e7
commit bbbcd780c9
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

View File

@ -1742,12 +1742,20 @@ func postProcessOptions(opts *Options) {
}
}
func expectsArbitraryString(opt string) bool {
switch opt {
case "-q", "--query", "-f", "--filter", "--header", "--prompt":
return true
}
return false
}
// ParseOptions parses command-line options
func ParseOptions() *Options {
opts := defaultOptions()
for _, arg := range os.Args[1:] {
if arg == "--version" {
for idx, arg := range os.Args[1:] {
if arg == "--version" && (idx == 0 || idx > 0 && !expectsArbitraryString(os.Args[idx])) {
opts.Version = true
return opts
}