cmdargparse 0.2.0__tar.gz → 0.3.1__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.2.0 → cmdargparse-0.3.1}/PKG-INFO +15 -2
  2. {cmdargparse-0.2.0 → cmdargparse-0.3.1}/README.md +12 -0
  3. {cmdargparse-0.2.0 → cmdargparse-0.3.1}/cmdargparse/command.py +16 -12
  4. {cmdargparse-0.2.0 → cmdargparse-0.3.1}/cmdargparse/field.py +12 -1
  5. {cmdargparse-0.2.0 → cmdargparse-0.3.1}/cmdargparse.egg-info/PKG-INFO +15 -2
  6. {cmdargparse-0.2.0 → cmdargparse-0.3.1}/setup.py +3 -3
  7. {cmdargparse-0.2.0 → cmdargparse-0.3.1}/LICENSE +0 -0
  8. {cmdargparse-0.2.0 → cmdargparse-0.3.1}/cmdargparse/__init__.py +0 -0
  9. {cmdargparse-0.2.0 → cmdargparse-0.3.1}/cmdargparse/actions/__init__.py +0 -0
  10. {cmdargparse-0.2.0 → cmdargparse-0.3.1}/cmdargparse/actions/store.py +0 -0
  11. {cmdargparse-0.2.0 → cmdargparse-0.3.1}/cmdargparse/argument.py +0 -0
  12. {cmdargparse-0.2.0 → cmdargparse-0.3.1}/cmdargparse/custom.py +0 -0
  13. {cmdargparse-0.2.0 → cmdargparse-0.3.1}/cmdargparse/namespace.py +0 -0
  14. {cmdargparse-0.2.0 → cmdargparse-0.3.1}/cmdargparse/parser.py +0 -0
  15. {cmdargparse-0.2.0 → cmdargparse-0.3.1}/cmdargparse/unset.py +0 -0
  16. {cmdargparse-0.2.0 → cmdargparse-0.3.1}/cmdargparse.egg-info/SOURCES.txt +0 -0
  17. {cmdargparse-0.2.0 → cmdargparse-0.3.1}/cmdargparse.egg-info/dependency_links.txt +0 -0
  18. {cmdargparse-0.2.0 → cmdargparse-0.3.1}/cmdargparse.egg-info/requires.txt +0 -0
  19. {cmdargparse-0.2.0 → cmdargparse-0.3.1}/cmdargparse.egg-info/top_level.txt +0 -0
  20. {cmdargparse-0.2.0 → cmdargparse-0.3.1}/pyproject.toml +0 -0
  21. {cmdargparse-0.2.0 → cmdargparse-0.3.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cmdargparse
3
- Version: 0.2.0
3
+ Version: 0.3.1
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)
@@ -13,9 +13,10 @@ Classifier: Intended Audience :: Developers
13
13
  Classifier: Intended Audience :: System Administrators
14
14
  Classifier: Operating System :: OS Independent
15
15
  Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.13
16
17
  Classifier: Programming Language :: Python :: 3.14
17
18
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
- Requires-Python: >=3.14
19
+ Requires-Python: >=3.13
19
20
  Description-Content-Type: text/markdown
20
21
  License-File: LICENSE
21
22
  Requires-Dist: cmd2~=4.2
@@ -76,6 +77,9 @@ class MyApplication(cmd2.Cmd):
76
77
  * `default` <br/>
77
78
  The arguments default value if not specified.
78
79
  <br/> (Providing a default value makes the argument optional.)
80
+ * `nargs` <br/>
81
+ The number of command-line values to be consumed.
82
+ <br/> https://docs.python.org/3/library/argparse.html#nargs
79
83
  * `type` <br/>
80
84
  Explicitly specifies the `type` to be used by `argparse`.
81
85
  <br/> https://docs.python.org/3/library/argparse.html#type
@@ -94,6 +98,8 @@ arg: str | None = cmdfield.argument(
94
98
  },
95
99
  default=None,
96
100
  )
