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

Rock example with grep and cut is broken #4

Closed
sagotsky opened this issue Dec 8, 2013 · 1 comment
Closed

Rock example with grep and cut is broken #4

sagotsky opened this issue Dec 8, 2013 · 1 comment

Comments

@sagotsky
Copy link

sagotsky commented Dec 8, 2013

Hi. I've been banging my head on this for about an hour. This is not my first attempt at getting docopt working on a stupid shell script. No matter what I do, the eval docopts line thinks -h is one of the args and spits out a help message.

I copied

#!/bin/sh                                                                                 
## rock 0.1.0
## Copyright (C) 200X Thomas Light
## License RIT (Robot Institute of Technology)
## This is free software: you are free to change and redistribute it.
## There is NO WARRANTY, to the extent permitted by law.

### Usage: rock [options] <argv>...
###
###       --help     Show help options.
###       --version  Print program version.

help=$(grep "^### " "$0" | cut -c 5-)
version=$(grep "^## "  "$0" | cut -c 4-)
eval "$(docopts -h "$help" -V "$version" : "$@")"

for arg in "${argv[@]}"; do
      echo "$arg"
done

from the example. It broke in the same way. When I switched to the heredoc example, it worked without issue.

@ghost
Copy link

ghost commented Dec 10, 2013

It's because of the line between the usage pattern and the options. There is a space in my README source code after the last hash sign, but naturally enough it gets dropped during the translations from reStructedText to HTML or a man page screen. So the grep for ^### doesn't catch it, and there isn't a blank line after the usage pattern, and docopt doesn't know what to do.

Thanks for bringing this up. I'll fix up the example so it's less fragile to whitespace hijinks.

@ghost ghost closed this as completed in 4c8b652 Dec 10, 2013
This issue was closed.
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

1 participant