A collection of classes and commands for automated command line scripting using Python.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

51 lines
1013 B

# Define A Custom Command
!!! note
It is not currently possible to define a custom command which may be used with the `tease` command.
## 1) Create A Function
Create a function that does what you want:
```python
# mycommands.py
from scripttease.lib.commands.base import Command
def do_something_impressive(arg1, **kwargs):
return Command("ls -ls %s" % arg1, **kwargs)
```
!!! important
kwargs are *always* required.
## 2) Create A Mapping
```python
# mycommands.py
MAPPINGS = {
'impressive': do_something_impressive,
}
```
`impressive` is now mapped to the function which creates the command.
## 3) Supply The Mapping to the Command Factory
```python
from scripttease.lib.factories import command_factory
from scripttease.lib.loaders import INILoader
from .mycommands import MAPPINGS
ini = INILoader("path/to/commands.ini")
ini.load()
commands = command_factory(ini, mappings=MAPPINGS)
```
## 4) Include the Custom Command
```ini
[this is my custom command]
impressive: testing
```