elemctl 0.52.1__tar.gz → 0.53.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 (83) hide show
  1. {elemctl-0.52.1 → elemctl-0.53.0}/PKG-INFO +7 -1
  2. {elemctl-0.52.1 → elemctl-0.53.0}/README.md +6 -0
  3. {elemctl-0.52.1 → elemctl-0.53.0}/docs/changelog.md +8 -0
  4. {elemctl-0.52.1 → elemctl-0.53.0}/docs/changelog.ru.md +8 -0
  5. {elemctl-0.52.1 → elemctl-0.53.0}/docs/mcp.md +6 -0
  6. {elemctl-0.52.1 → elemctl-0.53.0}/docs/mcp.ru.md +6 -0
  7. {elemctl-0.52.1 → elemctl-0.53.0}/src/elemctl/__init__.py +1 -1
  8. {elemctl-0.52.1 → elemctl-0.53.0}/src/elemctl/cli.py +44 -0
  9. {elemctl-0.52.1 → elemctl-0.53.0}/src/elemctl/i18n.py +6 -0
  10. {elemctl-0.52.1 → elemctl-0.53.0}/src/elemctl/plugins.py +26 -8
  11. {elemctl-0.52.1 → elemctl-0.53.0}/src/elemctl.egg-info/PKG-INFO +7 -1
  12. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_plugins.py +78 -1
  13. {elemctl-0.52.1 → elemctl-0.53.0}/.env.example +0 -0
  14. {elemctl-0.52.1 → elemctl-0.53.0}/LICENSE +0 -0
  15. {elemctl-0.52.1 → elemctl-0.53.0}/MANIFEST.in +0 -0
  16. {elemctl-0.52.1 → elemctl-0.53.0}/NOTICE +0 -0
  17. {elemctl-0.52.1 → elemctl-0.53.0}/ORIGIN.md +0 -0
  18. {elemctl-0.52.1 → elemctl-0.53.0}/docs/SPEC.md +0 -0
  19. {elemctl-0.52.1 → elemctl-0.53.0}/docs/SPEC.ru.md +0 -0
  20. {elemctl-0.52.1 → elemctl-0.53.0}/docs/cli.md +0 -0
  21. {elemctl-0.52.1 → elemctl-0.53.0}/docs/cli.ru.md +0 -0
  22. {elemctl-0.52.1 → elemctl-0.53.0}/docs/config.md +0 -0
  23. {elemctl-0.52.1 → elemctl-0.53.0}/docs/config.ru.md +0 -0
  24. {elemctl-0.52.1 → elemctl-0.53.0}/docs/index.md +0 -0
  25. {elemctl-0.52.1 → elemctl-0.53.0}/docs/index.ru.md +0 -0
  26. {elemctl-0.52.1 → elemctl-0.53.0}/docs/library.md +0 -0
  27. {elemctl-0.52.1 → elemctl-0.53.0}/docs/library.ru.md +0 -0
  28. {elemctl-0.52.1 → elemctl-0.53.0}/docs/platform.md +0 -0
  29. {elemctl-0.52.1 → elemctl-0.53.0}/docs/platform.ru.md +0 -0
  30. {elemctl-0.52.1 → elemctl-0.53.0}/pyproject.toml +0 -0
  31. {elemctl-0.52.1 → elemctl-0.53.0}/setup.cfg +0 -0
  32. {elemctl-0.52.1 → elemctl-0.53.0}/src/elemctl/__main__.py +0 -0
  33. {elemctl-0.52.1 → elemctl-0.53.0}/src/elemctl/auth.py +0 -0
  34. {elemctl-0.52.1 → elemctl-0.53.0}/src/elemctl/build.py +0 -0
  35. {elemctl-0.52.1 → elemctl-0.53.0}/src/elemctl/client.py +0 -0
  36. {elemctl-0.52.1 → elemctl-0.53.0}/src/elemctl/config.py +0 -0
  37. {elemctl-0.52.1 → elemctl-0.53.0}/src/elemctl/deploy.py +0 -0
  38. {elemctl-0.52.1 → elemctl-0.53.0}/src/elemctl/errors.py +0 -0
  39. {elemctl-0.52.1 → elemctl-0.53.0}/src/elemctl/mcp_server.py +0 -0
  40. {elemctl-0.52.1 → elemctl-0.53.0}/src/elemctl/probe.py +0 -0
  41. {elemctl-0.52.1 → elemctl-0.53.0}/src/elemctl/registry.py +0 -0
  42. {elemctl-0.52.1 → elemctl-0.53.0}/src/elemctl/schema.py +0 -0
  43. {elemctl-0.52.1 → elemctl-0.53.0}/src/elemctl/selfupdate.py +0 -0
  44. {elemctl-0.52.1 → elemctl-0.53.0}/src/elemctl/transport.py +0 -0
  45. {elemctl-0.52.1 → elemctl-0.53.0}/src/elemctl/versions.py +0 -0
  46. {elemctl-0.52.1 → elemctl-0.53.0}/src/elemctl.egg-info/SOURCES.txt +0 -0
  47. {elemctl-0.52.1 → elemctl-0.53.0}/src/elemctl.egg-info/dependency_links.txt +0 -0
  48. {elemctl-0.52.1 → elemctl-0.53.0}/src/elemctl.egg-info/entry_points.txt +0 -0
  49. {elemctl-0.52.1 → elemctl-0.53.0}/src/elemctl.egg-info/requires.txt +0 -0
  50. {elemctl-0.52.1 → elemctl-0.53.0}/src/elemctl.egg-info/top_level.txt +0 -0
  51. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_app_export.py +0 -0
  52. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_app_users.py +0 -0
  53. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_build.py +0 -0
  54. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_build_project.py +0 -0
  55. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_changelog_link.py +0 -0
  56. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_cli.py +0 -0
  57. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_cli_docs.py +0 -0
  58. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_client.py +0 -0
  59. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_config.py +0 -0
  60. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_conventions.py +0 -0
  61. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_deploy.py +0 -0
  62. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_docs_coverage.py +0 -0
  63. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_extension_export.py +0 -0
  64. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_extension_verify.py +0 -0
  65. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_extract_adapter.py +0 -0
  66. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_i18n.py +0 -0
  67. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_mcp.py +0 -0
  68. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_numbering_jumps.py +0 -0
  69. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_probe.py +0 -0
  70. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_probe_cleanup.py +0 -0
  71. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_rebuild_docs.py +0 -0
  72. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_registry.py +0 -0
  73. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_release_notes.py +0 -0
  74. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_schema.py +0 -0
  75. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_selfupdate.py +0 -0
  76. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_selfupdate_latest.py +0 -0
  77. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_server_starting.py +0 -0
  78. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_token_access.py +0 -0
  79. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_transport.py +0 -0
  80. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_user_lists.py +0 -0
  81. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_versions.py +0 -0
  82. {elemctl-0.52.1 → elemctl-0.53.0}/tests/test_workflows.py +0 -0
  83. {elemctl-0.52.1 → elemctl-0.53.0}/tools/extract_adapter.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: elemctl
3
- Version: 0.52.1
3
+ Version: 0.53.0
4
4
  Summary: CLI, MCP server and library for managing 1C:Element applications through Console API v2: builds from source, deployment with verification and temporary compilation probes
5
5
  Author: KeyFire
6
6
  License-Expression: MIT
@@ -577,6 +577,12 @@ A positional argument can have a CLI option alias:
577
577
  rejected. For a required argument, omitting both is also an error. Without
578
578
  `cli_alias`, the argument remains positional.
579
579
 
580
+ `Argument("--out", cli_prefix_alias="--report")` accepts `--out` after the
581
+ subcommand and `--report` before or after it. Both options set the same `out`
582
+ parameter. Supplying different values for a single-value option is a parsing
583
+ error. MCP keeps the `out` parameter. Use `hasattr(plugins.Argument,
584
+ "cli_prefix_alias")` when supporting cores without this field.
585
+
580
586
  `Argument("--file", multiple=True)` accepts multiple values:
581
587
  `elemctl wiki-attach --file a.png --file b.png` passes `["a.png", "b.png"]`
582
588
  to the handler in command-line order. If the option is absent, the declared
@@ -545,6 +545,12 @@ A positional argument can have a CLI option alias:
545
545
  rejected. For a required argument, omitting both is also an error. Without
