Skip to content

Commit

Permalink
Add --dir option to codegen for searching .edgeql files
Browse files Browse the repository at this point in the history
  • Loading branch information
fantix committed Jun 18, 2023
1 parent 045f127 commit ec90e35
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 5 additions & 0 deletions edgedb/codegen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ def error(self, message):
nargs="?",
help="Generate a single file instead of one per .edgeql file.",
)
parser.add_argument(
"--dir",
action="append",
help="Only search .edgeql files under specified directories.",
)
parser.add_argument(
"--target",
choices=["blocking", "async"],
Expand Down
20 changes: 19 additions & 1 deletion edgedb/codegen/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,20 @@ def __init__(self, args: argparse.Namespace):
print_msg(f"Found EdgeDB project: {C.BOLD}{self._project_dir}{C.ENDC}")
self._client = edgedb.create_client(**_get_conn_args(args))
self._single_mode_files = args.file
self._search_dirs = []
for search_dir in args.dir or []:
search_dir = pathlib.Path(search_dir).absolute()
if (
search_dir == self._project_dir
or self._project_dir in search_dir.parents
):
self._search_dirs.append(search_dir)
else:
print(
f"--dir '{search_dir}' is not under "
f"the project directory: {self._project_dir}"
)
sys.exit(1)
self._method_names = set()
self._describe_results = []

Expand All @@ -170,7 +184,11 @@ def run(self):
print(f"Failed to connect to EdgeDB instance: {e}")
sys.exit(61)
with self._client:
self._process_dir(self._project_dir)
if self._search_dirs:
for search_dir in self._search_dirs:
self._process_dir(search_dir)
else:
self._process_dir(self._project_dir)
for target, suffix, is_async in SUFFIXES:
if target in self._targets:
self._async = is_async
Expand Down

0 comments on commit ec90e35

Please sign in to comment.