Skip to content
Snippets Groups Projects
Commit 3c6b86c5 authored by Henke's avatar Henke
Browse files

Add some ending words for the plugin tutorial

parent c9653b52
No related branches found
No related tags found
No related merge requests found
Pipeline #
...@@ -127,8 +127,44 @@ def CLI(bus, parent): ...@@ -127,8 +127,44 @@ def CLI(bus, parent):
@click.argument('libfile') @click.argument('libfile')
@click.argument('problem') @click.argument('problem')
def libcp(libfile, problem): def libcp(libfile, problem):
'''my docstring'''
pass pass
``` ```
Now we have created the command `kattcmd libcp LIBFILE PROBLEM`. Both passed as Now we have created the command `kattcmd libcp LIBFILE PROBLEM`. Both
strings to the `libcp` function. passed as strings to the `libcp` function. Click will automatically
add the command as a visible subcommand when running `kattcmd` and
running `kattcmd libcp --help` will display the help message for it,
which is the docstring for the function.
If we combine our implementation with the code above we will have
finished our plugin! The final plugin looks like this:
```python
import click
import os
import shutil
def CLI(bus, parent):
@parent.command()
@click.argument('libfile')
@click.argument('problem')
def libcp(libfile, problem):
'''Copies a library file to a problem folder'''
try:
home = bus.call('kattcmd:find-root', bus)
except Exception as e:
print('User is not in a kattis directory', e)
exit(1)
src = os.path.join(home, 'library', libfile)
dst = os.path.join(home, 'kattis', problem, libfile)
shutil.copyfile(src, dst)
```
That is all that you should need to get started with plugin
development for `kattcmd`! If you need inspiration on how to create
more advanced plugins then I recommend you to look at the
[source](kattcmd/commands), because each command that `kattcmd` comes
with is essentially a plugin.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment