breadc 0.4.4 → 0.4.5

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
@@ -240,6 +240,10 @@ class Breadc {
240
240
  constructor(name, option) {
241
241
  this.options = [];
242
242
  this.commands = [];
243
+ this.callbacks = {
244
+ pre: [],
245
+ post: []
246
+ };
243
247
  this.name = name;
244
248
  this._version = option.version ?? "unknown";
245
249
  this.description = option.description;
@@ -381,10 +385,16 @@ class Breadc {
381
385
  options
382
386
  };
383
387
  }
388
+ on(event, fn) {
389
+ this.callbacks[event].push(fn);
390
+ }
384
391
  async run(args) {
385
392
  const parsed = this.parse(args);
386
393
  if (parsed.command) {
387
- return await parsed.command.run(...parsed.arguments, parsed.options);
394
+ await Promise.all(this.callbacks.pre.map((fn) => fn(parsed.options)));
395
+ const returnValue = await parsed.command.run(...parsed.arguments, parsed.options);
396
+ await Promise.all(this.callbacks.post.map((fn) => fn(parsed.options)));
397
+ return returnValue;
388
398
  }
389
399
  }
390
400
  }
package/dist/index.d.ts CHANGED
@@ -117,6 +117,8 @@ declare class Breadc<GlobalOption extends object = {}> {
117
117
  command<F extends string>(format: F, description: string, config?: Omit<CommandConfig, 'description'>): Command<F, GlobalOption>;
118
118
  command<F extends string>(format: F, config?: CommandConfig): Command<F, GlobalOption>;
119
119
  parse(args: string[]): ParseResult;
120
+ private readonly callbacks;
121
+ on(event: 'pre' | 'post', fn: (option: GlobalOption) => void | Promise<void>): void;
120
122
  run(args: string[]): Promise<any>;
121
123
  }
122
124
 
package/dist/index.mjs CHANGED
@@ -233,6 +233,10 @@ class Breadc {
233
233
  constructor(name, option) {
234
234
  this.options = [];
235
235
  this.commands = [];
236
+ this.callbacks = {
237
+ pre: [],
238
+ post: []
239
+ };
236
240
  this.name = name;
237
241
  this._version = option.version ?? "unknown";
238
242
  this.description = option.description;
@@ -374,10 +378,16 @@ class Breadc {
374
378
  options
375
379
  };
376
380
  }
381
+ on(event, fn) {
382
+ this.callbacks[event].push(fn);
383
+ }
377
384
  async run(args) {
378
385
  const parsed = this.parse(args);
379
386
  if (parsed.command) {
380
- return await parsed.command.run(...parsed.arguments, parsed.options);
387
+ await Promise.all(this.callbacks.pre.map((fn) => fn(parsed.options)));
388
+ const returnValue = await parsed.command.run(...parsed.arguments, parsed.options);
389
+ await Promise.all(this.callbacks.post.map((fn) => fn(parsed.options)));
390
+ return returnValue;
381
391
  }
382
392
  }
383
393
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "breadc",
3
- "version": "0.4.4",
3
+ "version": "0.4.5",
4
4
  "description": "Yet another Command Line Application Framework with fully strong TypeScript support",
5
5
  "keywords": [
6
6
  "cli",