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

Split out argparse.ArgumentParser into its own function #54

Merged
merged 1 commit into from
Apr 20, 2024

Conversation

josch
Copy link
Contributor

@josch josch commented Apr 19, 2024

This is useful for use with argcomplete or argparse-manpage.

For example, with this change a man page can be automatically generated from the information in the argparse object. It looks like this:

autotiling(1)                        General Commands Manual                        autotiling(1)

NAME
       autotiling

SYNOPSIS
       autotiling  [-h]  [-d]  [-v]  [-o  [OUTPUTS  ...]]  [-w  [WORKSPACES ...]] [-l LIMIT] [-sw
       SPLITWIDTH] [-sh SPLITHEIGHT] [-sr SPLITRATIO] [-e [EVENTS ...]]

DESCRIPTION
       Script for sway and i3 to automatically switch the horizontal / vertical
       window split orientation

OPTIONS
       -d, --debug
              print debug messages to stderr

       -v, --version
              display version information


This is useful for use with argcomplete or argparse-manpage
@josch josch force-pushed the argparse-manpage branch from cde88ea to 9f7d5c6 Compare April 19, 2024 20:33
@nwg-piotr
Copy link
Owner

Does it actually require use of a separate function (which will only be called once), or is it enough to provide positional arguments prog="autotiling", description="description"?

@josch
Copy link
Contributor Author

josch commented Apr 20, 2024

I'm calling argparse-manpage like this:

argparse-manpage --pyfile=autotiling/main.py --function get_parser

The utility can only access the object returned by argparse.ArgumentParser if it's somehow publicly accessible and currently parser is a variable private to the main function.

@nwg-piotr
Copy link
Owner

Sounds like a justification, thanks.

@nwg-piotr nwg-piotr merged commit bf94d97 into nwg-piotr:master Apr 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants