Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance argparse help output customizability #53861

Closed
TomBrowder mannequin opened this issue Aug 20, 2010 · 5 comments
Closed

Enhance argparse help output customizability #53861

TomBrowder mannequin opened this issue Aug 20, 2010 · 5 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@TomBrowder
Copy link
Mannequin

TomBrowder mannequin commented Aug 20, 2010

BPO 9652
Nosy @terryjreedy, @bitdancer
Superseder
  • bpo-11695: Improve argparse usage/help customization
  • Files
  • python-v2.7-argparser-patch.txt: Proposed patch for Python 2.7
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2011-03-27.14:09:31.373>
    created_at = <Date 2010-08-20.20:56:57.862>
    labels = ['type-feature', 'library']
    title = 'Enhance argparse help output customizability'
    updated_at = <Date 2011-03-27.14:09:31.372>
    user = 'https://bugs.python.org/TomBrowder'

    bugs.python.org fields:

    activity = <Date 2011-03-27.14:09:31.372>
    actor = 'bethard'
    assignee = 'none'
    closed = True
    closed_date = <Date 2011-03-27.14:09:31.373>
    closer = 'bethard'
    components = ['Library (Lib)']
    creation = <Date 2010-08-20.20:56:57.862>
    creator = 'Tom.Browder'
    dependencies = []
    files = ['18590']
    hgrepos = []
    issue_num = 9652
    keywords = []
    message_count = 5.0
    messages = ['114455', '115082', '115108', '115126', '132325']
    nosy_count = 4.0
    nosy_names = ['terry.reedy', 'bethard', 'r.david.murray', 'Tom.Browder']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '11695'
    type = 'enhancement'
    url = 'https://bugs.python.org/issue9652'
    versions = ['Python 3.2']

    @TomBrowder
    Copy link
    Mannequin Author

    TomBrowder mannequin commented Aug 20, 2010

    I would like to be able to change argparse default strings so the first word is capitalized. In lieu of that, I propose the attached patch to 2.7 which changes them in the source code.

    @TomBrowder TomBrowder mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Aug 20, 2010
    @bethard
    Copy link
    Mannequin

    bethard mannequin commented Aug 27, 2010

    Looks like "usage" is almost always lowercase in the programs I tried (ssh, svn, cat, etc.). So it probably wouldn't be a good idea to change the default. Seems like both this and bpo-9694 need a better way to customize the text in argparse mesages.

    As a temporary workaround for the group names, you can try:

    parser._optionals.title = "Optional arguments"
    parser._positionals.title = "Positional arguments"

    I can't guarantee this will continue to work since it relies on internal details but at least it would work for the time being.

    @terryjreedy
    Copy link
    Member

    2.7 is closed to new features and I cannot see making a non-bug change in a maintenance release that could break something.

    Should this be closed in favor of bpo-9694? (Or vice versa?). Perhaps one of the issues should be renamed something like "Improve argparse message customization".

    @bitdancer bitdancer changed the title Tidy argparse default output Enhance argparse help output customizability Aug 27, 2010
    @TomBrowder
    Copy link
    Mannequin Author

    TomBrowder mannequin commented Aug 27, 2010

    ...

    Should this be closed in favor of bpo-9694? (Or vice versa?). Perhaps one of the issues should be renamed something like "Improve argparse message customization".

    That sounds like a winner to me

    -Tom

    @TomBrowder TomBrowder mannequin changed the title Enhance argparse help output customizability Tidy argparse default output Aug 27, 2010
    @bitdancer bitdancer changed the title Tidy argparse default output Enhance argparse help output customizability Aug 27, 2010
    @bethard
    Copy link
    Mannequin

    bethard mannequin commented Mar 27, 2011

    I'm moving this over to bpo-11695, which proposes support for a usage/help message template.

    To customize the argument group names, the recommended approach is to create your own argument groups, and only put arguments there, e.g.:

    parser = argparse.ArgumentParser(add_help=False)
    flags = parser.add_argument_group('My Optional Arguments')
    flags.add_argument('-h', '--help', action='help')
    flags.add_argument('-v', action='version', version='1.3')

    Then you'll get just the "My Optional Arguments" heading.

    @bethard bethard mannequin closed this as completed Mar 27, 2011
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant