Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add --dir option to codegen for searching .edgeql files #434

Merged
merged 1 commit into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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