546
546
  `cli_alias`, the argument remains positional.
547
547
 
548
+ `Argument("--out", cli_prefix_alias="--report")` accepts `--out` after the
549
+ subcommand and `--report` before or after it. Both options set the same `out`
550
+ parameter. Supplying different values for a single-value option is a parsing
551
+ error. MCP keeps the `out` parameter. Use `hasattr(plugins.Argument,
552
+ "cli_prefix_alias")` when supporting cores without this field.
553
+
548
554
  `Argument("--file", multiple=True)` accepts multiple values:
549
555
  `elemctl wiki-attach --file a.png --file b.png` passes `["a.png", "b.png"]`
550
556
  to the handler in command-line order. If the option is absent, the declared
@@ -22,6 +22,14 @@ Run `python scripts/changelog-link.py <number>` to add the link and rebuild
22
22
  the generated site pages. This updates both language editions and their mirrors
23
23
  together.
24
24
 
25
+ ## 2026-11-07 – 0.53.0
26
+
27
+ ### Added
28
+
29
+ - Plugins can accept an option alias before or after the subcommand. For example,
30
+ `--report` can set the same parameter as `--out`.
31
+ ([#63](https://github.com/keyfire/elemctl/pull/63))
32
+
25
33
  ## 2026-11-06 – 0.52.1
26
34
 
27
35
  ### Fixed
@@ -22,6 +22,14 @@ sidebar:
22
22
  сгенерированные страницы сайта. Запускайте ее вместо ручного добавления ссылки,
23
23
  чтобы одновременно обновить обе языковые версии и их зеркала.
24
24
 
25
+ ## 07.11.2026 – 0.53.0
26
+
27
+ ### Добавлено
28
+
29
+ - Плагин может принимать синоним ключа до и после имени подкоманды. Например,
30
+ `--report` может задавать тот же параметр, что и `--out`.
31
+ ([#63](https://github.com/keyfire/elemctl/pull/63))
32
+
25
33
  ## 06.11.2026 – 0.52.1
26
34
 
27
35
  ### Исправлено
@@ -234,6 +234,12 @@ A positional argument can have a CLI option alias:
234
234
  rejected. For a required argument, omitting both is also an error. Without
235
235
  `cli_alias`, the argument remains positional.
236
236
 
237
+ `Argument("--out", cli_prefix_alias="--report")` accepts `--out` after the
238
+ subcommand and `--report` before or after it. Both options set the same `out`
239
+ parameter. Supplying different values for a single-value option is a parsing
240
+ error. MCP keeps the `out` parameter. Use `hasattr(plugins.Argument,
241
+ "cli_prefix_alias")` when supporting cores without this field.
242
+
237
243
  `Argument("--file", multiple=True)` accepts multiple values:
238
244
  `elemctl wiki-attach --file a.png --file b.png` passes `["a.png", "b.png"]`
239
245
  to the handler in command-line order. If the option is absent, the declared
@@ -241,6 +241,12 @@ def commands():
241
241
  отсутствие обеих форм также считается ошибкой. Без `cli_alias` используется
242
242
  обычный позиционный аргумент.
243
243
 
244
+ `Argument("--out", cli_prefix_alias="--report")` принимает `--out` после
245
+ имени подкоманды и `--report` до или после него. Оба ключа задают один параметр
246
+ `out`. Разные значения одиночной опции вызывают ошибку разбора. В MCP остается
247
+ параметр `out`. Для совместимости с ядром без этого поля проверяйте
248
+ `hasattr(plugins.Argument, "cli_prefix_alias")`.
249
+
244
250
  Параметр `Argument("--file", multiple=True)` принимает несколько значений:
245
251
  `elemctl wiki-attach --file a.png --file b.png`. В обработчик передается
246
252
  `["a.png", "b.png"]` в порядке командной строки. Если ключ не указан, передается
@@ -18,7 +18,7 @@ from .errors import (
18
18
  TransportError,
19
19
  )
20
20
 
21
- __version__ = "0.52.1"
21
+ __version__ = "0.53.0"
22
22
 
23
23
  __all__ = [
24
24
  "ApiError",
@@ -1811,6 +1811,10 @@ def add_plugin_commands(sub, discover=None):
1811
1811
  for argument in command.arguments:
1812
1812
  if argument.cli_alias:
1813
1813
  _add_aliased_positional(parser, argument)
1814
+ elif argument.cli_prefix_alias:
1815
+ parser.add_argument(
1816
+ argument.name, argument.cli_prefix_alias, **_argument_kwargs(argument)
1817
+ )
1814
1818
  else:
1815
1819
  parser.add_argument(argument.name, **_argument_kwargs(argument))
1816
1820
  parser.set_defaults(handler=_plugin_handler(command), plugin_command=command)
@@ -1949,6 +1953,45 @@ def _hoist_global_options(argv):
1949
1953
  return hoisted + rest
1950
1954
 
1951
1955
 
1956
+ def _move_plugin_prefix_aliases(argv, commands):
1957
+ """Move leading aliases after the command that declares them."""
1958
+ command_aliases = {
1959
+ command.name: {arg.cli_prefix_alias for arg in command.arguments if arg.cli_prefix_alias}
1960
+ for command in commands
1961
+ }
1962
+ known = set().union(*command_aliases.values())
1963
+ if not known:
1964
+ return argv
1965
+
1966
+ # The global options already precede any command-specific arguments.
1967
+ first = 0
1968
+ while first < len(argv):
1969
+ flag, equals, _ = argv[first].partition("=")
1970
+ if flag in _GLOBAL_OPTIONS:
1971
+ first += 1 if equals else 2
1972
+ elif flag in _GLOBAL_FLAGS:
1973
+ first += 1
1974
+ else:
1975
+ break
1976
+
1977
+ index = first
1978
+ aliases = set()
1979
+ while index < len(argv):
1980
+ flag, equals, _ = argv[index].partition("=")
1981
+ if flag not in known:
1982
+ break
1983
+ aliases.add(flag)
1984
+ index += 1
1985
+ if not equals:
1986
+ if index == len(argv) or argv[index] == "--":
1987
+ return argv
1988
+ index += 1
1989
+
1990
+ if aliases and index < len(argv) and aliases <= command_aliases.get(argv[index], set()):
1991
+ return argv[:first] + [argv[index]] + argv[first:index] + argv[index + 1:]
1992
+ return argv
1993
+
1994
+
1952
1995
  def _requested_command(argv):
1953
1996
  """The subcommand a call names: the first word after the global options ("" for none).
1954
1997
 
@@ -2531,6 +2574,7 @@ def main(argv=None):
2531
2574
  parser = build_parser()
2532
2575
  except ElemctlError as error:
2533
2576
  return _fail({"error": str(error)})
2577
+ argv = _move_plugin_prefix_aliases(argv, parser.get_default("plugin_commands") or ())
2534
2578
  # A plugin that did not load is left out of the parser rather than taking it down.
2535
2579
  # A call to a command that is missing while plugins failed gets the usual JSON
2536
2580
  # refusal naming them: the command may well have been theirs.
@@ -842,6 +842,12 @@ MESSAGES = {
842
842
  "cli_alias while not being positional itself – a synonym only makes sense for a "
843
843
  "positional argument, an option already has a name to call it by",
844
844
  },
845
+ "plugins.prefix-alias-needs-valued-option": {
846
+ "ru": "аргумент {argument} команды '{name}' плагина '{where}' содержит неверный "
847
+ "cli_prefix_alias '{alias}': нужен ключ с префиксом -- для опции со значением",
848
+ "en": "argument {argument} of command '{name}' from plugin '{where}' has an invalid "
849
+ "cli_prefix_alias '{alias}': expected a --option alias for an option that takes a value",
850
+ },
845
851
  "plugins.alias-not-an-option": {
846
852
  "ru": "cli_alias '{alias}' аргумента {argument} команды '{name}' плагина '{where}' "
847
853
  "обязан начинаться с дефиса, как имя опции",
@@ -182,6 +182,10 @@ class Argument:
182
182
  option, one that does not start with a dash, or one that collides with
183
183
  another argument's own flag.
184
184
 
185
+ cli_prefix_alias is a CLI-only alias for an option that takes a value. It is
186
+ accepted before or after this subcommand. Both option names fill the same
187
+ parameter and follow the same rules for repeated values.
188
+
185
189
  multiple - the argument takes several values, and the command gets the list of
186
190
  what was given, in the order of the command line. An option may be given more
187
191
  than once: "wiki-attach --file a.png --file b.png" hands over ["a.png",
@@ -213,6 +217,7 @@ class Argument:
213
217
  choices: tuple = ()
214
218
  cli_alias: str = ""
215
219
  multiple: bool = False
220
+ cli_prefix_alias: str = ""
216
221
 
217
222
  @property
218
223
  def is_option(self) -> bool:
@@ -330,6 +335,7 @@ class Command:
330
335
  # list of taken names this refusal offers leaves the global options out.
331
336
  kept_names = ", ".join(sorted(taken_names - set(reserved)))
332
337
  seen = set()
338
+ flags = []
333
339
  for argument in self.arguments:
334
340
  if not isinstance(argument, Argument):
335
341
  raise PluginError(i18n.t(
@@ -375,11 +381,23 @@ class Command:
375
381
  where=where, name=self.name, argument=argument.name,
376
382
  alias=argument.cli_alias,
377
383
  ))
384
+ prefix_alias = argument.cli_prefix_alias
385
+ if prefix_alias and (
386
+ not argument.is_option or argument.type is bool
387
+ or not prefix_alias.startswith("--") or len(prefix_alias) == 2
388
+ or "=" in prefix_alias or any(char.isspace() for char in prefix_alias)
389
+ ):
390
+ raise PluginError(i18n.t(
391
+ "plugins.prefix-alias-needs-valued-option",
392
+ where=where, name=self.name, argument=argument.name, alias=prefix_alias,
393
+ ))
378
394
  clash = reserved.get(argument.dest)
379
395
  label = argument.name
380
- if clash is None and argument.cli_alias in reserved.values():
381
- clash = argument.cli_alias
382
- label = f"{argument.name} (cli_alias {argument.cli_alias})"
396
+ alias = argument.cli_alias or prefix_alias
397
+ if clash is None and alias in reserved.values():
398
+ clash = alias
399
+ field = "cli_alias" if argument.cli_alias else "cli_prefix_alias"
400
+ label = f"{argument.name} ({field} {alias})"
383
401
  if clash is not None:
384
402
  raise PluginError(i18n.t(
385
403
  "plugins.global-option-taken",
@@ -392,9 +410,11 @@ class Command:
392
410
  where=where, name=self.name, argument=argument.name,
393
411
  dest=argument.dest, names=kept_names,
394
412
  ))
395
- flags = [argument.name] if argument.is_option else []
396
- flags += [argument.cli_alias] if argument.cli_alias else []
397
- for flag in flags:
413
+ argument_flags = [argument.name] if argument.is_option else []
414
+ if alias:
415
+ argument_flags.append(alias)
416
+ flags.extend(argument_flags)
417
+ for flag in argument_flags:
398
418
  if flag in taken_options:
399
419
  raise PluginError(i18n.t(
400
420
  "plugins.option-taken",
@@ -407,8 +427,6 @@ class Command:
407
427
  # surface as a bare argparse.ArgumentError the moment the CLI parser is built -
408
428
  # not a PluginError, and not only for the plugin's own command, since the parser
409
429
  # is shared by the whole CLI.
410
- flags = [a.name for a in self.arguments if a.is_option]
411
- flags += [a.cli_alias for a in self.arguments if a.cli_alias]
412
430
  duplicates = {flag for flag in flags if flags.count(flag) > 1}
413
431
  if duplicates:
414
432
  raise PluginError(i18n.t(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: elemctl
3
- Version: 0.52.1
3
+ Version: 0.53.0
4
4
  Summary: CLI, MCP server and library for managing 1C:Element applications through Console API v2: builds from source, deployment with verification and temporary compilation probes
5
5
  Author: KeyFire
6
6
  License-Expression: MIT
@@ -577,6 +577,12 @@ A positional argument can have a CLI option alias:
577
577
  rejected. For a required argument, omitting both is also an error. Without
578
578
  `cli_alias`, the argument remains positional.
579
579
 
580
+ `Argument("--out", cli_prefix_alias="--report")` accepts `--out` after the
581
+ subcommand and `--report` before or after it. Both options set the same `out`
582
+ parameter. Supplying different values for a single-value option is a parsing
583
+ error. MCP keeps the `out` parameter. Use `hasattr(plugins.Argument,
584
+ "cli_prefix_alias")` when supporting cores without this field.
585
+
580
586
  `Argument("--file", multiple=True)` accepts multiple values:
581
587
  `elemctl wiki-attach --file a.png --file b.png` passes `["a.png", "b.png"]`
582
588
  to the handler in command-line order. If the option is absent, the declared
@@ -207,6 +207,12 @@ def test_command_declaration_is_checked_at_discovery(monkeypatch):
207
207
  _command(arguments=["--stand"]),
208
208
  _command(arguments=[plugins.Argument("--stand", cli_alias="--s")]), # alias on an option
209
209
  _command(arguments=[plugins.Argument("stand", cli_alias="page")]), # alias without a dash
210
+ _command(arguments=[plugins.Argument("report", cli_prefix_alias="--file")]),
211
+ _command(arguments=[plugins.Argument("--force", type=bool, cli_prefix_alias="--yes")]),
212
+ _command(arguments=[plugins.Argument("--out", cli_prefix_alias="--json")]),
213
+ _command(arguments=[
214
+ plugins.Argument("--out", cli_prefix_alias="--file"), plugins.Argument("--file"),
215
+ ]),
210
216
  _command(arguments=[ # alias collides with another argument's own flag
211
217
  plugins.Argument("stand", cli_alias="--force"), plugins.Argument("--force", type=bool),
212
218
  ]),
@@ -345,7 +351,8 @@ def test_an_option_is_refused_by_its_value_name_as_well(monkeypatch):
345
351
  plugins.Argument("--help"),
346
352
  plugins.Argument("-h", type=bool),
347
353
  plugins.Argument("stand", required=False, cli_alias="--help"),
348
- ], ids=["option-help", "flag-h", "alias-help"])
354
+ plugins.Argument("--out", cli_prefix_alias="--help"),
355
+ ], ids=["option-help", "flag-h", "alias-help", "prefix-alias-help"])
349
356
  def test_a_plugin_may_not_declare_the_help_of_its_subcommand(monkeypatch, argument):
350
357
  """The subparser answers -h and --help itself, and argparse refused the second one with a
351
358
  bare ArgumentError while the parser of the whole CLI was being built."""
@@ -630,6 +637,76 @@ def test_cli_plugin_command_with_a_cli_alias_takes_either_form(monkeypatch, caps
630
637
  assert json.loads(capsys.readouterr().out) == {"page": "123"}
631
638
 
632
639
 
640
+ @pytest.mark.parametrize("argv", [
641
+ ["wiki-export", "--out", "report.json"],
642
+ ["wiki-export", "--report", "report.json"],
643
+ ["--report", "report.json", "wiki-export", "--lang", "en"],
644
+ ["--report=report.json", "wiki-export"],
645
+ ["--report", "report.json", "wiki-export", "--out", "report.json"],
646
+ ])
647
+ def test_cli_plugin_option_accepts_its_prefix_alias(monkeypatch, capsys, argv):
648
+ _with_commands(monkeypatch, _command(
649
+ name="wiki-export",
650
+ arguments=[plugins.Argument("--out", cli_prefix_alias="--report")],
651
+ handler=lambda context, out: {"file": out},
652
+ ))
653
+
654
+ assert cli.main(argv) == 0
655
+ assert json.loads(capsys.readouterr().out) == {"file": "report.json"}
656
+
657
+
658
+ def test_cli_plugin_multiple_option_keeps_prefix_alias_values_in_order(monkeypatch, capsys):
659
+ _with_commands(monkeypatch, _command(
660
+ name="wiki-export",
661
+ arguments=[plugins.Argument("--out", cli_prefix_alias="--report", multiple=True)],
662
+ handler=lambda context, out: {"files": out},
663
+ ))
664
+
665
+ assert cli.main([
666
+ "--report=first.json", "--lang=en", "--report", "second.json",
667
+ "wiki-export", "--out", "third.json", "--report", "fourth.json",
668
+ ]) == 0
669
+ assert json.loads(capsys.readouterr().out) == {
670
+ "files": ["first.json", "second.json", "third.json", "fourth.json"],
671
+ }
672
+
673
+
674
+ def test_cli_plugin_option_prefix_alias_shares_help_and_conflict_checks(monkeypatch, capsys):
675
+ _with_commands(monkeypatch, _command(
676
+ name="wiki-export",
677
+ arguments=[plugins.Argument("--out", cli_prefix_alias="--report")],
678
+ handler=lambda context, out: pytest.fail("invalid options reached the handler"),
679
+ ))
680
+
681
+ with pytest.raises(SystemExit) as help_exit:
682
+ cli.main(["wiki-export", "--help"])
683
+ assert help_exit.value.code == 0
684
+ help_text = capsys.readouterr().out
685
+ assert "--out" in help_text and "--report" in help_text
686
+
687
+ with pytest.raises(SystemExit) as conflict:
688
+ cli.main(["--report", "first.json", "wiki-export", "--out", "second.json"])
689
+ assert conflict.value.code == 2
690
+ message = capsys.readouterr().err
691
+ assert "--report" in message and "--out" in message
692
+ assert "first.json" in message and "second.json" in message
693
+
694
+
695
+ def test_cli_plugin_option_prefix_alias_is_local_to_its_command(monkeypatch):
696
+ _with_commands(
697
+ monkeypatch,
698
+ _command(
699
+ name="wiki-export",
700
+ arguments=[plugins.Argument("--out", cli_prefix_alias="--report")],
701
+ ),
702
+ _command(name="wiki-get"),
703
+ )
704
+
705
+ with pytest.raises(SystemExit) as unrelated:
706
+ cli.main(["--report", "report.json", "wiki-get"])
707
+ assert unrelated.value.code == 2
708
+
709
+
633
710
  def test_cli_plugin_command_refuses_the_alias_given_twice_or_not_at_all(monkeypatch):
634
711
  """One value, one place to put it: both forms at once, or neither of a required
635
712
  argument, is a parser refusal rather than a silent pick of one over the other."""
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes