Skip to content
This repository has been archived by the owner on Jul 20, 2020. It is now read-only.

When arguments are passed to script via $@ in bash script, quoted parameters like --author get truncated #11

Open
jf-ct opened this issue Nov 8, 2018 · 6 comments
Assignees

Comments

@jf-ct
Copy link
Contributor

jf-ct commented Nov 8, 2018

This may not be a bug in the library, but it may be possible to set nargs="+" and then have some logic to do a ' '.join(gerrit_args.author) (and so on for similar fields)

So far I have had to do a workaround after parsing (using sys.argv) for the following fields:

  • --uploader
  • --change-owner
  • --author

Another similar issue occurs when Gerrit passes --topic without any argument, and the parser expects one to be there. (i.e. some of the configurations could be tweaked for certain options)

Maybe instead of _generate_parser() there could be an extra step before that like _generate_options() so that the options could be modified before the call to _generate_parser()

@jf-ct jf-ct changed the title When arguments are passed to script via $@ in bash script, quoted parameters like author get truncated When arguments are passed to script via $@ in bash script, quoted parameters like --author get truncated Nov 8, 2018
@deepbrook
Copy link
Owner

It's a good idea to handle this though. If you have the time to take care of this, it would be greatly appreciated!

Otherwise, I'll look into it asap.

Also, thanks for your contribution so far!

@deepbrook
Copy link
Owner

@jf-ct , what python version are you running?

I tried the following to reproduce the issue you mentioned, but I think it may have been already taken care of in newer versions of python.

Shell script:

#!/usr/bin/env bash
# Relay all flags given to this script to python using "@$"
python patchset-created "$@"

patchset-created file

#!/usr/bin/python3
import sys
from gerrit_hooks import parse_options

print(sys.argv)
options = parse_options()
print(options.uploader)

Output:

(tests-2UXd7nDr) nls@nls-ThinkPad-X270:~/repos/gerrit-hooks/tests$ bash arg_proxy.sh --uploader "me" --change 1
['patchset-created', '--uploader', 'me', '--change', '1']
me
(tests-2UXd7nDr) nls@nls-ThinkPad-X270:~/repos/gerrit-hooks/tests$ 

So either my test case is too simple, or it's already fixed.

As for the tweaks, I updated the --topic argument as you stated.

@deepbrook deepbrook self-assigned this Nov 23, 2018
@jf-ct
Copy link
Contributor Author

jf-ct commented Nov 26, 2018 via email

@jf-ct
Copy link
Contributor Author

jf-ct commented Nov 26, 2018

I would also note that for the submit hook that the --submitter parameter has this same issue.

@jf-ct
Copy link
Contributor Author

jf-ct commented Nov 26, 2018

One thing I forgot, when the value "John Doe [email protected]" gets passed by Gerrit, it seemed like it wasn't passing it with quotes

@deepbrook
Copy link
Owner

Ah, okay! If it isn't passed with quotes, that would be an issue concerning the nargs option. It should be possible to use a custom action for that.

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

No branches or pull requests

2 participants