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

Commit

Permalink
Updated 'Customise Kedro CLI' (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-ivaniuk authored Jan 19, 2021
1 parent 979a6b8 commit 07c3562
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 136 deletions.
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.

0 comments on commit 07c3562

Please sign in to comment.