101
+ args: list[str] = cmdfield.argument()
102
+ more: list[str] = cmdfield.argument(nargs="+")
97
103
  ```
98
104
 
99
105
 
@@ -116,6 +122,9 @@ arg: str | None = cmdfield.argument(
116
122
  Explicitly specifies all option declarations.
117
123
  * `more_decls` <br/>
118
124
  Specifies additional option declarations.
125
+ * `nargs` <br/>
126
+ The number of command-line values to be consumed.
127
+ <br/> https://docs.python.org/3/library/argparse.html#nargs
119
128
  * `type` <br/>
120
129
  Explicitly specifies the `type` to be used by `argparse`.
121
130
  <br/> https://docs.python.org/3/library/argparse.html#type
@@ -131,6 +140,8 @@ arg: str | None = cmdfield.argument(
131
140
  xx: str | None = cmdfield.option()
132
141
  yy: int | None = cmdfield.option([1, 2, 3])
133
142
  zz: str = cmdfield.option(required=True)
143
+ hh: list[str] | None = cmdfield.option(default=None)
144
+ qq: list[int] | None = cmdfield.option(nargs=2, default=None)
134
145
  ```
135
146
 
136
147
  #### Declarations
@@ -145,6 +156,7 @@ mm: str | None = cmdfield.option(decls="--mm") # --mm
145
156
  nn: str | None = cmdfield.option(decls="-oo") # -oo
146
157
  pp: str | None = cmdfield.option(decls=("--rr", "-ss")) # --rr, -ss
147
158
  tt: str | None = cmdfield.option(more_decls="-uu") # -tt, -uu
159
+ vv_ww: str | None = cmdfield.option() # -vv-ww OR --vv-ww
148
160
  ```
149
161
 
150
162
 
@@ -192,6 +204,7 @@ mm: bool = cmdfield.flag(decls="--mm") # --mm
192
204
  nn: bool = cmdfield.flag(decls="-oo") # -oo
193
205
  pp: bool = cmdfield.flag(decls=("--rr", "-ss")) # --rr, -ss
194
206
  tt: bool = cmdfield.flag(more_decls="-uu") # -tt, -uu
207
+ vv_ww: bool = cmdfield.flag() # -vv-ww OR --vv-ww
195
208
  ```
196
209
 
197
210
 
@@ -43,6 +43,9 @@ class MyApplication(cmd2.Cmd):
43
43
  * `default` <br/>
44
44
  The arguments default value if not specified.
45
45
  <br/> (Providing a default value makes the argument optional.)
46
+ * `nargs` <br/>
47
+ The number of command-line values to be consumed.
48
+ <br/> https://docs.python.org/3/library/argparse.html#nargs
46
49
  * `type` <br/>
47
50
  Explicitly specifies the `type` to be used by `argparse`.
48
51
  <br/> https://docs.python.org/3/library/argparse.html#type
@@ -61,6 +64,8 @@ arg: str | None = cmdfield.argument(
61
64
  },
62
65
  default=None,
63
66
  )
67
+ args: list[str] = cmdfield.argument()
68
+ more: list[str] = cmdfield.argument(nargs="+")
64
69
  ```
65
70
 
66
71
 
@@ -83,6 +88,9 @@ arg: str | None = cmdfield.argument(
83
88
  Explicitly specifies all option declarations.
84
89
  * `more_decls` <br/>
85
90
  Specifies additional option declarations.
91
+ * `nargs` <br/>
92
+ The number of command-line values to be consumed.
93
+ <br/> https://docs.python.org/3/library/argparse.html#nargs
86
94
  * `type` <br/>
87
95
  Explicitly specifies the `type` to be used by `argparse`.
88
96
  <br/> https://docs.python.org/3/library/argparse.html#type
@@ -98,6 +106,8 @@ arg: str | None = cmdfield.argument(
98
106
  xx: str | None = cmdfield.option()
99
107
  yy: int | None = cmdfield.option([1, 2, 3])
100
108
  zz: str = cmdfield.option(required=True)
109
+ hh: list[str] | None = cmdfield.option(default=None)
110
+ qq: list[int] | None = cmdfield.option(nargs=2, default=None)
101
111
  ```
