cmdargparse 0.4.0__tar.gz → 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (21) hide show
  1. {cmdargparse-0.4.0 → cmdargparse-0.5.0}/PKG-INFO +6 -3
  2. {cmdargparse-0.4.0 → cmdargparse-0.5.0}/README.md +5 -2
  3. {cmdargparse-0.4.0 → cmdargparse-0.5.0}/cmdargparse/command.py +11 -1
  4. {cmdargparse-0.4.0 → cmdargparse-0.5.0}/cmdargparse/namespace.py +13 -0
  5. {cmdargparse-0.4.0 → cmdargparse-0.5.0}/cmdargparse.egg-info/PKG-INFO +6 -3
  6. {cmdargparse-0.4.0 → cmdargparse-0.5.0}/setup.py +1 -1
  7. {cmdargparse-0.4.0 → cmdargparse-0.5.0}/LICENSE +0 -0
  8. {cmdargparse-0.4.0 → cmdargparse-0.5.0}/cmdargparse/__init__.py +0 -0
  9. {cmdargparse-0.4.0 → cmdargparse-0.5.0}/cmdargparse/actions/__init__.py +0 -0
  10. {cmdargparse-0.4.0 → cmdargparse-0.5.0}/cmdargparse/actions/store.py +0 -0
  11. {cmdargparse-0.4.0 → cmdargparse-0.5.0}/cmdargparse/argument.py +0 -0
  12. {cmdargparse-0.4.0 → cmdargparse-0.5.0}/cmdargparse/custom.py +0 -0
  13. {cmdargparse-0.4.0 → cmdargparse-0.5.0}/cmdargparse/field.py +0 -0
  14. {cmdargparse-0.4.0 → cmdargparse-0.5.0}/cmdargparse/parser.py +0 -0
  15. {cmdargparse-0.4.0 → cmdargparse-0.5.0}/cmdargparse/unset.py +0 -0
  16. {cmdargparse-0.4.0 → cmdargparse-0.5.0}/cmdargparse.egg-info/SOURCES.txt +0 -0
  17. {cmdargparse-0.4.0 → cmdargparse-0.5.0}/cmdargparse.egg-info/dependency_links.txt +0 -0
  18. {cmdargparse-0.4.0 → cmdargparse-0.5.0}/cmdargparse.egg-info/requires.txt +0 -0
  19. {cmdargparse-0.4.0 → cmdargparse-0.5.0}/cmdargparse.egg-info/top_level.txt +0 -0
  20. {cmdargparse-0.4.0 → cmdargparse-0.5.0}/pyproject.toml +0 -0
  21. {cmdargparse-0.4.0 → cmdargparse-0.5.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cmdargparse
3
- Version: 0.4.0
3
+ Version: 0.5.0
4
4
  Summary: A declarative way to define `cmd2` argument parsers.
5
5
  Home-page: https://github.com/krnd/cmdargparse
6
6
  Author: Kilian Kaiping (krnd)
@@ -217,6 +217,9 @@ vv_ww: bool = cmdfield.flag() # -vv-ww OR --vv-ww
217
217
  <br/> *Named after the function `*_<name>`, or explicitly via
218
218
  `(command, name)`.*
219
219
 
220
+ Subcommands can be called via `args.subcommand()` instead of
221
+ `args.cmd2_subcommand_func(args)`.
222
+
220
223
  #### Arguments
221
224
  Subcommands also get the arguments of their parent commands and the constants
222
225
  of the root command.
@@ -227,7 +230,7 @@ Inheritance cannot be used to share options between subcommands.
227
230
  ```py
228
231
  @cmdcommand(_MyCommandArgs, subcommands=True)
229
232
  def do_mycommand(self, args: _MyCommandArgs) -> None:
230
- args.cmd2_subcommand_func(args)
233
+ args.subcommand()
231
234
 
232
235
  @cmdargument
233
236
  class _MySubArgs(_MyCommandArgs): ...
@@ -240,7 +243,7 @@ def mycommand_my_sub(self, args: _MySubArgs) -> None: ...
240
243
 
241
244
  @cmdcommand(_MyGroupArgs, subcommands=True, subcommand_to="mycommand") # mycommand mygroup
242
245
  def mycommand_mygroup(self, args: _MyGroupArgs) -> None:
243
- args.cmd2_subcommand_func(args)
246
+ args.subcommand()
244
247
 
245
248
  @cmdcommand(_MySubArgs, subcommand_to="mycommand mygroup") # mycommand mygroup mysub
246
249
  def mycommand_mygroup_mysub(self, args: _MySubArgs) -> None: ...
@@ -183,6 +183,9 @@ vv_ww: bool = cmdfield.flag() # -vv-ww OR --vv-ww
183
183
  <br/> *Named after the function `*_<name>`, or explicitly via
184
184
  `(command, name)`.*
185
185
 
186
+ Subcommands can be called via `args.subcommand()` instead of
187
+ `args.cmd2_subcommand_func(args)`.
188
+
186
189
  #### Arguments
187
190
  Subcommands also get the arguments of their parent commands and the constants
188
191
  of the root command.
@@ -193,7 +196,7 @@ Inheritance cannot be used to share options between subcommands.
193
196
  ```py
194
197
  @cmdcommand(_MyCommandArgs, subcommands=True)
195
198
  def do_mycommand(self, args: _MyCommandArgs) -> None:
196
- args.cmd2_subcommand_func(args)
199
+ args.subcommand()
197
200
 
198
201
  @cmdargument
199
202
  class _MySubArgs(_MyCommandArgs): ...
@@ -206,7 +209,7 @@ def mycommand_my_sub(self, args: _MySubArgs) -> None: ...
206
209
 
207
210
  @cmdcommand(_MyGroupArgs, subcommands=True, subcommand_to="mycommand") # mycommand mygroup
208
211
  def mycommand_mygroup(self, args: _MyGroupArgs) -> None:
209
- args.cmd2_subcommand_func(args)
212
+ args.subcommand()
210
213
 
211
214
  @cmdcommand(_MySubArgs, subcommand_to="mycommand mygroup") # mycommand mygroup mysub
212
215
  def mycommand_mygroup_mysub(self, args: _MySubArgs) -> None: ...
@@ -145,7 +145,17 @@ class _cmdcommand(type):
145
145
 
146
146
  (_, _, subcommand) = func.__name__.rpartition("_")
147
147
 
148
- return cmd2.as_subcommand_to(command, subcommand, parser)(func)
148
+ if func.__doc__:
149
+ help = cmd2.utils.strip_doc_annotations(func.__doc__)
150
+ else:
151
+ help = None
152
+
153
+ return cmd2.as_subcommand_to(
154
+ command,
155
+ subcommand,
156
+ parser,
157
+ help=help,
158
+ )(func)
149
159
 
150
160
  return _decorator
151
161
 
@@ -1,4 +1,5 @@
1
1
  import argparse
2
+ from typing import Any
2
3
 
3
4
  import cmd2
4
5
 
@@ -8,6 +9,18 @@ import cmd2
8
9
 
9
10
  class Namespace(argparse.Namespace):
10
11
 
12
+ def subcommand(self) -> Any:
13
+ """Calls the selected subcommand."""
14
+
15
+ # The function is 'None' for commands without subcommands.
16
+ if self.cmd2_subcommand_func is None:
17
+ raise RuntimeError(
18
+ f"Command '{self.cmd2_statement.command}' does not have "
19
+ "subcommands"
20
+ )
21
+
22
+ return self.cmd2_subcommand_func(self)
23
+
11
24
  def pfields(self, cmd: cmd2.Cmd, /) -> None:
12
25
  """Prints all fields using the feedback output function."""
13
26
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cmdargparse
3
- Version: 0.4.0
3
+ Version: 0.5.0
4
4
  Summary: A declarative way to define `cmd2` argument parsers.
5
5
  Home-page: https://github.com/krnd/cmdargparse
6
6
  Author: Kilian Kaiping (krnd)
@@ -217,6 +217,9 @@ vv_ww: bool = cmdfield.flag() # -vv-ww OR --vv-ww
217
217
  <br/> *Named after the function `*_<name>`, or explicitly via
218
218
  `(command, name)`.*
219
219
 
220
+ Subcommands can be called via `args.subcommand()` instead of
221
+ `args.cmd2_subcommand_func(args)`.
222
+
220
223
  #### Arguments
221
224
  Subcommands also get the arguments of their parent commands and the constants
222
225
  of the root command.
@@ -227,7 +230,7 @@ Inheritance cannot be used to share options between subcommands.
227
230
  ```py
228
231
  @cmdcommand(_MyCommandArgs, subcommands=True)
229
232
  def do_mycommand(self, args: _MyCommandArgs) -> None:
230
- args.cmd2_subcommand_func(args)
233
+ args.subcommand()
231
234
 
232
235
  @cmdargument
233
236
  class _MySubArgs(_MyCommandArgs): ...
@@ -240,7 +243,7 @@ def mycommand_my_sub(self, args: _MySubArgs) -> None: ...
240
243
 
241
244
  @cmdcommand(_MyGroupArgs, subcommands=True, subcommand_to="mycommand") # mycommand mygroup
242
245
  def mycommand_mygroup(self, args: _MyGroupArgs) -> None:
243
- args.cmd2_subcommand_func(args)
246
+ args.subcommand()
244
247
 
245
248
  @cmdcommand(_MySubArgs, subcommand_to="mycommand mygroup") # mycommand mygroup mysub
246
249
  def mycommand_mygroup_mysub(self, args: _MySubArgs) -> None: ...
@@ -7,7 +7,7 @@ with open("README.md", "r", encoding="utf-8") as file:
7
7
 
8
8
  setup(
9
9
  name="cmdargparse",
10
- version="0.4.0",
10
+ version="0.5.0",
11
11
  description="A declarative way to define `cmd2` argument parsers.",
12
12
  long_description=README,
13
13
  long_description_content_type="text/markdown",
File without changes
File without changes
File without changes