Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Updated 'Customise Kedro CLI' #10

Merged
merged 6 commits into from
Jan 19, 2021
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
2 changes: 1 addition & 1 deletion docs/13_custom-datasets.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,4 @@ context.catalog.load('shuttles').head()
Kedro users create many custom dataset implementations while working on real-world projects, and it makes sense that they should be able to share their work with each other. Sharing your custom datasets implementations is possibly the easiest way to contribute back to Kedro and if you are interested in doing so, you can check out the [Kedro contribution guide](https://github.com/quantumblacklabs/kedro/blob/develop/CONTRIBUTING.md) in the GitHub.

### Next section
[Go to the next section](./14_extending-kedro.md)
[Go to the next section](./14_custom-cli-commands.md)
44 changes: 44 additions & 0 deletions docs/14_custom-cli-commands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# How to add a custom CLI command

As the following steps explain, to add a new custom CLI command, you need to create a new `click` group, add a `@cli.command()` to that group and then register the new group with `cli` group defined in `src/<package_name>/cli.py`:

```python
# src/<package_name>/cli.py
...

@click.group()
def custom():
"""Custom commands."""

@custom.command()
def to_json():
""" Display the pipeline in JSON format """
package_name = str(Path(__file__).resolve().parent.name)
with KedroSession.create(package_name) as session:
context = session.load_context()
print(context.pipeline.to_json())

...
cli.add_command(jupyter_group)
cli.add_command(custom)
...
```

Once you have made the modification, if you run `kedro -h` in your terminal, you see the new `custom` group.

![](../img/custom_command.png)

Run the custom command:

```shell
$ kedro custom to-json
```

# Customise existing Kedro CLI

> Note: All the existing Kedro CLI commands are closed for modification.

The only possible way to extend an existing command is to create a new custom command as described in the previous section.

### Next section
[Go to the next section](./15_plugins.md)
135 changes: 0 additions & 135 deletions docs/14_extending-kedro.md

This file was deleted.

Binary file modified img/custom_command.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.