drdoctr / doctr

A tool for automatically deploying docs from Travis CI to GitHub pages.
https://drdoctr.github.io
MIT License
107 stars 30 forks source link

--command not working with spaces #365

Closed ZryletTC closed 4 years ago

ZryletTC commented 4 years ago

Hi,

I can't tell if this is a bug or I'm doing something wrong (likely the latter), but my build is breaking when I add more than one term to the --command option. This is visible in the most recent build of my test project or in this older build.

On the outside it looks almost as if the #193 was never added. Any ideas what's going on?

Thanks :)

asmeurer commented 4 years ago

Hmm, it should be working. We even have a test for it https://github.com/drdoctr/doctr/blob/747a8819041d688fe871cdf2de52eba4bc877de5/.travis.yml#L53. Maybe Travis's command line parsing is broken somehow?

asmeurer commented 4 years ago

And here it is working in doctr master https://travis-ci.org/github/drdoctr/doctr/jobs/687650375#L2888.

Does it work if you replace double quotes with single quotes?

asmeurer commented 4 years ago

Oh, I think you are getting the quoting wrong in your config. This is an issue with the way the shell works with quoted arguments, not doctr. You can see what is going on with something like

# test.py
import sys
print(sys.argv)
$ DOCTR_VERSIONS_COMMAND='--command "doctr-versions-menu --no-downloads-file"'
$ python test.py $DOCTR_VERSIONS_COMMAND
['test.py', '--command', '"doctr-versions-menu', '--no-downloads-file"']

whereas what you want is

$ python test.py --command "doctr-versions-menu --no-downloads-file"
['test.py', '--command', 'doctr-versions-menu --no-downloads-file']

Quoting $DOCTR_VERSIONS_COMMAND doesn't work either

$ python test.py "$DOCTR_VERSIONS_COMMAND"
['test.py', "--command 'doctr-versions-menu --no-downloads-file'"]

I don't know if there is a way to recursively quote args like this. If you want to extract the arguments, I would suggest doing something like

$ DOCTR_VERSIONS_COMMAND_ARGS="doctr-versions-menu --no-downloads-file"
$ python test.py --command "$DOCTR_VERSIONS_COMMAND_ARGS"
['test.py', '--command', 'doctr-versions-menu --no-downloads-file']

(note that it is important that "$DOCTR_VERSIONS_COMMAND_ARGS" is itself quoted!)

ZryletTC commented 4 years ago

Hmm, ok. I was wondering if it was something like that and had tried quoting $DOCTR_VERSIONS_COMMAND to no avail, but it looks like your solution could work. I guess it doesn't matter since I can just pass it sleep 1 if necessary but will doctr not error if given an empty --command flag?

asmeurer commented 4 years ago

It looks like it currently won't, but only because the return code of --command is ignored (that's a bug I guess).

I don't know how to do recursive quoting like you are trying to do in the shell. I'm not sure if it is possible. Someone with more shell experience would need to answer what the best way to deal with this is.

asmeurer commented 4 years ago

Looks like you can use this syntax:

DOCTR_VERSIONS_COMMAND=("--command" "doctr-versions-menu --no-downloads-file")
doctr "${DOCTR_VERSION_COMMANDS[@]}"

For example

$ python test.py "${DOCTR_VERSIONS_COMMAND[@]}"
['test.py', '--command', 'doctr-versions-menu --no-downloads-file']
ZryletTC commented 4 years ago

That's perfect, thank you!