102
112
 
103
113
  #### Declarations
@@ -112,6 +122,7 @@ mm: str | None = cmdfield.option(decls="--mm") # --mm
112
122
  nn: str | None = cmdfield.option(decls="-oo") # -oo
113
123
  pp: str | None = cmdfield.option(decls=("--rr", "-ss")) # --rr, -ss
114
124
  tt: str | None = cmdfield.option(more_decls="-uu") # -tt, -uu
125
+ vv_ww: str | None = cmdfield.option() # -vv-ww OR --vv-ww
115
126
  ```
116
127
 
117
128
 
@@ -159,6 +170,7 @@ mm: bool = cmdfield.flag(decls="--mm") # --mm
159
170
  nn: bool = cmdfield.flag(decls="-oo") # -oo
160
171
  pp: bool = cmdfield.flag(decls=("--rr", "-ss")) # --rr, -ss
161
172
  tt: bool = cmdfield.flag(more_decls="-uu") # -tt, -uu
173
+ vv_ww: bool = cmdfield.flag() # -vv-ww OR --vv-ww
162
174
  ```
163
175
 
164
176
 
@@ -36,14 +36,15 @@ class _cmdcommand(type):
36
36
  ]:
37
37
  """Decorate as command function."""
38
38
 
39
- if hasattr(argtype, "_cmdargparse_command_decorator"):
40
- return getattr(argtype, "_cmdargparse_command_decorator")
39
+ if "_cmdargparse_command_decorator" in argtype.__dict__:
40
+ return argtype.__dict__["_cmdargparse_command_decorator"]
41
41
 
42
42
  parser = ArgumentParser()
43
43
 
44
44
  _dcfields = dataclasses.fields(
45
45
  argtype # pyright: ignore[reportArgumentType]
46
46
  )
47
+ _fieldtypes = typing.get_type_hints(argtype, include_extras=True)
47
48
 
48
49
  default_form: _DeclFormSpecifier
49
50
  default_form = getattr(argtype, "_cmdargparse_default_form")
@@ -63,7 +64,7 @@ class _cmdcommand(type):
63
64
  )
64
65
 
65
66
  args: dict[str, Any]
66
- args = field.metadata["args"]
67
+ args = dict(field.metadata["args"])
67
68
 
