Skip to content

fix: Update docs for codegen create command to include required PATH parameter #963

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2025
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
4 changes: 2 additions & 2 deletions docs/building-with-codegen/dot-codegen.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Codegen automatically adds appropriate entries to your `.gitignore`:
The `codemods/` directory is where your transformation functions live. You can create new codemods using:

```bash
codegen create my-codemod [--description "what it does"]
codegen create my-codemod PATH [--description "what it does"]
```

This will:
Expand Down Expand Up @@ -115,7 +115,7 @@ After initializing your `.codegen` directory:

1. Create your first codemod:
```bash
codegen create my-codemod -d "describe what you want to do"
codegen create my-codemod . -d "describe what you want to do"
```

2. Run it:
Expand Down
4 changes: 2 additions & 2 deletions docs/building-with-codegen/reusable-codemods.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Codegen enables you to create reusable code transformations using Python functio
The easiest way to create a new codemod is using the CLI [create](/cli/create) command:

```bash
codegen create rename-function
codegen create rename-function .
```

This creates a new codemod in your `.codegen/codemods` directory:
Expand All @@ -37,7 +37,7 @@ def run(codebase: Codebase):
You can use AI to generate an initial implementation by providing a description:

```bash
codegen create rename-function -d "Rename the getUserData function to fetchUserProfile"
codegen create rename-function . -d "Rename the getUserData function to fetchUserProfile"
```

This will:
Expand Down
11 changes: 6 additions & 5 deletions docs/cli/create.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,27 @@ iconType: "solid"
The `create` command generates a new codemod function with the necessary boilerplate.

```bash
codegen create rename-function
codegen create rename-function .
```

## Usage

```bash
codegen create NAME [OPTIONS]
codegen create NAME PATH [OPTIONS]
```

## Arguments

- `NAME`: The name of the codemod to create (e.g., "rename-function")
- `PATH`: The path where the codemod should be created (e.g., "." for current directory)

## Options

- `--description`, `-d`: A description of what the codemod should do. This will be used to generate an AI-powered implementation.

## Generated Files

When you run `codegen create rename-function`, it creates:
When you run `codegen create rename-function .`, it creates:

```
.codegen/
Expand Down Expand Up @@ -63,12 +64,12 @@ if __name__ == "__main__":

Create a basic codemod:
```bash
codegen create rename-function
codegen create rename-function .
```

Create with an AI-powered implementation:
```bash
codegen create rename-function -d "Rename the getUserData function to fetchUserProfile"
codegen create rename-function . -d "Rename the getUserData function to fetchUserProfile"
```

## Next Steps
Expand Down
4 changes: 3 additions & 1 deletion docs/cli/init.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ After initializing:
1. Create your first codemod:

```bash
codegen create my-function -d "describe what you want to do"
codegen create my-function . -d "describe what you want to do"
```

Note: The second parameter (`.`) specifies the path where the codemod should be created. This is required.

2. Run it:

```bash
Expand Down
4 changes: 2 additions & 2 deletions docs/introduction/work-with-ai.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ The [Codegen CLI](/cli/about) provides commands to generate `.md` files that can
When you create a new codemod via [codegen create](/cli/create):

```bash
codegen create delete-dead-imports --description "Delete unused imports"
codegen create delete-dead-imports . --description "Delete unused imports"
```

Codegen automatically generates an optimized ["system prompt"](https://news.ycombinator.com/item?id=37880023) that includes:
Expand All @@ -52,7 +52,7 @@ This `.md` file can be used with any AI assistant (Claude, GPT-4, etc.) to get m
<Step title="Create a codemod with description">
Use the [create command](/cli/create) with a detailed description of what you want to accomplish:
```bash
codegen create modernize-components --description "Convert class components to functional components with hooks"
codegen create modernize-components . --description "Convert class components to functional components with hooks"
```
</Step>
<Step title="Review the generated system prompt">
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/cli/commands/init/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
def init_command(path: str | None = None, token: str | None = None, language: str | None = None, fetch_docs: bool = False):
"""Initialize or update the Codegen folder."""
# Print a message if not in a git repo
path = Path.cwd() if path is None else Path(path)

Check failure on line 22 in src/codegen/cli/commands/init/main.py

View workflow job for this annotation

GitHub Actions / mypy

error: Incompatible types in assignment (expression has type "Path", variable has type "str | None") [assignment]
repo_path = get_git_root_path(path)

Check failure on line 23 in src/codegen/cli/commands/init/main.py

View workflow job for this annotation

GitHub Actions / mypy

error: Argument 1 to "get_git_root_path" has incompatible type "str | None"; expected "Path | None" [arg-type]
rich.print(f"Found git repository at: {repo_path}")

if repo_path is None:
Expand All @@ -37,15 +37,15 @@
session.config.save()

action = "Updating" if session.existing else "Initializing"
codegen_dir, docs_dir, examples_dir = initialize_codegen(status=action, session=session, fetch_docs=fetch_docs)

Check failure on line 40 in src/codegen/cli/commands/init/main.py

View workflow job for this annotation

GitHub Actions / mypy

error: "CodegenSession" object is not iterable [misc]

# Print success message
rich.print(f"✅ {action} complete\n")
rich.print(get_success_message(codegen_dir, docs_dir, examples_dir))

Check failure on line 44 in src/codegen/cli/commands/init/main.py

View workflow job for this annotation

GitHub Actions / mypy

error: Cannot determine type of "codegen_dir" [has-type]

Check failure on line 44 in src/codegen/cli/commands/init/main.py

View workflow job for this annotation

GitHub Actions / mypy

error: Cannot determine type of "docs_dir" [has-type]

Check failure on line 44 in src/codegen/cli/commands/init/main.py

View workflow job for this annotation

GitHub Actions / mypy

error: Cannot determine type of "examples_dir" [has-type]

# Print next steps
rich.print("\n[bold]What's next?[/bold]\n")
rich.print("1. Create a function:")
rich.print(format_command('codegen create my-function -d "describe what you want to do"'))
rich.print(format_command('codegen create my-function . -d "describe what you want to do"'))
rich.print("2. Run it:")
rich.print(format_command("codegen run my-function --apply-local"))
Loading