-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support reading Argparse instances inside classes
So far, shphinxarg only has support for reading/importing Argparse instances from global variables/attributes within a module. However, there are use cases where Argparse is used inside classes of a module, not as a global variable. This is particularly the case for uses of 'argparse' in the context of CLI / REPL style user interfaces, such as for example those built using the 'cmd2' module. This change introduces the ability to specify a path in ':func:' using the '.'-notation (e.g. 'PysimApp.bulk_script_parser'). Initial patch by: Harald Welte <laforge@osmocom.org> Co-authored by: Vadim Yanitskiy <fixeria@osmocom.org>
- Loading branch information
Showing
4 changed files
with
72 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Argparse inside class Foo | ||
######################### | ||
|
||
.. argparse:: | ||
:filename: test/sample-inside-class.py | ||
:prog: sample-inside-class-foo | ||
:func: Foo.parser | ||
|
||
Argparse inside class Foo.Bar | ||
############################# | ||
|
||
.. argparse:: | ||
:filename: test/sample-inside-class.py | ||
:prog: sample-inside-class-foo-bar | ||
:func: Foo.Bar.parser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import argparse | ||
|
||
|
||
desc = 'Test parsing of Argparse instances inside classes' | ||
|
||
class Foo: | ||
parser = argparse.ArgumentParser(prog=f'{__name__}-foo', | ||
description=desc) | ||
parser.add_argument('--foo-arg1', help='foo-arg1 help') | ||
parser.add_argument('--foo-arg2', help='foo-arg2 help') | ||
|
||
|
||
class Bar: | ||
parser = argparse.ArgumentParser(prog=f'{__name__}-foo-bar', | ||
description=desc) | ||
parser.add_argument('--foo-bar-arg1', help='foo-bar-arg1 help') | ||
parser.add_argument('--foo-bar-arg2', help='foo-bar-arg2 help') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters