Skip to content

Adds docs for @codegen.function decorator #187

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 3 commits into from
Jan 29, 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
53 changes: 53 additions & 0 deletions docs/building-with-codegen/function-decorator.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
title: Function Decorator
sidebarTitle: "@codegen.function"
icon: "at"
iconType: "solid"
---

# Function Decorator

The `function` decorator is used to define codegen functions within your application. It allows you to specify a name for the function that will be ran making it easier to run specific codemods

## Usage

To use the `function` decorator, simply annotate your function with `@codegen.function` and provide a name as an argument.

### Example

```python
@codegen.function('my-function')
def run(codebase):
pass
```

In this example, the function `run` is decorated with `@codegen.function` and given the name `'my-function'`. This name will be used when the function is ran.

## Parameters

- `name` (str): The name of the function to be used when ran.

## Description

The `function` decorator is part of the codegen SDK CLI and is used to mark functions that are intended to be ran as part of a code generation process. It ensures that the function is properly registered and can be invoked with the specified name.


## CLI Examples

### Running a Function

To run a deployed function using the CLI, use the following command:

```bash
codegen run my-function
```

This command runs the function named `my-function`.

## See Also

- [Webhook Decorator](./webhook-decorator.mdx): For handling webhook events with decorators.
- [Codebase Visualization](./codebase-visualization.mdx): For visualizing codebases in your application.
- [CLI Init Command](../cli/init.mdx): For initializing projects or environments related to the function decorator.
- [CLI Create Command](../cli/create.mdx): For creating new functions or projects using the CLI.
- [CLI Run Command](../cli/run.mdx): For running code or scripts using the CLI.
1 change: 1 addition & 0 deletions docs/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"building-with-codegen/parsing-codebases",
"building-with-codegen/reusable-codemods",
"building-with-codegen/dot-codegen",
"building-with-codegen/function-decorator",
"building-with-codegen/language-support",
"building-with-codegen/commit-and-reset",
"building-with-codegen/git-operations",
Expand Down