-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommand.js
60 lines (47 loc) · 1.33 KB
/
command.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const Argument = require('./argument')
const Option = require('./option')
const CommandContracts = require('@ostro/contracts/console/command')
const { implement } = require('@ostro/support/function')
const Interaction = require('./concerns/intraction')
const HasParameters = require('./concerns/hasParameters')
const CallCommands = require('./concerns/callsCommands')
class Command extends implement(CommandContracts, Interaction, CallCommands, HasParameters) {
get $signature() {
throw Error('$signature must be defined')
}
get $description() {
throw Error('$description must be defined')
}
get $options() {
return []
}
get $arguments() {
return []
}
createArgument() {
return new Argument(...arguments)
}
createOption() {
return new Option(...arguments)
}
getApp() {
return this.$app;
}
setApp($app) {
this.$app = $app;
}
setConsole($console) {
this.$console = $console
}
getConsole() {
return this.$console
}
execute() {
let $method = typeof this['handle'] == 'function' ? 'handle' : '__invoke';
return this.$app.call(this, $method);
}
__invoke() {
throw Error('class should have either handle or __invike function')
}
}
module.exports = Command