|
3 | 3 | import argparse |
4 | 4 | import os |
5 | 5 | import libcst as cst |
| 6 | +from itertools import chain |
6 | 7 | from typing import (Any, Callable, Dict, List, Sequence, Tuple) |
7 | 8 |
|
8 | 9 |
|
@@ -79,13 +80,16 @@ class {{ service.client_name }}CallTransformer(cst.CSTTransformer): |
79 | 80 |
|
80 | 81 | def fix_files( |
81 | 82 | dirs: Sequence[str], |
| 83 | + files: Sequence[str], |
82 | 84 | *, |
83 | 85 | transformer={{ service.client_name }}CallTransformer(), |
84 | 86 | ): |
85 | | - pyfile_gen = (os.path.join(root, f) |
86 | | - for d in dirs |
87 | | - for root, _, files in os.walk(d) |
88 | | - for f in files if os.path.splitext(f)[1] == ".py") |
| 87 | + pyfile_gen = chain( |
| 88 | + (os.path.join(root, f) |
| 89 | + for d in dirs |
| 90 | + for root, _, files in os.walk(d) |
| 91 | + for f in files if os.path.splitext(f)[1] == ".py"), |
| 92 | + files) |
89 | 93 |
|
90 | 94 | for fpath in pyfile_gen: |
91 | 95 | with open(fpath, 'r+') as f: |
@@ -113,13 +117,21 @@ Note: This tool operates at a best-effort level at converting positional |
113 | 117 |
|
114 | 118 | Be sure to back up your source files before running this tool and to compare the diffs. |
115 | 119 | """) |
116 | | - parser.add_argument( |
| 120 | + group = parser.add_mutually_exclusive_group(required=True) |
| 121 | + group.add_argument( |
117 | 122 | '-d', |
118 | 123 | metavar='dir', |
119 | 124 | dest='dirs', |
120 | 125 | action='append', |
121 | | - help='a directory to walk for python files to fix up' |
| 126 | + help='a directory to walk for python files to fix up', |
| 127 | + ) |
| 128 | + group.add_argument( |
| 129 | + '-f', |
| 130 | + metavar='file', |
| 131 | + dest='files', |
| 132 | + action='append', |
| 133 | + help='a file to fix up via un-flattening', |
122 | 134 | ) |
123 | 135 | args = parser.parse_args() |
124 | | - fix_files(args.dirs or ['.']) |
| 136 | + fix_files(args.dirs or [], args.files or []) |
125 | 137 | {% endblock %} |
0 commit comments