You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Option to display metavar for non-toggle flags #105
I've been using flaggy in different projects for a while and it has been great, but there is one issue that bothers me, there's no metavar display for flags that require a value, which can be confusing and make flags seem like they don't require a value when they do, or vice versa, if the flag names aren't super obvious. Most other popular argument parsing libraries display this information.
argtest
Flags:
--version Displays the program version string.
-h --help Displays help with available flag, subcommand, and positional value parameters.
-c --config Config file
-v --verbose Verbose output
usage: main.py [-h] [-c CONFIG] [--config2 cfg-file] [-v]
argtest
options:
-h, --help show this help message and exit
-c CONFIG, --config CONFIG
Config file
--config2 cfg-file Config file with custom metavar
-v, --verbose Verbose output
Linux coreutils also follow a similar format (excerpt from grep --help):
-e, --regexp=PATTERNS use PATTERNS for matching
-f, --file=FILE take PATTERNS from FILE
-i, --ignore-case ignore case distinctions in patterns and data
It would be great if there was an option to configure whether to display the metavar or not (in case people want to preserve the current behavior), and to change the default metavar name.
Just thinking about this, I haven't been able to figure out what the best way to formulate the metavar string. Things that have come to mind so far:
The long flag name if it exists
The short flag name if it exists
The variable name inside the code, perhaps capitalized
Some new input (I dislike this because it means adding new properties to existing or new flag inputs funcs)
Do you have any ideas what you would like to see there? If this can be done simply, then it's relatively easy to add it as a global toggle for the package to enable.
Also, your username @unrealtournament is perhaps serendipity, but I do work Epic Games. If you're someone who works there, say "hi" on Slack!
I opened draft PR #106 with an opt-in implementation.
It derives metavars from flag names (--config-file → CONFIG_FILE, -p → P), leaves boolean toggles unchanged, and keeps metavars disabled by default. Enable metavars with flaggy.EnableMetavars() or p.EnableMetavars().
I think your proposed solution is good, without having to break current function signatures by adding additional parameters. I would be ok with that.
The ideal situation would be to be able to specify the metavar name, but due to how flaggy is structured it would complicate things, and its a rather niche thing to have to change the metavar anyway, so I don't think it's worth it. Other libraries, such as pflag just add the type (--config string), but I prefer it the way you have chosen to do it, as its a bit more expressive.
P.S: Unfortunately the username is just coincidence, I just like the game :)
Activity
integrii commentedon Jul 28, 2026
Thanks for your appreciation of the project!
Just thinking about this, I haven't been able to figure out what the best way to formulate the metavar string. Things that have come to mind so far:
Do you have any ideas what you would like to see there? If this can be done simply, then it's relatively easy to add it as a global toggle for the package to enable.
Also, your username @unrealtournament is perhaps serendipity, but I do work Epic Games. If you're someone who works there, say "hi" on Slack!
integrii commentedon Jul 28, 2026
I opened draft PR #106 with an opt-in implementation.
It derives metavars from flag names (
--config-file→CONFIG_FILE,-p→P), leaves boolean toggles unchanged, and keeps metavars disabled by default. Enable metavars withflaggy.EnableMetavars()orp.EnableMetavars().unrealtournament commentedon Jul 28, 2026
I think your proposed solution is good, without having to break current function signatures by adding additional parameters. I would be ok with that.
The ideal situation would be to be able to specify the metavar name, but due to how flaggy is structured it would complicate things, and its a rather niche thing to have to change the metavar anyway, so I don't think it's worth it. Other libraries, such as pflag just add the type (
--config string), but I prefer it the way you have chosen to do it, as its a bit more expressive.P.S: Unfortunately the username is just coincidence, I just like the game :)
unrealtournament commentedon Sep 12, 2026
Looks like the PR is pretty much ready and working, could this be merged (and released)? Thanks!