68
69
  assert "dest" not in args, (
69
70
  "Specifying 'dest' directly is not supported."
@@ -86,8 +87,11 @@ class _cmdcommand(type):
86
87
  continue
87
88
 
88
89
  # Resolve the type from the fields type annotation.
90
+ (_type, _nargs) = argparse_type(_fieldtypes[field.name])
89
91
  if args.get("type", None) is None:
90
- args["type"] = argparse_type(field.type)
92
+ args["type"] = _type
93
+ if args.get("nargs", None) is None and _nargs is not None:
94
+ args["nargs"] = _nargs
91
95
 
92
96
  # Remove custom unspecified arguments.
93
97
  if args.get("choicesmap", None) is None:
@@ -168,7 +172,7 @@ def argparse_name_or_flags(
168
172
  return tuple(
169
173
  _decl
170
174
  for _decl in (
171
- decl or (form + field),
175
+ decl or (form + field.replace("_", "-")),
172
176
  altdecl,
173
177
  *more_decls,
174
178
  )
@@ -176,13 +180,10 @@ def argparse_name_or_flags(
176
180
  )
177
181
 
178
182
 
179
- def argparse_type(type: Any, /) -> Type[Any]:
180
- if isinstance(type, str):
181
- raise TypeError("forward reference type annotations are not supported")
182
-
183
+ def argparse_type(type: Any, /) -> Tuple[Type[Any], str | None]:
183
184
  origin = typing.get_origin(type)
184
185
  if origin is None:
185
- return type
186
+ return (type, None)
186
187
 
187
188
  if origin is typing.Annotated:
188
189
  (argtype, *_) = typing.get_args(type)
@@ -192,9 +193,12 @@ def argparse_type(type: Any, /) -> Type[Any]:
192
193
  # should be passed to the `argparse` module.
193
194
  if isinstance(type, types.UnionType):
194
195
  (argtype, *_) = typing.get_args(type)
195
- return argtype
196
+ return argparse_type(argtype)
196
197
  elif origin is typing.Union:
197
198
  (argtype, *_) = typing.get_args(type)
198
- return argtype
199
+ return argparse_type(argtype)
200
+ elif origin is list:
201
+ (argtype, *_) = typing.get_args(type)
202
+ return (argparse_type(argtype)[0], "*")
199
203
 
200
204
  raise TypeError("unsupported type annotation")
@@ -112,6 +112,8 @@ class _cmdfield(type):
112
112
 
113
113
  class _ArgumentArgs(TypedDict, total=False):
114
114
 
115
+ nargs: Annotated[int, "N"] | Literal["?", "*", "+"]
116
+
115
117
  type: Annotated[Any, Callable[[str], Annotated[Any, "FieldType"]]]
116
118
 
117
119
  help: str
@@ -180,6 +182,9 @@ class _cmdfield(type):
180
182
  The arguments default value if not specified.
181
183
  (Providing a default value makes the argument optional.)
182
184
 
185
+ :param nargs:
186
+ The number of command-line values to be consumed.
187
+ <br/> https://docs.python.org/3/library/argparse.html#nargs
183
188
  :param type:
184
189
  Explicitly specifies the `type` to be used by `argparse`.
185
190
  <br/> https://docs.python.org/3/library/argparse.html#type
@@ -192,10 +197,10 @@ class _cmdfield(type):
192
197
  """
193
198
  return _argparse(
194
199
  None,
195
- nargs=("?" if not isunset(default) else None),
196
200
  choices=choices,
197
201
  choicesmap=choicesmap,
198
202
  default=on_unset(default, None),
203
+ nargs=args.get("nargs", ("?" if not isunset(default) else None)),
199
204
  type=args.get("type", None),
200
205
  help=args.get("help", None),
201
206
  metavar=args.get("helpvar", None),
@@ -209,6 +214,8 @@ class _cmdfield(type):
209
214
  decls: Tuple[str, str] | str
210
215
  more_decls: Sequence[str] | str
211
216
 
217
+ nargs: Annotated[int, "N"] | Literal["?", "*", "+"]
218
+
212
219
  type: Annotated[Any, Callable[[str], Annotated[Any, "FieldType"]]]
213
220
 
214
221
  required: bool
@@ -388,6 +395,9 @@ class _cmdfield(type):
388
395
  :param more_decls:
389
396
  Specifies additional option declarations.
390
397
 
398
+ :param nargs:
399
+ The number of command-line values to be consumed.
400
+ <br/> https://docs.python.org/3/library/argparse.html#nargs
391
401
  :param type:
392
402
  Explicitly specifies the `type` to be used by `argparse`.
393
403
  <br/> https://docs.python.org/3/library/argparse.html#type
@@ -431,6 +441,7 @@ class _cmdfield(type):
431
441
  choicesmap=choicesmap,
432
442
  default=on_unset(default, None),
433
443
  required=args.get("required", False),
444
+ nargs=args.get("nargs", None),
434
445
  type=args.get("type", None),
435
446
  help=args.get("help", None),
436
447
  metavar=args.get("helpvar", None),
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cmdargparse
3
- Version: 0.2.0
3
+ Version: 0.3.1
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)
@@ -13,9 +13,10 @@ Classifier: Intended Audience :: Developers
13
13
  Classifier: Intended Audience :: System Administrators
14
14
  Classifier: Operating System :: OS Independent
15
15
  Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.13
16
17
  Classifier: Programming Language :: Python :: 3.14
17
18
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
- Requires-Python: >=3.14
19
+ Requires-Python: >=3.13
19
20
  Description-Content-Type: text/markdown
20
21
  License-File: LICENSE
21
22
  Requires-Dist: cmd2~=4.2
@@ -76,6 +77,9 @@ class MyApplication(cmd2.Cmd):
76
77
  * `default` <br/>
77
78
  The arguments default value if not specified.
78
79
  <br/> (Providing a default value makes the argument optional.)
80
+ * `nargs` <br/>
81
+ The number of command-line values to be consumed.
82
+ <br/> https://docs.python.org/3/library/argparse.html#nargs
79
83
  * `type` <br/>
80
84
  Explicitly specifies the `type` to be used by `argparse`.
81
85
  <br/> https://docs.python.org/3/library/argparse.html#type
@@ -94,6 +98,8 @@ arg: str | None = cmdfield.argument(
94
98
  },
95
99
  default=None,
96
100
  )
101
+ args: list[str] = cmdfield.argument()
102
+ more: list[str] = cmdfield.argument(nargs="+")
97
103
  ```
98
104
 
99
105
 
@@ -116,6 +122,9 @@ arg: str | None = cmdfield.argument(
116
122
  Explicitly specifies all option declarations.
117
123
  * `more_decls` <br/>
118
124
  Specifies additional option declarations.
125
+ * `nargs` <br/>
126
+ The number of command-line values to be consumed.
127
+ <br/> https://docs.python.org/3/library/argparse.html#nargs
119
128
  * `type` <br/>
120
129
  Explicitly specifies the `type` to be used by `argparse`.
121
130
  <br/> https://docs.python.org/3/library/argparse.html#type
@@ -131,6 +140,8 @@ arg: str | None = cmdfield.argument(
131
140
  xx: str | None = cmdfield.option()
132
141
  yy: int | None = cmdfield.option([1, 2, 3])
133
142
  zz: str = cmdfield.option(required=True)
143
+ hh: list[str] | None = cmdfield.option(default=None)
144
+ qq: list[int] | None = cmdfield.option(nargs=2, default=None)
134
145
  ```
135
146
 
136
147
  #### Declarations
@@ -145,6 +156,7 @@ mm: str | None = cmdfield.option(decls="--mm") # --mm
145
156
  nn: str | None = cmdfield.option(decls="-oo") # -oo
146
157
  pp: str | None = cmdfield.option(decls=("--rr", "-ss")) # --rr, -ss
147
158
  tt: str | None = cmdfield.option(more_decls="-uu") # -tt, -uu
159
+ vv_ww: str | None = cmdfield.option() # -vv-ww OR --vv-ww
148
160
  ```
149
161
 
150
162
 
@@ -192,6 +204,7 @@ mm: bool = cmdfield.flag(decls="--mm") # --mm
192
204
  nn: bool = cmdfield.flag(decls="-oo") # -oo
193
205
  pp: bool = cmdfield.flag(decls=("--rr", "-ss")) # --rr, -ss
194
206
  tt: bool = cmdfield.flag(more_decls="-uu") # -tt, -uu
207
+ vv_ww: bool = cmdfield.flag() # -vv-ww OR --vv-ww
195
208
  ```
196
209
 
197
210
 
@@ -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.2.0",
10
+ version="0.3.1",
11
11
  description="A declarative way to define `cmd2` argument parsers.",
12
12
  long_description=README,
13
13
  long_description_content_type="text/markdown",
@@ -15,8 +15,7 @@ setup(
15
15
  url="https://github.com/krnd/cmdargparse",
16
16
  license="MIT",
17
17
  packages=find_packages(include=["cmdargparse", "cmdargparse.*"]),
18
- # Tested with Python 3.14 only.
19
- python_requires=">=3.14",
18
+ python_requires=">=3.13",
20
19
  install_requires=[
21
20
  ("cmd2" "~=4.2"),
22
21
  ],
@@ -36,6 +35,7 @@ setup(
36
35
  "Intended Audience :: System Administrators",
37
36
  "Operating System :: OS Independent",
38
37
  "Programming Language :: Python :: 3 :: Only",
38
+ "Programming Language :: Python :: 3.13",
39
39
  "Programming Language :: Python :: 3.14",
40
40
  "Topic :: Software Development :: Libraries :: Python Modules",
41
41
  ],
File without changes
File without changes
File without changes