Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boolean options don't seem to work #73

Open
tmbdev opened this issue Mar 24, 2020 · 4 comments
Open

boolean options don't seem to work #73

tmbdev opened this issue Mar 24, 2020 · 4 comments

Comments

@tmbdev
Copy link

tmbdev commented Mar 24, 2020

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
Copy link

gwijnja commented Jun 30, 2020

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
Copy link

marco-m commented Nov 30, 2023

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

@tmbdev
Copy link
Author

tmbdev commented Dec 1, 2023 via email

@marco-m
Copy link

marco-m commented Dec 1, 2023

@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 :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants