@wooksjs/event-cli 0.3.11 → 0.4.0

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 CHANGED
@@ -167,14 +167,16 @@ class WooksCli extends wooks.WooksAdapterBase {
167
167
  *
168
168
  * @param _argv optionally overwrite `process.argv.slice(2)` with your `argv` array
169
169
  */
170
- run(_argv) {
170
+ run(_argv, _opts) {
171
171
  var _a, _b;
172
172
  return __awaiter(this, void 0, void 0, function* () {
173
173
  const argv = _argv || process.argv.slice(2);
174
- const pathParams = argv.filter(a => !a.startsWith('-'));
174
+ const parsedFlags = minimist(argv, _opts);
175
+ const pathParams = parsedFlags._;
175
176
  const path = '/' +
176
177
  pathParams.map((v) => encodeURI(v).replace(/\//g, '%2F')).join('/');
177
- const { restoreCtx, clearCtx, store } = createCliContext({ argv, pathParams, cliHelp: this.cliHelp, command: path.replace(/\//g, ' ').trim() }, this.mergeEventOptions((_a = this.opts) === null || _a === void 0 ? void 0 : _a.eventOptions));
178
+ const { restoreCtx, clearCtx, store } = createCliContext({ opts: _opts, argv, pathParams, cliHelp: this.cliHelp, command: path.replace(/\//g, ' ').trim() }, this.mergeEventOptions((_a = this.opts) === null || _a === void 0 ? void 0 : _a.eventOptions));
179
+ store('flags').value = parsedFlags;
178
180
  this.computeAliases();
179
181
  const { handlers: foundHandlers, firstStatic } = this.wooks.lookup('CLI', path);
180
182
  if (typeof firstStatic === 'string') {
@@ -409,7 +411,8 @@ function useCliOptions() {
409
411
  const { store } = useCliContext();
410
412
  const flags = store('flags');
411
413
  if (!flags.value) {
412
- flags.value = minimist(store('event').value.argv);
414
+ const event = store('event');
415
+ flags.value = minimist(event.value.argv, event.get('opts'));
413
416
  }
414
417
  return flags.value;
415
418
  }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { CliHelpRenderer } from '@prostojs/cli-help';
2
+ import minimist from 'minimist';
2
3
  import { TCliEntry } from '@prostojs/cli-help';
3
4
  import { TCliHelpOptions } from '@prostojs/cli-help';
4
5
  import { TConsoleBase } from '@prostojs/logger';
@@ -56,6 +57,7 @@ export declare interface TCliEventData {
56
57
  argv: string[];
57
58
  pathParams: string[];
58
59
  command: string;
60
+ opts?: minimist.Opts;
59
61
  type: 'CLI';
60
62
  cliHelp: TCliHelpRenderer;
61
63
  }
@@ -267,7 +269,7 @@ export declare class WooksCli extends WooksAdapterBase {
267
269
  *
268
270
  * @param _argv optionally overwrite `process.argv.slice(2)` with your `argv` array
269
271
  */
270
- run(_argv?: string[]): Promise<void>;
272
+ run(_argv?: string[], _opts?: minimist.Opts): Promise<void>;
271
273
  protected onError(e: Error): void;
272
274
  /**
273
275
  * Triggers `unknown command` processing and callbacks
package/dist/index.mjs CHANGED
@@ -165,14 +165,16 @@ class WooksCli extends WooksAdapterBase {
165
165
  *
166
166
  * @param _argv optionally overwrite `process.argv.slice(2)` with your `argv` array
167
167
  */
168
- run(_argv) {
168
+ run(_argv, _opts) {
169
169
  var _a, _b;
170
170
  return __awaiter(this, void 0, void 0, function* () {
171
171
  const argv = _argv || process.argv.slice(2);
172
- const pathParams = argv.filter(a => !a.startsWith('-'));
172
+ const parsedFlags = minimist(argv, _opts);
173
+ const pathParams = parsedFlags._;
173
174
  const path = '/' +
174
175
  pathParams.map((v) => encodeURI(v).replace(/\//g, '%2F')).join('/');
175
- const { restoreCtx, clearCtx, store } = createCliContext({ argv, pathParams, cliHelp: this.cliHelp, command: path.replace(/\//g, ' ').trim() }, this.mergeEventOptions((_a = this.opts) === null || _a === void 0 ? void 0 : _a.eventOptions));
176
+ const { restoreCtx, clearCtx, store } = createCliContext({ opts: _opts, argv, pathParams, cliHelp: this.cliHelp, command: path.replace(/\//g, ' ').trim() }, this.mergeEventOptions((_a = this.opts) === null || _a === void 0 ? void 0 : _a.eventOptions));
177
+ store('flags').value = parsedFlags;
176
178
  this.computeAliases();
177
179
  const { handlers: foundHandlers, firstStatic } = this.wooks.lookup('CLI', path);
178
180
  if (typeof firstStatic === 'string') {
@@ -407,7 +409,8 @@ function useCliOptions() {
407
409
  const { store } = useCliContext();
408
410
  const flags = store('flags');
409
411
  if (!flags.value) {
410
- flags.value = minimist(store('event').value.argv);
412
+ const event = store('event');
413
+ flags.value = minimist(event.value.argv, event.get('opts'));
411
414
  }
412
415
  return flags.value;
413
416
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wooksjs/event-cli",
3
- "version": "0.3.11",
3
+ "version": "0.4.0",
4
4
  "description": "@wooksjs/event-cli",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -31,8 +31,8 @@
31
31
  "url": "https://github.com/wooksjs/wooksjs/issues"
32
32
  },
33
33
  "peerDependencies": {
34
- "wooks": "0.3.11",
35
- "@wooksjs/event-core": "0.3.11"
34
+ "wooks": "0.4.0",
35
+ "@wooksjs/event-core": "0.4.0"
36
36
  },
37
37
  "dependencies": {
38
38
  "minimist": "^1.2.6",