docopt / docopt.go

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

boolean options don't seem to work #73

Open tmbdev opened 4 years ago

tmbdev commented 4 years ago

Boolean options don't seem to work the way they should. Here is an example:

package main

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

var usage string = `
Mytest.

Usage:
    mytest [options]

Options:
  --flag    a flag
`

func main() {
    opts, _ := docopt.ParseDoc(usage)
    flag, err := opts.Bool("--flag")
    fmt.Println(flag)
    fmt.Println(err)
}
$ go run mytest.go
false
key: "--flag" failed type conversion
$ go run mytest.go --flag
--flag requires argument
Usage:
    mytest [options]
exit status 1
$ go run mytest.go --flag=true
false
key: "--flag" failed type conversion
$ go version
go version go1.14.1 linux/amd64
$ 
gwijnja commented 4 years ago

You are using a tab between --flag and a. The docopt website says:

Use two spaces to separate options with their informal description.

If you replace the tab with two (or more) spaces, it works:

package main

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

var usage string = `
Mytest.

Usage:
        mytest [options]

Options:
  --flag    a flag
`

func main() {
        opts, _ := docopt.ParseDoc(usage)
        flag, err := opts.Bool("--flag")
        fmt.Println(flag)
        fmt.Println(err)
}
$ go run mytest.go
false
<nil>
$ go run mytest.go --flag
true
<nil>
marco-m commented 10 months ago

@tmbdev it looks like that this ticket can be closed?

tmbdev commented 10 months ago

Wouldn't it make sense to permit tabs?

On Thu, Nov 30, 2023, 01:49 Marco Molteni @.***> wrote:

@tmbdev https://github.com/tmbdev it looks like that this ticket can be closed?

— Reply to this email directly, view it on GitHub https://github.com/docopt/docopt.go/issues/73#issuecomment-1833426282, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACRQPZ7LTTSM3RHUPZH4NTYHBJD5AVCNFSM4LSOEOF2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBTGM2DENRSHAZA . You are receiving this because you were mentioned.Message ID: @.***>

marco-m commented 10 months ago

@tmbdev I am just an observer, so take my answer for what is worth. Permitting tabs would require to reach consensus on all the docopt project, not only docopt.go. The whole project itself seems to be inactive (see #74) This ticket is solved: just use spaces :-)