#497 Passing additional arguments to underlaying commands
Merged by onosek. Opened by onosek.
onosek/rpkg extra_args  into  master

Download 497.patch

There are two groups of arguments:
* standard arguments defined by individual parsers
* extra arguments that are allowed for some (individually allowed)
commands. They are passed to underlying command (usually appended
to the rest of arguments on commandline)
This commit adds a common way that allow user to use extra arguments
for some commands. Commands include mockbuild, srpm, clone.

JIRA: RHELCMP-101
JIRA: RHELCMP-141
Fixes: #432
Fixes: #413

Signed-off-by: Ondrej Nosek onosek@redhat.com

rebased onto 188e3390264730e369929dc81f5c9f1ebc53a5a1

With this feature is possible to remove previously manually added arguments like
mockbuild --disablerepo/--enablerepo, local --with/--without, ...
But I think when we already have them and some users possibly use them, removing could cause little confusion. It means removing them from help (functionality would be the same). Argparse help generator would not show them.

'update' command mentioned in the request will be treated in the fedpkg, because it is not part of rpkg common library.

I found "--" string separates regular arguments and extra arguments unnecessary. Is it OK? Or does it have a special function or is it a convention?

Personally I would expect the usage would be to always separate put the extra arguments at the end and separate them by --. That should prevent conflicts and I think -- is a relatively common way to indicate parsing arguments should stop.

For example fedpkg mockbuild -N --enable-network -- --with-ssl --without-python2. Anything before -- will go to fedpkg, anything after that will be given to mock directly.

I was considering it. But I didn't find the way how to do this via argparse library.
It is probably possible. But this approach would require lot of manual parsing because argparse will not even give me even a ordering of arguments.

I think it should be doable with argparse.REMAINDER. I'm not sure it always requires the -- in there, but it should support it.

I had a similar problem in compose-partial-copy, and in the end the solution is very similar to what is in this PR. I must have misremembered it.

https://pagure.io/compose-utils/blob/master/f/bin/compose-partial-copy

Right now it's possible to use the -- to avoid conflicts, but it's not required, right? If so, I guess it should be fine.

rebased onto ac416257d4b6a9fa8f9e033c429b30cd7f0254b3

rebased onto 61255c88b812c79387eacff9a55fa1971e293a72

Despite I didn't find inspiration in compose-partial-copy, I found argparse.REMAINDER good tip for implementation. Thanks. It is significantly simpler than the original solution.
Current code lacks tests, I am gonna add some.
A lot of code changes in the PR modifies ordering of argument processing in methods regarding rpmbuild operations, hopefully with no functional consequences. The intension was better readability because methods do almost the same work and therefore they should look similar.

That is really very nice. I like it.

rebased onto fe638de275182cf9302eb42aecd327e01854969b

Unittests and minor corrections were just posted.

2 new commits added

  • Unittests for passing additional arguments
  • Passing additional arguments to underlaying commands

Pull-Request has been merged by onosek

Metadata