Skip to content

Commit 59592bb

Browse files
committed
adding static expect
1 parent b6ad0d7 commit 59592bb

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/event/EventTerminal.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@ export default class EventTerminal extends EventEmitter<Record<string, [Hash]>>
1616
this.output(message, variables, '\x1b[31m%s\x1b[0m');
1717
}
1818

19+
/**
20+
* Retrieves the first value found from the given flag/s in cli
21+
*/
22+
public static expect<T>(args: string[], flags: string[], defaults: T) {
23+
const params = this.params(args);
24+
for (const flag of flags) {
25+
if (params[flag]) {
26+
return params[flag] as T;
27+
}
28+
}
29+
return defaults;
30+
}
31+
1932
/**
2033
* Outputs an colorful (blue) log
2134
*/
@@ -61,7 +74,7 @@ export default class EventTerminal extends EventEmitter<Record<string, [Hash]>>
6174
* Creates the name space given the space
6275
* and sets the value to that name space
6376
*/
64-
public static params(...args: string[]) {
77+
public static params(args: string[]) {
6578
const params: Record<string, any> = {};
6679

6780
const format = (
@@ -224,7 +237,7 @@ export default class EventTerminal extends EventEmitter<Record<string, [Hash]>>
224237
*/
225238
public get params() {
226239
if (!this._params) {
227-
this._params = this.terminal.params(...this._args);
240+
this._params = this.terminal.params(this._args);
228241
}
229242
return { ...this._params };
230243
}

0 commit comments

Comments
 (0)