env-alias 0.7.1__tar.gz → 0.8.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 (144) hide show
  1. {env_alias-0.7.1 → env_alias-0.8.0}/PKG-INFO +7 -1
  2. {env_alias-0.7.1 → env_alias-0.8.0}/README.md +6 -0
  3. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/examples/multi-file.md +12 -6
  4. {env_alias-0.7.1 → env_alias-0.8.0}/src/env_alias/__init__.py +1 -1
  5. {env_alias-0.7.1 → env_alias-0.8.0}/src/env_alias/main.py +80 -21
  6. {env_alias-0.7.1 → env_alias-0.8.0}/tests/test_main_coverage.py +93 -2
  7. {env_alias-0.7.1 → env_alias-0.8.0}/tests/test_multi_file.py +12 -0
  8. {env_alias-0.7.1 → env_alias-0.8.0}/.agents/AGENTS.md +0 -0
  9. {env_alias-0.7.1 → env_alias-0.8.0}/.agents/context/project_context.md +0 -0
  10. {env_alias-0.7.1 → env_alias-0.8.0}/.agents/rules/dev-directory.md +0 -0
  11. {env_alias-0.7.1 → env_alias-0.8.0}/.agents/rules/environment.md +0 -0
  12. {env_alias-0.7.1 → env_alias-0.8.0}/.agents/skills/architect-review/SKILL.md +0 -0
  13. {env_alias-0.7.1 → env_alias-0.8.0}/.agents/skills/caveman/SKILL.md +0 -0
  14. {env_alias-0.7.1 → env_alias-0.8.0}/.agents/skills/code-reviewer/SKILL.md +0 -0
  15. {env_alias-0.7.1 → env_alias-0.8.0}/.agents/skills/karpathy-guidelines/SKILL.md +0 -0
  16. {env_alias-0.7.1 → env_alias-0.8.0}/.agents/skills/python-pro/SKILL.md +0 -0
  17. {env_alias-0.7.1 → env_alias-0.8.0}/.agents/skills/uv-testing/SKILL.md +0 -0
  18. {env_alias-0.7.1 → env_alias-0.8.0}/.agents/skills/vulnerability-scanner/SKILL.md +0 -0
  19. {env_alias-0.7.1 → env_alias-0.8.0}/.agents/skills/vulnerability-scanner/checklists.md +0 -0
  20. {env_alias-0.7.1 → env_alias-0.8.0}/.agents/skills/vulnerability-scanner/scripts/security_scan.py +0 -0
  21. {env_alias-0.7.1 → env_alias-0.8.0}/.agents/workflows/post-implementation-verification.md +0 -0
  22. {env_alias-0.7.1 → env_alias-0.8.0}/.agents/workflows/uv-commands.md +0 -0
  23. {env_alias-0.7.1 → env_alias-0.8.0}/.changelog/0.3.1.toml +0 -0
  24. {env_alias-0.7.1 → env_alias-0.8.0}/.changelog/0.3.3.toml +0 -0
  25. {env_alias-0.7.1 → env_alias-0.8.0}/.changelog/0.3.4.toml +0 -0
  26. {env_alias-0.7.1 → env_alias-0.8.0}/.changelog/0.3.5.toml +0 -0
  27. {env_alias-0.7.1 → env_alias-0.8.0}/.changelog/0.3.6.toml +0 -0
  28. {env_alias-0.7.1 → env_alias-0.8.0}/.changelog/0.3.7.toml +0 -0
  29. {env_alias-0.7.1 → env_alias-0.8.0}/.changelog/0.3.8.toml +0 -0
  30. {env_alias-0.7.1 → env_alias-0.8.0}/.changelog/0.4.0.toml +0 -0
  31. {env_alias-0.7.1 → env_alias-0.8.0}/.changelog/0.5.1.toml +0 -0
  32. {env_alias-0.7.1 → env_alias-0.8.0}/.changelog/0.7.0.toml +0 -0
  33. {env_alias-0.7.1 → env_alias-0.8.0}/.github/workflows/docs.yml +0 -0
  34. {env_alias-0.7.1 → env_alias-0.8.0}/.github/workflows/project-tests.yml +0 -0
  35. {env_alias-0.7.1 → env_alias-0.8.0}/.github/workflows/publish.yml +0 -0
  36. {env_alias-0.7.1 → env_alias-0.8.0}/.gitignore +0 -0
  37. {env_alias-0.7.1 → env_alias-0.8.0}/LICENSE +0 -0
  38. {env_alias-0.7.1 → env_alias-0.8.0}/Makefile +0 -0
  39. {env_alias-0.7.1 → env_alias-0.8.0}/docs/.python-version +0 -0
  40. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/assets/css/extra.css +0 -0
  41. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/assets/img/icons8-keepassxc.svg +0 -0
  42. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/assets/img/terminal-128x128.png +0 -0
  43. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/assets/js/extra.js +0 -0
  44. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/debugging.md +0 -0
  45. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/definition-attributes/ansible-vault-password-file.md +0 -0
  46. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/definition-attributes/ansible-vault-password.md +0 -0
  47. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/definition-attributes/exec.md +0 -0
  48. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/definition-attributes/keepass-password.md +0 -0
  49. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/definition-attributes/name.md +0 -0
  50. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/definition-attributes/override.md +0 -0
  51. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/definition-attributes/parser.md +0 -0
  52. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/definition-attributes/selector.md +0 -0
  53. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/definition-attributes/source.md +0 -0
  54. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/definition-attributes/value-to.md +0 -0
  55. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/definition-attributes/value.md +0 -0
  56. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/development.md +0 -0
  57. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/examples/ansible-project.md +0 -0
  58. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/examples/aws-credentials.md +0 -0
  59. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/examples/keepass-chained-secret.md +0 -0
  60. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/examples/keepass-secret-bundle.md +0 -0
  61. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/examples/multi-provider-ini.md +0 -0
  62. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/examples/per-session-secrets.md +0 -0
  63. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/examples/project-readiness.md +0 -0
  64. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/examples/remote-config.md +0 -0
  65. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/examples/structured-files.md +0 -0
  66. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/examples/terminal-messages.md +0 -0
  67. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/examples/terraform-aws-project.md +0 -0
  68. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/examples/value-reuse.md +0 -0
  69. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/index.md +0 -0
  70. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/license.md +0 -0
  71. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/project.md +0 -0
  72. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/security.md +0 -0
  73. {env_alias-0.7.1 → env_alias-0.8.0}/docs/docs/troubleshooting.md +0 -0
  74. {env_alias-0.7.1 → env_alias-0.8.0}/docs/mkdocs.yml +0 -0
  75. {env_alias-0.7.1 → env_alias-0.8.0}/docs/pyproject.toml +0 -0
  76. {env_alias-0.7.1 → env_alias-0.8.0}/docs/uv.lock +0 -0
  77. {env_alias-0.7.1 → env_alias-0.8.0}/pyproject.toml +0 -0
  78. {env_alias-0.7.1 → env_alias-0.8.0}/src/env_alias/exceptions.py +0 -0
  79. {env_alias-0.7.1 → env_alias-0.8.0}/src/env_alias/lib/__init__.py +0 -0
  80. {env_alias-0.7.1 → env_alias-0.8.0}/src/env_alias/lib/definitions.py +0 -0
  81. {env_alias-0.7.1 → env_alias-0.8.0}/src/env_alias/lib/generator.py +0 -0
  82. {env_alias-0.7.1 → env_alias-0.8.0}/src/env_alias/lib/logger.py +0 -0
  83. {env_alias-0.7.1 → env_alias-0.8.0}/src/env_alias/lib/selector.py +0 -0
  84. {env_alias-0.7.1 → env_alias-0.8.0}/src/env_alias/lib/source.py +0 -0
  85. {env_alias-0.7.1 → env_alias-0.8.0}/src/env_alias/models/__init__.py +0 -0
  86. {env_alias-0.7.1 → env_alias-0.8.0}/src/env_alias/models/constants.py +0 -0
  87. {env_alias-0.7.1 → env_alias-0.8.0}/src/env_alias/models/envalias_definition.py +0 -0
  88. {env_alias-0.7.1 → env_alias-0.8.0}/src/env_alias/models/sourced_content.py +0 -0
  89. {env_alias-0.7.1 → env_alias-0.8.0}/src/env_alias/py.typed +0 -0
  90. {env_alias-0.7.1 → env_alias-0.8.0}/tests/__init__.py +0 -0
  91. {env_alias-0.7.1 → env_alias-0.8.0}/tests/conftest.py +0 -0
  92. {env_alias-0.7.1 → env_alias-0.8.0}/tests/data/blns.base64.json +0 -0
  93. {env_alias-0.7.1 → env_alias-0.8.0}/tests/data/envalias-ansible-vault-datafile-password.txt +0 -0
  94. {env_alias-0.7.1 → env_alias-0.8.0}/tests/data/envalias-ansible-vault-datafile.vault +0 -0
  95. {env_alias-0.7.1 → env_alias-0.8.0}/tests/data/envalias-keepass-database-password.txt +0 -0
  96. {env_alias-0.7.1 → env_alias-0.8.0}/tests/data/envalias-keepass-database.kdbx +0 -0
  97. {env_alias-0.7.1 → env_alias-0.8.0}/tests/manual/ansible_vault_01.yml +0 -0
  98. {env_alias-0.7.1 → env_alias-0.8.0}/tests/manual/ansible_vault_password_file_01.yml +0 -0
  99. {env_alias-0.7.1 → env_alias-0.8.0}/tests/manual/direct_01.yml +0 -0
  100. {env_alias-0.7.1 → env_alias-0.8.0}/tests/manual/direct_02.yml +0 -0
  101. {env_alias-0.7.1 → env_alias-0.8.0}/tests/manual/direct_03.yml +0 -0
  102. {env_alias-0.7.1 → env_alias-0.8.0}/tests/manual/exec_01.yml +0 -0
  103. {env_alias-0.7.1 → env_alias-0.8.0}/tests/manual/exec_02.yml +0 -0
  104. {env_alias-0.7.1 → env_alias-0.8.0}/tests/manual/exec_03.yml +0 -0
  105. {env_alias-0.7.1 → env_alias-0.8.0}/tests/manual/exec_04.yml +0 -0
  106. {env_alias-0.7.1 → env_alias-0.8.0}/tests/manual/exec_bad_01.yml +0 -0
  107. {env_alias-0.7.1 → env_alias-0.8.0}/tests/manual/inputs_01.yml +0 -0
  108. {env_alias-0.7.1 → env_alias-0.8.0}/tests/manual/keepass_01.yml +0 -0
  109. {env_alias-0.7.1 → env_alias-0.8.0}/tests/manual/local_ini_01.yml +0 -0
  110. {env_alias-0.7.1 → env_alias-0.8.0}/tests/manual/local_ini_02.yml +0 -0
  111. {env_alias-0.7.1 → env_alias-0.8.0}/tests/manual/local_ini_03.yml +0 -0
  112. {env_alias-0.7.1 → env_alias-0.8.0}/tests/manual/local_json_01.yml +0 -0
  113. {env_alias-0.7.1 → env_alias-0.8.0}/tests/manual/local_json_02.yml +0 -0
  114. {env_alias-0.7.1 → env_alias-0.8.0}/tests/manual/local_text_01.yml +0 -0
  115. {env_alias-0.7.1 → env_alias-0.8.0}/tests/manual/local_text_02.yml +0 -0
  116. {env_alias-0.7.1 → env_alias-0.8.0}/tests/manual/local_yaml_01.yml +0 -0
  117. {env_alias-0.7.1 → env_alias-0.8.0}/tests/manual/local_yaml_02.yml +0 -0
  118. {env_alias-0.7.1 → env_alias-0.8.0}/tests/manual/overrides_01.yml +0 -0
  119. {env_alias-0.7.1 → env_alias-0.8.0}/tests/manual/remote_json_01.yml +0 -0
  120. {env_alias-0.7.1 → env_alias-0.8.0}/tests/manual/remote_json_02.yml +0 -0
  121. {env_alias-0.7.1 → env_alias-0.8.0}/tests/manual/remote_text_01.yml +0 -0
  122. {env_alias-0.7.1 → env_alias-0.8.0}/tests/test_ansible_vault_password_file.py +0 -0
  123. {env_alias-0.7.1 → env_alias-0.8.0}/tests/test_ansible_vault_source.py +0 -0
  124. {env_alias-0.7.1 → env_alias-0.8.0}/tests/test_basic.py +0 -0
  125. {env_alias-0.7.1 → env_alias-0.8.0}/tests/test_blns_edge_cases.py +0 -0
  126. {env_alias-0.7.1 → env_alias-0.8.0}/tests/test_cli.py +0 -0
  127. {env_alias-0.7.1 → env_alias-0.8.0}/tests/test_direct.py +0 -0
  128. {env_alias-0.7.1 → env_alias-0.8.0}/tests/test_exec_source.py +0 -0
  129. {env_alias-0.7.1 → env_alias-0.8.0}/tests/test_exit_codes.py +0 -0
  130. {env_alias-0.7.1 → env_alias-0.8.0}/tests/test_keepass_source.py +0 -0
  131. {env_alias-0.7.1 → env_alias-0.8.0}/tests/test_local_ini.py +0 -0
  132. {env_alias-0.7.1 → env_alias-0.8.0}/tests/test_local_json.py +0 -0
  133. {env_alias-0.7.1 → env_alias-0.8.0}/tests/test_local_text.py +0 -0
  134. {env_alias-0.7.1 → env_alias-0.8.0}/tests/test_local_yaml.py +0 -0
  135. {env_alias-0.7.1 → env_alias-0.8.0}/tests/test_override.py +0 -0
  136. {env_alias-0.7.1 → env_alias-0.8.0}/tests/test_release_metadata.py +0 -0
  137. {env_alias-0.7.1 → env_alias-0.8.0}/tests/test_remote_source.py +0 -0
  138. {env_alias-0.7.1 → env_alias-0.8.0}/tests/test_secret_cleanup.py +0 -0
  139. {env_alias-0.7.1 → env_alias-0.8.0}/tests/test_selector_edge_cases.py +0 -0
  140. {env_alias-0.7.1 → env_alias-0.8.0}/tests/test_shell_quoting.py +0 -0
  141. {env_alias-0.7.1 → env_alias-0.8.0}/tests/test_source_strategy_resolution.py +0 -0
  142. {env_alias-0.7.1 → env_alias-0.8.0}/tests/test_value_to.py +0 -0
  143. {env_alias-0.7.1 → env_alias-0.8.0}/tests/test_wheel_packaging.py +0 -0
  144. {env_alias-0.7.1 → env_alias-0.8.0}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: env-alias
