docopt / docopt.go

A command-line arguments parser that will make you smile.
http://docopt.org/
MIT License
1.43k stars 111 forks source link

When a line follows `Options:` declaration, options don't parse correctly #50

Open ghost opened 6 years ago

ghost commented 6 years ago

Description

When a non-option line comes after the Options: declaration, parsing fails in weird ways. Not only are options missing, but -h and --help are now split. This doesn't happen at try.docopt.org.

Repro

  1. Start with the options shortcut example
package main

import (
    "fmt"
    "github.com/docopt/docopt-go"
)

func main() {
    usage := `Example of program which uses [options] shortcut in pattern.

Usage:
  options_shortcut_example [options] <port>
  options_shortcut_example -h | --help

Options:
  -h --help                show this help message and exit
  --version                show version and exit
  -n, --number N           use N as a number
  -t, --timeout TIMEOUT    set timeout TIMEOUT seconds
  --apply                  apply changes to database
  -q                       operate in quiet mode`

    arguments, _ := docopt.Parse(usage, nil, false, "1.0.0rc2", false)
    fmt.Println(arguments)
}
  1. Modify as such
    Options:
    +These are things
    -h --help                show this help message and exit

Expected Behavior

$ go run options_shortcut_example.go --help
map[<port>:<nil> --help:true --version:false --number:<nil> --timeout:<nil> --apply:false -q:false]

Actual Behavior

$ go run options_shortcut_example.go --help
map[<port>:<nil> -h:false --help:true]