Skip to content

Commit b96cb74

Browse files
committed
docs: Update documentation for CLI command extensions and overrides
1 parent 42cc526 commit b96cb74

File tree

4 files changed

+137
-1
lines changed

4 files changed

+137
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ Apache-2.0
407407

408408
## 🔗 Links
409409

410-
- **Documentation**: [docs/index.md](docs/index.md) - Complete documentation
410+
- **Documentation**: [docs/index.md](docs/README.md) - Complete documentation
411411
- **Website**: [aipartnerup.com](https://aipartnerup.com)
412412
- **GitHub**: [aipartnerup/apflow](https://github.com/aipartnerup/apflow)
413413
- **PyPI**: [apflow](https://pypi.org/project/apflow/)

docs/guides/cli.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,57 @@ apflow users stat
259259
```
260260

261261
For more details on how to develop these extensions, see the [Extending Guide](../development/extending.md#creating-cli-extensions).
262+
263+
## Extending and Overriding CLI Commands
264+
265+
apflow allows you to register new CLI command groups or single commands, extend existing groups, or override built-in commands and groups. This is done using the `@cli_register` decorator, with the `group` and `override=True` parameters.
266+
267+
### Register a New Command or Group
268+
```python
269+
from apflow.cli.decorators import cli_register
270+
271+
@cli_register(name="my-group", help="My command group")
272+
class MyGroup:
273+
def foo(self):
274+
print("foo")
275+
def bar(self):
276+
print("bar")
277+
```
278+
279+
### Add a Subcommand to an Existing Group
280+
```python
281+
@cli_register(group="my-group", name="baz", help="Baz command")
282+
def baz():
283+
print("baz")
284+
```
285+
286+
### Override an Existing Command or Group
287+
288+
```python
289+
@cli_register(name="my-group", override=True)
290+
class NewMyGroup:
291+
...
292+
293+
@cli_register(group="my-group", name="foo", override=True)
294+
def new_foo():
295+
print("new foo")
296+
```
297+
298+
**Override a built-in command (e.g., 'run'):**
299+
```python
300+
from apflow.cli.decorators import cli_register
301+
302+
@cli_register(name="run", override=True, help="Override built-in run command")
303+
def my_run():
304+
print("This is my custom run command!")
305+
```
306+
Now, running `apflow run` will execute your custom logic instead of the built-in command.
307+
308+
### Core Extension Override
309+
310+
apflow also supports custom extensions for executors, hooks, storage backends, and more. You can register your own or override built-in extensions by passing `override=True` when registering.
311+
312+
**Best Practices:**
313+
- Use `override=True` only when you want to replace an existing command or extension.
314+
- Keep extension logic simple and well-documented.
315+
- Test your extensions thoroughly.

docs/guides/extensions.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Extensions in apflow
2+
3+
apflow supports a powerful extension system for both CLI commands and core functionality. You can add your own extensions or override existing ones, making it easy to customize and adapt apflow to your needs.
4+
5+
## CLI Extensions: Custom Commands and Overriding
6+
7+
You can register new CLI command groups or single commands using the `@cli_register` decorator. You can also extend or override existing commands and groups by specifying the `group` and `override=True` parameters.
8+
9+
For detailed usage and examples, see the [CLI Guide](./cli.md) and [Library Usage Guide](./library-usage.md).
10+
11+
## Core Extensions: Custom and Override
12+
13+
apflow also supports custom extensions for executors, hooks, storage backends, and more. You can register your own or override built-in extensions by passing `override=True` when registering.
14+
15+
For how to override executors and other extensions, see the [API Quick Reference](../api/quick-reference.md) and [Python API Reference](../api/python.md).
16+
17+
For more details, see the [Extending Guide](../development/extending.md).
18+
19+
For more details, see the [Extending Guide](../development/extending.md).
20+
21+
## Best Practices
22+
- Use `override=True` only when you want to replace an existing command or extension.
23+
- Keep extension logic simple and well-documented.
24+
- Test your extensions thoroughly.

docs/guides/library-usage.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,64 @@ This means your custom middleware runs **after** the default middleware, so it c
406406
5. **Test middleware** thoroughly as it affects all requests
407407
6. **Use type hints** for better code clarity
408408

409+
## Extending and Overriding CLI Commands and Extensions
410+
411+
apflow supports advanced extensibility for both CLI commands and core extensions. You can add your own commands, extend existing groups, or override built-in commands and extensions using simple decorators and parameters.
412+
413+
### CLI Command Extension and Override
414+
415+
416+
You can register new CLI command groups or single commands using the `@cli_register` decorator. To extend an existing group, use the `group` parameter. To override an existing command or group, set `override=True`.
417+
418+
**Register a new command group:**
419+
```python
420+
from apflow.cli.decorators import cli_register
421+
422+
@cli_register(name="my-group", help="My command group")
423+
class MyGroup:
424+
def foo(self):
425+
print("foo")
426+
def bar(self):
427+
print("bar")
428+
```
429+
430+
**Add a subcommand to an existing group:**
431+
```python
432+
@cli_register(group="my-group", name="baz", help="Baz command")
433+
def baz():
434+
print("baz")
435+
```
436+
437+
**Override an existing command or group:**
438+
```python
439+
@cli_register(name="my-group", override=True)
440+
class NewMyGroup:
441+
...
442+
443+
@cli_register(group="my-group", name="foo", override=True)
444+
def new_foo():
445+
print("new foo")
446+
```
447+
448+
**Override a built-in command (e.g., 'run'):**
449+
```python
450+
from apflow.cli.decorators import cli_register
451+
452+
@cli_register(name="run", override=True, help="Override built-in run command")
453+
def my_run():
454+
print("This is my custom run command!")
455+
```
456+
Now, running `apflow run` will execute your custom logic instead of the built-in command.
457+
458+
### Core Extension Override
459+
460+
apflow also supports custom extensions for executors, hooks, storage backends, and more. You can register your own or override built-in extensions by passing `override=True` when registering.
461+
462+
**Best Practices:**
463+
- Use `override=True` only when you want to replace an existing command or extension.
464+
- Keep extension logic simple and well-documented.
465+
- Test your extensions thoroughly.
466+
409467
## Quick Reference: What main.py Does
410468

411469
For reference, here's what `apflow.api.main.main()` and `create_runnable_app()` do:

0 commit comments

Comments
 (0)