3
- Version: 0.7.1
3
+ Version: 0.8.0
4
4
  Summary: Powerful helper utility to create shell alias commands to easily set collections of environment variables often with secret values from a variety of data-sources and data-formats.
5
5
  Project-URL: Homepage, https://github.com/threatpatrols/env-alias
6
6
  Project-URL: Repository, https://github.com/threatpatrols/env-alias.git
@@ -123,6 +123,12 @@ source <(env-alias \
123
123
  ~/.config/env-alias/env-proj-c.yml)
124
124
  ```
125
125
 
126
+ You can also pass a file pattern (glob):
127
+
128
+ ```shell
129
+ source <(env-alias ~/.config/env-alias/env-*.yml)
130
+ ```
131
+
126
132
  One process at shell startup defines `env-proj-a`, `env-proj-b` and `env-proj-c` as independent lazily-loaded
127
133
  aliases. This is the recommended pattern when you have many definitions.
128
134
 
@@ -87,6 +87,12 @@ source <(env-alias \
87
87
  ~/.config/env-alias/env-proj-c.yml)
88
88
  ```
89
89
 
90
+ You can also pass a file pattern (glob):
91
+
92
+ ```shell
93
+ source <(env-alias ~/.config/env-alias/env-*.yml)
94
+ ```
95
+
90
96
  One process at shell startup defines `env-proj-a`, `env-proj-b` and `env-proj-c` as independent lazily-loaded
91
97
  aliases. This is the recommended pattern when you have many definitions.
92
98
 
@@ -25,12 +25,18 @@ Walkthrough:
25
25
  1. Create the other project definition files in the same way, then register all of them at shell
26
26
  startup with one command:
27
27
 
28
- ```shell
29
- source <(env-alias \
30
- ~/.config/env-alias/env-project-a.yml \
31
- ~/.config/env-alias/env-project-b.yml \
32
- ~/.config/env-alias/env-project-c.yml)
33
- ```
28
+ ```shell
29
+ source <(env-alias \
30
+ ~/.config/env-alias/env-project-a.yml \
31
+ ~/.config/env-alias/env-project-b.yml \
32
+ ~/.config/env-alias/env-project-c.yml)
33
+ ```
34
+
35
+ Or using a file pattern (glob):
36
+
37
+ ```shell
38
+ source <(env-alias ~/.config/env-alias/env-*.yml)
39
+ ```
34
40
 
35
41
  2. One invocation emits **one lazy alias per file**, named from each basename —
36
42
  `env-project-a`, `env-project-b`, `env-project-c`.
@@ -5,7 +5,7 @@
5
5
  from os import getenv
6
6
 
7
7
  __title__ = "Env Alias"
8
- __version__ = "0.7.1"
8
+ __version__ = "0.8.0"
9
9
 
