[issue42023] Argparse: Add a "display" arg

2020-10-14 Thread ThatXliner


ThatXliner  added the comment:

In the end, I think python's argparse needs more built-in help formatters...


Should I close this?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42023] Argparse: Add a "display" arg

2020-10-14 Thread ThatXliner


ThatXliner  added the comment:

Editing the description, etc. seems like a good way to do this. But it seems 
"hacky". The other answer on StackOverflow implements a custom class which does 
nice things, but not what I want.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42023] Argparse: Add a "display" arg

2020-10-14 Thread paul j3


paul j3  added the comment:

Some StackOverFlow answers cusomizing this help method:

https://stackoverflow.com/questions/23936145/python-argparse-help-message-disable-metavar-for-short-options

https://stackoverflow.com/questions/18275023/dont-show-long-options-twice-in-print-help-from-argparse

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42023] Argparse: Add a "display" arg

2020-10-14 Thread ThatXliner


ThatXliner  added the comment:

> So if you can get by with just customizing _format_action_invocation, there's 
> no need for further action here.

Then maybe we could just make a new function that takes 2 arguments: Name of 
another action class (or the action class itself), and a tuple of the arg names 
to be displayed. It returns a new action class that contains the help text 
properties of the given action class with customized displayed arg names.


Maybe like

parser.add_argument("-f", "--foo", 
action=argparse.CustomArgName(action="store_true", name=("-F!!", "--FOO!"), 
help="TO foo a bar"))

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42023] Argparse: Add a "display" arg

2020-10-14 Thread ThatXliner


ThatXliner  added the comment:

Should I rename this to "Argparse: finer control on help txt"

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42023] Argparse: Add a "display" arg

2020-10-14 Thread paul j3


paul j3  added the comment:

That method could be customized in a HelpFormatter subclass.  There already are 
several subclasses (documented), and writing your own is allowed, if not 
actually encouraged.

https://docs.python.org/3/library/argparse.html#formatter-class

Adding an extra parameter to 'add_argument', and passing that on through the 
Action class (and subclasses) is, potentially, a bigger task.  

So if you can get by with just customizing _format_action_invocation, there's 
no need for further action here.

I'll look for some examples, here or on SO, of customizing this method.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42023] Argparse: Add a "display" arg

2020-10-14 Thread ThatXliner


ThatXliner  added the comment:

>However, I can imagine adding a variable that gives the user full control over 
>the action-invocation.  In:

argparse.HelpFormatter._format_action_invocation method.

That's what I'm trying to change. If there was a public API/method for 
manipulating the left side of the help menu.

  (This part) (Manipulatable via help=)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42023] Argparse: Add a "display" arg

2020-10-13 Thread paul j3


paul j3  added the comment:

I'm not following this request either, especially the colored part.

However, I can imagine adding a variable that gives the user full control over 
the action-invocation.  In:

argparse.HelpFormatter._format_action_invocation method.

Currently it accepts the metavar (but not the tuple version) for a positional, 
but for optionals constructs:

  -s ARGS, --long ARGS

This can be quite long and ugly if the ARGS is a long choices, or there are 
many flag alternatives.  A number of SO users have asked for something simpler, 
usually with just on flag or

  -s, --long ARGS

There may even be a bug/issue(s) related to this already.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42023] Argparse: Add a "display" arg

2020-10-13 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

> and the metavar arg isn't really helpful.

Is your issue with *metavar* that it changes the help() output in two places?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42023] Argparse: Add a "display" arg

2020-10-12 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +paul.j3, rhettinger

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42023] Argparse: Add a "display" arg

2020-10-12 Thread ThatXliner


New submission from ThatXliner :

In argparse, I've always wanted a way to make colored help text like those of 
poetry and pipenv. But argparse's show help isn't well documented (Therefore, I 
can't find a way to completely modify the help text), and the metavar arg isn't 
really helpful. I want to do something like this:

>>> import argparse
>>> parser = argparse.ArgumentParser()
>>> parser.add_argument("foo", help="To foo a bar", display="FOO")
>>> parser.print_help()

usage: main.py [-h] foo

positional arguments:
  FOO To foo a bar

optional arguments:
  -h, --help  show this help message and exit

>>>

That way, I can colorize the help output.

--
components: Library (Lib)
messages: 378526
nosy: ThatXliner
priority: normal
severity: normal
status: open
title: Argparse: Add a "display" arg
type: enhancement
versions: Python 3.10, Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com