Skip to content
Merged
Changes from 2 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: 3 additions & 2 deletions src/codegen/cli/commands/create/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@ def make_relative(path: Path) -> str:


@click.command(name="create")
@requires_init
@click.argument("name", type=str)
@click.argument("path", type=click.Path(path_type=Path), default=Path.cwd())
@click.option("--description", "-d", default=None, help="Description of what this codemod does.")
@click.option("--overwrite", is_flag=True, help="Overwrites function if it already exists.")
def create_command(session: CodegenSession, name: str, path: Path, description: str | None = None, overwrite: bool = False):
def create_command(name: str, path: Path, description: str | None = None, overwrite: bool = False):
"""Create a new codegen function.

NAME is the name/label for the function
PATH is where to create the function (default: current directory)
"""
# Get the target path for the function
codemod_path, prompt_path = get_target_paths(name, path)
session = CodegenSession()

# Check if file exists
if codemod_path.exists() and not overwrite:
Expand All @@ -93,6 +93,7 @@ def create_command(session: CodegenSession, name: str, path: Path, description:
with create_spinner("Generating function (using LLM, this will take ~10s)") as status:
response = RestAPI(session.token).create(name=name, query=description)
code = convert_to_cli(response.code, session.language, name)
prompt_path.parent.mkdir(parents=True, exist_ok=True)
prompt_path.write_text(response.context)
else:
# Use default implementation
Expand Down