@travetto/cli 2.2.0 → 2.2.1

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@travetto/cli",
3
3
  "displayName": "Command Line Interface",
4
- "version": "2.2.0",
4
+ "version": "2.2.1",
5
5
  "description": "CLI infrastructure for travetto framework",
6
6
  "keywords": [
7
7
  "cli",
@@ -27,7 +27,7 @@
27
27
  "directory": "module/cli"
28
28
  },
29
29
  "dependencies": {
30
- "@travetto/base": "^2.2.0",
30
+ "@travetto/base": "^2.2.1",
31
31
  "commander": "^9.4.0"
32
32
  },
33
33
  "docDependencies": {
@@ -6,9 +6,9 @@ import { CliUtil } from './util';
6
6
 
7
7
  type Completion = Record<string, string[]>;
8
8
 
9
- type ParamPrimitive = string | number | boolean | string[] | number[];
9
+ type OptionPrimitive = string | number | boolean | string[] | number[];
10
10
 
11
- type ParamConfig<K extends ParamPrimitive = ParamPrimitive> = {
11
+ export type OptionConfig<K extends OptionPrimitive = OptionPrimitive> = {
12
12
  type?: Function;
13
13
  key?: string;
14
14
  short?: string | false;
@@ -21,14 +21,14 @@ type ParamConfig<K extends ParamPrimitive = ParamPrimitive> = {
21
21
  };
22
22
 
23
23
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
24
- type ParamMap<T = any> = { [key in keyof T]: T[key] extends ParamPrimitive ? ParamConfig<T[key]> : never };
24
+ type OptionMap<T = any> = { [key in keyof T]: T[key] extends OptionPrimitive ? OptionConfig<T[key]> : never };
25
25
 
26
- type Shape<M extends ParamMap> = { [k in keyof M]: Exclude<M[k]['def'], undefined> };
26
+ type Shape<M extends OptionMap> = { [k in keyof M]: Exclude<M[k]['def'], undefined> };
27
27
 
28
28
  /**
29
29
  * Base plugin
30
30
  */
31
- export abstract class BasePlugin<V extends ParamMap = ParamMap> {
31
+ export abstract class BasePlugin<V extends OptionMap> {
32
32
  /**
33
33
  * Command object
34
34
  */
@@ -74,7 +74,7 @@ export abstract class BasePlugin<V extends ParamMap = ParamMap> {
74
74
  /**
75
75
  * Define option
76
76
  */
77
- option(cfg: ParamConfig<string>): ParamConfig<string> {
77
+ option(cfg: OptionConfig<string>): OptionConfig<string> {
78
78
  if (cfg.combine && cfg.def) {
79
79
  cfg.def = cfg.combine(cfg.def, cfg.def);
80
80
  }
@@ -84,8 +84,8 @@ export abstract class BasePlugin<V extends ParamMap = ParamMap> {
84
84
  /**
85
85
  * Define option
86
86
  */
87
- choiceOption<K extends string | number>({ choices, ...cfg }: ParamConfig<K> & { choices: K[] | readonly K[] }): ParamConfig<K> {
88
- const config: ParamConfig<K> = {
87
+ choiceOption<K extends string | number>({ choices, ...cfg }: OptionConfig<K> & { choices: K[] | readonly K[] }): OptionConfig<K> {
88
+ const config: OptionConfig<K> = {
89
89
  type: String,
90
90
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
91
91
  combine: (v: string, acc: K): K => choices.includes(v as K) ? v as K : acc,
@@ -99,7 +99,7 @@ export abstract class BasePlugin<V extends ParamMap = ParamMap> {
99
99
  /**
100
100
  * Define list option
101
101
  */
102
- listOption(cfg: ParamConfig<string[]>): ParamConfig<string[]> {
102
+ listOption(cfg: OptionConfig<string[]>): OptionConfig<string[]> {
103
103
  return {
104
104
  type: String,
105
105
  def: [],
@@ -112,7 +112,7 @@ export abstract class BasePlugin<V extends ParamMap = ParamMap> {
112
112
  /**
113
113
  * Define bool option
114
114
  */
115
- boolOption(cfg: ParamConfig<boolean>): ParamConfig<boolean> {
115
+ boolOption(cfg: OptionConfig<boolean>): OptionConfig<boolean> {
116
116
  return {
117
117
  type: Boolean,
118
118
  combine: CliUtil.toBool.bind(CliUtil),
@@ -124,7 +124,7 @@ export abstract class BasePlugin<V extends ParamMap = ParamMap> {
124
124
  /**
125
125
  * Define int option
126
126
  */
127
- intOption({ lower, upper, ...cfg }: ParamConfig<number> & { lower?: number, upper?: number }): ParamConfig<number> {
127
+ intOption({ lower, upper, ...cfg }: OptionConfig<number> & { lower?: number, upper?: number }): OptionConfig<number> {
128
128
  return {
129
129
  type: Number,
130
130
  combine: CliUtil.toInt.bind(CliUtil, lower, upper),
@@ -143,9 +143,8 @@ export abstract class BasePlugin<V extends ParamMap = ParamMap> {
143
143
  /**
144
144
  * Expose configuration as constrained typed object
145
145
  */
146
- get cmd(): Shape<ReturnType<Exclude<this['getOptions'], undefined>>> {
147
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
148
- return this.#cmd.opts() as Shape<ReturnType<Exclude<this['getOptions'], undefined>>>;
146
+ get cmd(): Shape<V> {
147
+ return this.#cmd.opts();
149
148
  }
150
149
 
151
150
  /**
@@ -169,7 +168,7 @@ export abstract class BasePlugin<V extends ParamMap = ParamMap> {
169
168
  * Process all options into final set before registering with commander
170
169
  * @returns
171
170
  */
172
- async finalizeOptions(): Promise<ParamConfig[]> {
171
+ async finalizeOptions(): Promise<OptionConfig[]> {
173
172
  const opts = this.getOptions?.();
174
173
  const used = new Set();
175
174
 
package/src/util.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import * as timers from 'timers/promises';
1
2
  import * as readline from 'readline';
2
3
  import { Writable } from 'stream';
3
4
 
@@ -94,10 +95,6 @@ export class CliUtil {
94
95
  }));
95
96
  }
96
97
 
97
- static sleep(ms: number): Promise<void> {
98
- return new Promise(r => setTimeout(r, ms));
99
- }
100
-
101
98
  /**
102
99
  * Waiting message with a callback to end
103
100
  *
@@ -129,12 +126,12 @@ export class CliUtil {
129
126
  .finally(() => done = true);
130
127
 
131
128
  if (delay) {
132
- await Promise.race([this.sleep(delay), final]);
129
+ await Promise.race([timers.setTimeout(delay), final]);
133
130
  }
134
131
 
135
132
  while (!done) {
136
133
  await writeLine(`${this.#waitState[i = (i + 1) % this.#waitState.length]} ${message}`);
137
- await this.sleep(50);
134
+ await timers.setTimeout(50);
138
135
  }
139
136
 
140
137
  if (i >= 0) {