10
10
  LOGGER_LEVEL = "info"
11
11
  if getenv("ENVALIAS_DEBUG", "").lower().startswith(("true", "yes", "enable", "on")):
@@ -1,4 +1,5 @@
1
1
  import argparse
2
+ import glob
2
3
  import os
3
4
  import re
4
5
  import sys
@@ -14,7 +15,47 @@ logger = logger_get(name=LOGGER_NAME, loglevel=LOGGER_LEVEL)
14
15
  # ``env-awesome-vars``. Hyphens are safe inside the double-quoted alias-name
15
16
  # in the emitted ``alias`` statement — the P0-2 injection hardening guarded
16
17
  # against ``$`\\`` characters, not ``-``.
17
- _ALIAS_NAME_RE = re.compile(r"[A-Za-z_][A-Za-z0-9_-]*")
18
+ _ALIAS_NAME_RE = re.compile(r"^[A-Za-z_][A-Za-z0-9_-]*$")
19
+ _DEF_FILE_RE = re.compile(r"^[A-Za-z0-9_-]+\.ya?ml$", re.IGNORECASE)
20
+ _DEF_GLOB_RE = re.compile(r"^.*\.ya?ml$", re.IGNORECASE)
21
+
22
+
23
+ def _resolve_definition_files(arg: str) -> list[str]:
24
+ """Resolve a positional argument to one or more definition filenames.
25
+
26
+ Globs (*, ?) are expanded; an empty match logs a warning and returns [].
27
+ Static filenames are validated syntactically (must match _DEF_FILE_RE)
28
+ without touching the filesystem.
29
+ """
30
+ clean_path = arg.rstrip("/\\")
31
+ basename = os.path.basename(clean_path)
32
+ if not basename:
33
+ raise EnvAliasException(f"Definition file path {arg!r} is invalid: must be a YAML file, not a directory.")
34
+
35
+ if glob.has_magic(arg):
36
+ if not _DEF_GLOB_RE.fullmatch(basename):
37
+ raise EnvAliasException(f"Definition glob pattern {arg!r} must end with .yml or .yaml")
38
+ matches = sorted(glob.glob(os.path.expanduser(arg)))
39
+ if not matches:
40
+ logger.warning(f"No definition files matched glob pattern: {arg}")
41
+ return []
42
+ for f in matches:
43
+ fb = os.path.basename(f)
44
+ if not _DEF_FILE_RE.fullmatch(fb):
45
+ raise EnvAliasException(f"Matched definition filename {fb!r} must match ^[A-Za-z0-9_-]+\\.ya?ml$")
46
+ return matches
47
+
48
+ if not _DEF_FILE_RE.fullmatch(basename):
49
+ raise EnvAliasException(f"Definition filename {basename!r} must match ^[A-Za-z0-9_-]+\\.ya?ml$")
50
+
51
+ return [arg]
52
+
53
+
54
+ def _is_definition_arg(arg: str) -> bool:
55
+ """Return True if arg looks like a definition file or glob rather than an alias name."""
56
+ clean_path = arg.rstrip("/\\")
57
+ basename = os.path.basename(clean_path)
58
+ return bool(glob.has_magic(arg) or _DEF_FILE_RE.fullmatch(basename) or basename.lower().endswith((".yml", ".yaml")))
18
59
 
19
60
 
20
61
  def entrypoint() -> None:
@@ -48,34 +89,52 @@ def entrypoint() -> None:
48
89
 
49
90
  # Process positionals for alias mode. The result is a list of
50
91
  # (alias_name, filename) pairs, one entry per alias to emit.
92
+ entries: list[tuple[str, str]] = []
93
+
51
94
  if len(args.args) == 1:
52
- # Single arg: derive alias name from the filename basename.
53
- entries = [
54
- (
55
- os.path.splitext(os.path.basename(args.args[0]))[0],
56
- args.args[0],
57
- )
58
- ]
59
- elif len(args.args) >= 2:
60
- if os.path.isfile(args.args[0]):
61
- # First arg is a file: ALL args are definition files. Emit one
62
- # alias per file, each name inferred from its own basename, so a
63
- # single invocation defines N independent lazily-loaded aliases.
64
- entries = [(os.path.splitext(os.path.basename(f))[0], f) for f in args.args]
95
+ files = _resolve_definition_files(args.args[0])
96
+ if not files:
97
+ return
98
+ entries = [(os.path.splitext(os.path.basename(f))[0], f) for f in files]
99
+
100
+ elif len(args.args) == 2:
101
+ arg0, arg1 = args.args[0], args.args[1]
102
+ if _is_definition_arg(arg0):
103
+ # Multi-file mode: both args are definition files / patterns
104
+ for arg in args.args:
105
+ for f in _resolve_definition_files(arg):
106
+ entries.append((os.path.splitext(os.path.basename(f))[0], f))
65
107
  else:
66
- # First arg is an explicit alias name — only a single definition
67
- # file may follow; with multiple files the intent is ambiguous.
68
- alias_name = args.args[0]
69
- trailing = args.args[1:]
70
- if len(trailing) > 1:
108
+ # First arg is explicit alias name
109
+ alias_name = arg0
110
+ if not _ALIAS_NAME_RE.fullmatch(alias_name):
111
+ raise EnvAliasException(f"Invalid alias name {alias_name!r}: must match ^[A-Za-z_][A-Za-z0-9_-]*$")
112
+ files = _resolve_definition_files(arg1)
113
+ if not files:
114
+ return
115
+ if len(files) > 1:
71
116
  raise EnvAliasException(
72
- f"An explicit alias name may be followed by only one definition file, got {len(trailing)}."
117
+ f"An explicit alias name may be followed by only one definition file, got {len(files)}."
73
118
  )
74
- entries = [(alias_name, trailing[0])]
119
+ entries = [(alias_name, files[0])]
120
+
121
+ elif len(args.args) >= 3:
122
+ arg0 = args.args[0]
123
+ if not _is_definition_arg(arg0) and _ALIAS_NAME_RE.fullmatch(arg0):
124
+ trailing = args.args[1:]
125
+ raise EnvAliasException(
126
+ f"An explicit alias name may be followed by only one definition file, got {len(trailing)}."
127
+ )
128
+ for arg in args.args:
129
+ for f in _resolve_definition_files(arg):
130
+ entries.append((os.path.splitext(os.path.basename(f))[0], f))
75
131
  else:
76
132
  usage_help(exit_code=0)
77
133
  return
78
134
 
135
+ if not entries:
136
+ return
137
+
79
138
  # Validate every inferred/explicit alias name up front so that a single
80
139
  # bad name never yields partial alias output on stdout.
81
140
  for alias_name, _ in entries:
@@ -200,8 +200,10 @@ def test_entrypoint_systemexit_nonzero(capsys):
200
200
 
201
201
 
202
202
  def test_entrypoint_rhs_special_chars(tmp_path, config_file, capsys):
203
- """Filenames with single quotes should be escaped in the alias."""
204
- f = tmp_path / "test'file.yml"
203
+ """Filepaths with single quotes in directory name should be escaped in the alias."""
204
+ d = tmp_path / "test'dir"
205
+ d.mkdir()
206
+ f = d / "test-file.yml"
205
207
  f.write_text("env-alias:\n VAR:\n value: val\n")
206
208
  code = _run("myalias", str(f))
207
209
  assert code is None
@@ -209,3 +211,92 @@ def test_entrypoint_rhs_special_chars(tmp_path, config_file, capsys):
209
211
  assert "alias" in out.lower()
210
212
  # single quote should be escaped
211
213
  assert "'\\''" in out or "test" in out
214
+
215
+
216
+ # --- entrypoint() — glob expansion and validation -------------------------
217
+
218
+
219
+ def test_entrypoint_glob_zero_matches_emits_warning(tmp_path, capsys, caplog):
220
+ """Glob with zero matches logs a WARNING to stderr and exits 0 with no stdout."""
221
+ code = _run(str(tmp_path / "nonexistent-*.yml"))
222
+ assert code is None
223
+ captured = capsys.readouterr()
224
+ assert captured.out == ""
225
+ assert "No definition files matched glob pattern" in caplog.text
226
+
227
+
228
+ def test_entrypoint_glob_matches_emits_aliases(tmp_path, capsys):
229
+ """Glob with matches expands and emits an alias per matched file."""
230
+ f1 = tmp_path / "env-app1.yml"
231
+ f1.write_text("env-alias:\n A:\n value: 1\n")
232
+ f2 = tmp_path / "env-app2.yml"
233
+ f2.write_text("env-alias:\n B:\n value: 2\n")
234
+
235
+ code = _run(str(tmp_path / "env-*.yml"))
236
+ assert code is None
237
+ captured = capsys.readouterr()
238
+ assert 'alias "env-app1"=' in captured.out
239
+ assert 'alias "env-app2"=' in captured.out
240
+
241
+
242
+ def test_entrypoint_naked_directory_raises(tmp_path):
243
+ """Passing a naked directory raises EnvAliasException."""
244
+ d = tmp_path / "configs"
245
+ d.mkdir()
246
+ code = _run(str(d))
247
+ assert code == 1
248
+
249
+
250
+ def test_entrypoint_non_yaml_extension_raises(tmp_path):
251
+ """Passing a non-YAML file raises EnvAliasException."""
252
+ f = tmp_path / "config.json"
253
+ f.write_text("{}")
254
+ code = _run(str(f))
255
+ assert code == 1
256
+
257
+
258
+ def test_entrypoint_empty_basename_raises():
259
+ """Root slash only path raises EnvAliasException."""
260
+ code = _run("/")
261
+ assert code == 1
262
+
263
+
264
+ def test_entrypoint_explicit_alias_with_zero_match_glob(tmp_path, capsys):
265
+ """Explicit alias with a glob that matches 0 files exits 0 cleanly."""
266
+ code = _run("myalias", str(tmp_path / "nonexistent-*.yml"))
267
+ assert code is None
268
+ captured = capsys.readouterr()
269
+ assert captured.out == ""
270
+
271
+
272
+ def test_entrypoint_explicit_alias_with_multi_match_glob(tmp_path):
273
+ """Explicit alias with a glob matching multiple files raises EnvAliasException."""
274
+ f1 = tmp_path / "env-1.yml"
275
+ f1.write_text("env-alias:\n A:\n value: 1\n")
276
+ f2 = tmp_path / "env-2.yml"
277
+ f2.write_text("env-alias:\n B:\n value: 2\n")
278
+
279
+ code = _run("myalias", str(tmp_path / "env-*.yml"))
280
+ assert code == 1
281
+
282
+
283
+ def test_entrypoint_glob_invalid_extension_raises(tmp_path):
284
+ """Glob pattern with non-YAML extension raises EnvAliasException."""
285
+ code = _run(str(tmp_path / "env-*.txt"))
286
+ assert code == 1
287
+
288
+
289
+ def test_entrypoint_glob_matched_invalid_filename_raises(tmp_path):
290
+ """Glob matching a file with invalid characters in filename raises EnvAliasException."""
291
+ f = tmp_path / "env-bad$name.yml"
292
+ f.write_text("env-alias:\n A:\n value: 1\n")
293
+ code = _run(str(tmp_path / "env-*.yml"))
294
+ assert code == 1
295
+
296
+
297
+ def test_entrypoint_multi_file_all_zero_match_globs(tmp_path, capsys):
298
+ """Multi-file mode where all globs match 0 files exits 0 cleanly."""
299
+ code = _run(str(tmp_path / "none1-*.yml"), str(tmp_path / "none2-*.yml"))
300
+ assert code is None
301
+ captured = capsys.readouterr()
302
+ assert captured.out == ""
@@ -230,6 +230,18 @@ class TestEntrypointMultiFile:
230
230
 
231
231
 
232
232
  class TestCliMultiFile:
233
+ def test_multi_file_nonexistent_files_emits_aliases(self, tmp_path, capsys):
234
+ """Non-existent definition files still emit aliases without disk access."""
235
+ f1 = tmp_path / "env-host1.yml"
236
+ f2 = tmp_path / "env-host2.yml"
237
+ # Neither file exists on disk
238
+ code = _run(str(f1), str(f2))
239
+ assert code is None
240
+ aliases = _find_alias_lines(capsys.readouterr().out)
241
+ assert len(aliases) == 2
242
+ assert any('alias "env-host1"=' in a for a in aliases)
243
+ assert any('alias "env-host2"=' in a for a in aliases)
244
+
233
245
  def test_multi_file_subprocess(self, tmp_path, config_file):
234
246
  import shutil
235
247
  import subprocess
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