|
15 | 15 | import click
|
16 | 16 |
|
17 | 17 | from idom import html
|
18 |
| -from idom._console.utils import error |
| 18 | +from idom._console.utils import echo_error, echo_warning |
19 | 19 |
|
20 | 20 |
|
21 | 21 | CAMEL_CASE_SUB_PATTERN = re.compile(r"(?<!^)(?=[A-Z])")
|
22 | 22 |
|
23 | 23 |
|
24 | 24 | @click.command()
|
25 |
| -@click.argument("directories", nargs=-1) |
26 |
| -def update_html_usages(directories: list[str]) -> None: |
27 |
| - """Rewrite files in the given directories to use the new html element API. |
| 25 | +@click.argument( |
| 26 | + "directories", |
| 27 | + nargs=-1, |
| 28 | + type=click.Path(exists=True, dir_okay=True, file_okay=False), |
| 29 | +) |
| 30 | +def update_html_usages(paths: list[str]) -> None: |
| 31 | + """Rewrite files under the given paths using the new html element API. |
28 | 32 |
|
29 | 33 | The old API required users to pass a dictionary of attributes to html element
|
30 | 34 | constructor functions. For example:
|
@@ -55,16 +59,19 @@ def update_html_usages(directories: list[str]) -> None:
|
55 | 59 | if sys.version_info < (3, 9): # pragma: no cover
|
56 | 60 | raise RuntimeError("This command requires Python>=3.9")
|
57 | 61 |
|
58 |
| - at_leat_one_file = False |
59 |
| - for d in directories: |
60 |
| - for file in Path(d).rglob("*.py"): |
61 |
| - at_leat_one_file = True |
62 |
| - result = generate_rewrite(file=file, source=file.read_text()) |
| 62 | + at_least_one_file = False |
| 63 | + for p in map(Path, paths): |
| 64 | + if not p.exists(): |
| 65 | + echo_warning(f"no directory {p}") |
| 66 | + continue |
| 67 | + for f in [p] if p.is_file() else p.rglob("*.py"): |
| 68 | + at_least_one_file = True |
| 69 | + result = generate_rewrite(file=f, source=f.read_text()) |
63 | 70 | if result is not None:
|
64 |
| - file.write_text(result) |
| 71 | + f.write_text(result) |
65 | 72 |
|
66 |
| - if not at_leat_one_file: |
67 |
| - error("Found no Python files in the given directories.") |
| 73 | + if not at_least_one_file: |
| 74 | + echo_error("Found no Python files in the given directories.") |
68 | 75 | sys.exit(1)
|
69 | 76 |
|
70 | 77 |
|
|
0 commit comments