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