Files
computer-playbook/cli/build/list/__main__.py
T
kevinveenbirkenbachandClaude Opus 4.7 3ffc7894bd refactor(cli): rename build/meta packages and move services resolver to utils
Package renames (dynamic discovery picks up new names automatically):
- cli/build/role_include/      -> cli/build/include/
- cli/build/roles_list/        -> cli/build/list/
- cli/meta/roles/lifecycle_filter/ -> cli/meta/roles/lifecycle/

Domain logic moved out of cli/ (no CLI surface, just a helper class):
- cli/meta/roles/applications/resolution/services/{resolver,errors}.py
  -> utils/roles/applications/services/{resolver,errors}.py
- drop dead services/yaml_utils.py + its only test

Bug fixes:
- cli/meta/{callorder -> roles/callorder} dropped its hard-coded
  parents[3] PROJECT_ROOT (broke after the directory move and resolved
  to <repo>/cli/); it now reuses utils.PROJECT_ROOT.

Help renderer (cli/core/help.py + colors.py):
- DIM color on the description column to separate it from the command name
- Blank line between the long command name and its wrapped description
- Italic invocation under the category heading + leading blank line
- New Style.ITALIC

Doc updates: path references in docs/requirements/00{8,10}*.md plus
soft-wrap fixes in the touched regions.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 02:45:40 +02:00

64 lines
1.8 KiB
Python

#!/usr/bin/env python3
"""
Generate a JSON file listing all Ansible role directories.
Usage:
python -m cli.build.list [--roles-dir path/to/roles] [--output path/to/roles/list.json | console]
"""
import os
import json
import argparse
from . import PROJECT_ROOT
def find_roles(roles_dir: str):
"""Return sorted list of role names under roles_dir."""
return sorted([
entry for entry in os.listdir(roles_dir)
if os.path.isdir(os.path.join(roles_dir, entry))
])
def write_roles_list(roles, out_file):
"""Write the list of roles to out_file as JSON."""
os.makedirs(os.path.dirname(out_file), exist_ok=True)
with open(out_file, 'w', encoding='utf-8') as f:
json.dump(roles, f, indent=2)
print(f"Wrote roles list to {out_file}")
def main():
default_roles_dir = str(PROJECT_ROOT / "roles")
default_output = os.path.join(default_roles_dir, 'list.json')
parser = argparse.ArgumentParser(description='Generate roles/list.json')
parser.add_argument(
'--roles-dir', '-r',
default=default_roles_dir,
help=f'Directory containing role subfolders (default: {default_roles_dir})'
)
parser.add_argument(
'--output', '-o',
default=default_output,
help=(
'Output path for roles list JSON '
'(or "console" to print to stdout, default: %(default)s)'
)
)
args = parser.parse_args()
if not os.path.isdir(args.roles_dir):
parser.error(f"Roles directory not found: {args.roles_dir}")
roles = find_roles(args.roles_dir)
if args.output.lower() == 'console':
# Print JSON to stdout
print(json.dumps(roles, indent=2))
else:
write_roles_list(roles, args.output)
if __name__ == '__main__':
main()