@moostjs/event-cli 0.3.10 → 0.3.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +165 -317
- package/dist/index.d.ts +208 -219
- package/dist/index.mjs +164 -316
- package/package.json +6 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,219 +1,208 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* @
|
|
80
|
-
*
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
* Use
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
*/
|
|
210
|
-
globalCliOptions?: {
|
|
211
|
-
keys: string[];
|
|
212
|
-
description?: string;
|
|
213
|
-
type?: TFunction;
|
|
214
|
-
}[];
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
export { useCliContext }
|
|
218
|
-
|
|
219
|
-
export { }
|
|
1
|
+
import * as moost from 'moost';
|
|
2
|
+
import { TMoostAdapter, Moost, TMoostAdapterOptions } from 'moost';
|
|
3
|
+
import { WooksCli, TWooksCliOptions } from '@wooksjs/event-cli';
|
|
4
|
+
export { useCliContext } from '@wooksjs/event-cli';
|
|
5
|
+
|
|
6
|
+
type TFunction = Function;
|
|
7
|
+
|
|
8
|
+
interface TCliHandlerMeta {
|
|
9
|
+
path: string;
|
|
10
|
+
}
|
|
11
|
+
interface TMoostCliOpts {
|
|
12
|
+
/**
|
|
13
|
+
* WooksCli options or instance
|
|
14
|
+
*/
|
|
15
|
+
wooksCli?: WooksCli | TWooksCliOptions;
|
|
16
|
+
/**
|
|
17
|
+
* more internal logs are printed when true
|
|
18
|
+
*/
|
|
19
|
+
debug?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Array of cli options applicable to every cli command
|
|
22
|
+
*/
|
|
23
|
+
globalCliOptions?: {
|
|
24
|
+
keys: string[];
|
|
25
|
+
description?: string;
|
|
26
|
+
type?: TFunction;
|
|
27
|
+
}[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* ## Moost Cli Adapter
|
|
31
|
+
*
|
|
32
|
+
* Moost Adapter for CLI events
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* │ // Quick example
|
|
36
|
+
* │ import { MoostCli, Cli, CliOption, cliHelpInterceptor } from '@moostjs/event-cli'
|
|
37
|
+
* │ import { Moost, Param } from 'moost'
|
|
38
|
+
* │
|
|
39
|
+
* │ class MyApp extends Moost {
|
|
40
|
+
* │ @Cli('command/:arg')
|
|
41
|
+
* │ command(
|
|
42
|
+
* │ @Param('arg')
|
|
43
|
+
* │ arg: string,
|
|
44
|
+
* │ @CliOption('test', 't')
|
|
45
|
+
* │ test: boolean,
|
|
46
|
+
* │ ) {
|
|
47
|
+
* │ return `command run with flag arg=${ arg }, test=${ test }`
|
|
48
|
+
* │ }
|
|
49
|
+
* │ }
|
|
50
|
+
* │
|
|
51
|
+
* │ const app = new MyApp()
|
|
52
|
+
* │ app.applyGlobalInterceptors(cliHelpInterceptor())
|
|
53
|
+
* │
|
|
54
|
+
* │ const cli = new MoostCli()
|
|
55
|
+
* │ app.adapter(cli)
|
|
56
|
+
* │ app.init()
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
declare class MoostCli implements TMoostAdapter<TCliHandlerMeta> {
|
|
60
|
+
protected opts?: TMoostCliOpts | undefined;
|
|
61
|
+
protected cliApp: WooksCli;
|
|
62
|
+
protected optionTypes: Record<string, TFunction[]>;
|
|
63
|
+
constructor(opts?: TMoostCliOpts | undefined);
|
|
64
|
+
onNotFound(): Promise<unknown>;
|
|
65
|
+
protected moost?: Moost;
|
|
66
|
+
onInit(moost: Moost): void;
|
|
67
|
+
bindHandler<T extends object = object>(opts: TMoostAdapterOptions<TCliHandlerMeta, T>): void;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* ## Define CLI Option
|
|
72
|
+
* ### @ParameterDecorator
|
|
73
|
+
* Use together with @Description('...') to document cli option
|
|
74
|
+
*
|
|
75
|
+
* ```ts
|
|
76
|
+
* │ @Cli('command')
|
|
77
|
+
* │ command(
|
|
78
|
+
* │ @Description('Test option...')
|
|
79
|
+
* │ @CliOption('test', 't')
|
|
80
|
+
* │ test: boolean,
|
|
81
|
+
* │ ) {
|
|
82
|
+
* │ return `test=${ test }`
|
|
83
|
+
* │ }
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @param keys list of keys (short and long alternatives)
|
|
87
|
+
* @returns
|
|
88
|
+
*/
|
|
89
|
+
declare function CliOption(...keys: string[]): ParameterDecorator;
|
|
90
|
+
/**
|
|
91
|
+
* ## Define Global CLI Option
|
|
92
|
+
* ### @ClassDecorator
|
|
93
|
+
* The option described here will appear in every command instructions
|
|
94
|
+
* @param option keys and description of CLI option
|
|
95
|
+
* @returns
|
|
96
|
+
*/
|
|
97
|
+
declare function CliGlobalOption(option: {
|
|
98
|
+
keys: string[];
|
|
99
|
+
description?: string;
|
|
100
|
+
value?: string;
|
|
101
|
+
}): ClassDecorator;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* ## Define CLI Command
|
|
105
|
+
* ### @MethodDecorator
|
|
106
|
+
*
|
|
107
|
+
* Command path segments may be separated by / or space.
|
|
108
|
+
*
|
|
109
|
+
* For example the folowing path are interpreted the same:
|
|
110
|
+
* - "command test use:dev :name"
|
|
111
|
+
* - "command/test/use:dev/:name"
|
|
112
|
+
*
|
|
113
|
+
* Where name will become an argument
|
|
114
|
+
*
|
|
115
|
+
* @param path - command path
|
|
116
|
+
* @returns
|
|
117
|
+
*/
|
|
118
|
+
declare function Cli(path?: string): MethodDecorator;
|
|
119
|
+
/**
|
|
120
|
+
* ## Define CLI Command Alias
|
|
121
|
+
* ### @MethodDecorator
|
|
122
|
+
*
|
|
123
|
+
* Use it to define alias for @Cli('...') command
|
|
124
|
+
*
|
|
125
|
+
* @param path - command alias path
|
|
126
|
+
* @returns
|
|
127
|
+
*/
|
|
128
|
+
declare function CliAlias(alias: string): MethodDecorator;
|
|
129
|
+
/**
|
|
130
|
+
* ## Define CLI Example
|
|
131
|
+
* ### @MethodDecorator
|
|
132
|
+
*
|
|
133
|
+
* Use it to define example for Cli Help display
|
|
134
|
+
*
|
|
135
|
+
* @param path - command alias path
|
|
136
|
+
* @returns
|
|
137
|
+
*/
|
|
138
|
+
declare function CliExample(cmd: string, description?: string): MethodDecorator;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* ### Interceptor Factory for CliHelpRenderer
|
|
142
|
+
*
|
|
143
|
+
* By default intercepts cli calls with flag --help
|
|
144
|
+
* and prints help.
|
|
145
|
+
*
|
|
146
|
+
* ```js
|
|
147
|
+
* new Moost().applyGlobalInterceptors(cliHelpInterceptor({ colors: true }))
|
|
148
|
+
* ```
|
|
149
|
+
* @param opts {} { helpOptions: ['help', 'h'], colors: true } cli options to invoke help renderer
|
|
150
|
+
* @returns TInterceptorFn
|
|
151
|
+
*/
|
|
152
|
+
declare const cliHelpInterceptor: (opts?: {
|
|
153
|
+
/**
|
|
154
|
+
* CLI Options that invoke help
|
|
155
|
+
* ```js
|
|
156
|
+
* helpOptions: ['help', 'h']
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
helpOptions?: string[];
|
|
160
|
+
/**
|
|
161
|
+
* Enable colored help
|
|
162
|
+
*/
|
|
163
|
+
colors?: boolean;
|
|
164
|
+
/**
|
|
165
|
+
* Enable lookup for a command
|
|
166
|
+
*/
|
|
167
|
+
lookupLevel?: number;
|
|
168
|
+
}) => moost.TInterceptorFn;
|
|
169
|
+
/**
|
|
170
|
+
* ## @Decorator
|
|
171
|
+
* ### Interceptor Factory for CliHelpRenderer
|
|
172
|
+
*
|
|
173
|
+
* By default intercepts cli calls with flag --help
|
|
174
|
+
* and prints help.
|
|
175
|
+
*
|
|
176
|
+
* ```ts
|
|
177
|
+
* // default configuration
|
|
178
|
+
* • @CliHelpInterceptor({ helpOptions: 'help', colors: true })
|
|
179
|
+
*
|
|
180
|
+
* // additional option -h to invoke help renderer
|
|
181
|
+
* • @CliHelpInterceptor({ helpOptions: ['help', 'h'], colors: true })
|
|
182
|
+
*
|
|
183
|
+
* // redefine cli option to invoke help renderer
|
|
184
|
+
* • @CliHelpInterceptor({ helpOptions: ['usage'] })
|
|
185
|
+
* ```
|
|
186
|
+
*
|
|
187
|
+
* @param opts {} { helpOptions: ['help', 'h'], colors: true } cli options to invoke help renderer
|
|
188
|
+
* @returns Decorator
|
|
189
|
+
*/
|
|
190
|
+
declare const CliHelpInterceptor: (opts?: {
|
|
191
|
+
/**
|
|
192
|
+
* CLI Options that invoke help
|
|
193
|
+
* ```js
|
|
194
|
+
* helpOptions: ['help', 'h']
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
helpOptions?: string[] | undefined;
|
|
198
|
+
/**
|
|
199
|
+
* Enable colored help
|
|
200
|
+
*/
|
|
201
|
+
colors?: boolean | undefined;
|
|
202
|
+
/**
|
|
203
|
+
* Enable lookup for a command
|
|
204
|
+
*/
|
|
205
|
+
lookupLevel?: number | undefined;
|
|
206
|
+
} | undefined) => ClassDecorator & MethodDecorator;
|
|
207
|
+
|
|
208
|
+
export { Cli, CliAlias, CliExample, CliGlobalOption, CliHelpInterceptor, CliOption, MoostCli, type TCliHandlerMeta, type TMoostCliOpts, cliHelpInterceptor };
|