UNPKG

2.14 kBMarkdownView Raw
1## Extending KD tool
2
3You can define subcommands:
4
5 kd module command sub1 sub2 --paramkey paramval --paramkey1 paramval1 --parambool
6
7This command will match these pattern:
8
9```coffeescript
10module.exports = class Module
11 command: (sub1, sub2)->
12 {paramkey, paramkey1, parambool} = @options
13
14 # paramkey is paramval
15 # paramkey1 is paramval1
16 # parambool is true
17```
18
19## Modules
20
21Modules are in `modules` directory. Every module is a file exporting a class.
22
23Also you can create your modules in `.kd/modules` directory.
24
25This is an example with a name `mymodule.coffee`
26
27```coffeescript
28module.exports = class MyModule
29
30 # This closes the errors of the command. Not recommended.
31 silent: yes
32
33 help: """
34 Koding MyModule Controller
35 """
36
37 alias:
38 hi: "hello"
39
40 constructor: (@config)->
41
42 hello: (name)->
43 {with} = @options
44 console.log "hello #{name} and #{with}"
45
46 __command: (command, params)->
47 # magic command
48```
49
50### Kodingfile.coffee
51
52You also can use `kd` with `Kodingfile.coffee` file. If a directory has that file kd will run it.
53The command shouldn't be a module name. Because kd will search for existing modules first. Kodingfile
54is the latest one it looks.
55
56While using Kodingfile, you should use only the command name:
57
58```coffeescript
59module.exports = class Kodingfile
60 hello: (name)->
61 console.log "Hello, #{name}"
62```
63
64will run with
65
66 kd hello fka
67
68This command will search for "hello" module first, won't find and will look for your Kodingfile.coffee.
69
70### Modules Meta
71
72The `help` is an help to show user. When user call `kd mymodule` that information will be shown.
73
74`@config` variable is the `~/.kdconfig` file. It's a JSON file and you can set global variables using `config` module (write `kd config`).
75
76If you write `__command` into your module class, your module will never give a error about command existance. It'll call that method.
77
78You can use `alias` to make aliases.
79
80The example above can be run calling:
81
82 kd mymodule hello koding --with birds
83
84or with the alias:
85
86 kd mymodule hello koding --with birds
87
88The output will be:
89
90 hello koding and birds
\No newline at end of file