question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Subcommand-specific -v flag shadows the global one

See original GitHub issue

We register -v on subcommands (such as lock create), but we also register it globally. However argparse returns the global args and subcommand args in a single Namespace object, and in that object the value from the subcommand wins, and so the global value is hidden.

In other words, in pex -vvv lock create -vvvvv .... the subcommand value (verbosity=5) is the one available in the Namespace object returned by parse_args(), and the global value (verbosity=3) is not available anywhere. This is true even if no explicit arg is provided for the subcommand. The subcommand arg’s default (verbosity=0) overwrites the global value.

This is confusing to users, because pex -vvv lock create doesn’t fail, it just silently ignores that value. Pants, in fact, made this mistake.

We work around this in Pants here: https://github.com/pantsbuild/pants/pull/15243 but should fix at the Pex level as well.

One option is to not register the verbosity flag globally. Another, possibly simpler, is to only register it globally and not register it on the subcommands. In either case, there is the following consequence: the flag cannot appear in that position. I.e., either pex -vvv lock create ... will fail or pex lock create -vvv ... will fail, respectively.

A third, probably best, option is to register the global verbosity under a different dest. Then both will be available in the Namespace object. We then just have to decide what the effective verbosity should be if both are specified.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
benjywcommented, Apr 25, 2022

As you may have guessed, this affects all the global options. Basically registering them in global position, as we do today, has no practical effect and the args are silently ignored, if a subcommand is encountered.

0reactions
jsiroiscommented, Apr 28, 2022

Hrm. Yeah, I was confused by subcommands in argparse and I think I still am. Trying to page this in, but the path you’re pushing seems like the right way to fix things for now at the very least.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Conventions for Command Line Options | Hacker News
I can't stop but see here parallels between cmdline arguments vs. environment variables for programs, and keyword arguments vs. dynamic binding ...
Read more >
Product Manual: Ultrastar DC HC560 (SATA) - Western Digital
1. Hard Disk Drive Specification. Hard disk drive specifications ... SATA Specification Revision 3.1 and prior revisions assigned 3.3V to ...
Read more >
Latest Blogposts - Yahoo Developer Network
We recently converted one of our internal libraries from all Objective-C to ... JSON Objects of Unknown Type In a perfect world, we...
Read more >
man pages section 1M: System Administration Commands
the global variable errno indicating why they failed. ... If the -v flag is specified, the following will result.
Read more >
SLES 15 SP3 | Virtualization Guide - SUSE Documentation
Add the vmx (for Intel CPUs) or the svm (for AMD CPUs) CPU feature to the -cpu QEMU command line option, which enables...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found