Skip to content

Commit 4ec1630

Browse files
committed
1.3.0
1 parent 5c8aea8 commit 4ec1630

5 files changed

Lines changed: 33 additions & 5 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@grandlinex/easy-cli",
3-
"version": "1.2.2",
3+
"version": "1.3.0",
44
"description": "Cli lib to perform common tasks",
55
"main": "dist/index.js",
66
"module": "dist/index.js",

src/CommandHandler.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export default abstract class CommandHandler<X = any>
2020
extends CoreLogChannel
2121
implements IHandler<X>
2222
{
23+
private statics: CMap<string, string>;
24+
2325
private baseCmd: CMap<string, ShellCommand>;
2426

2527
private cmdMap: CMap<string, ShellCommand>;
@@ -58,6 +60,7 @@ export default abstract class CommandHandler<X = any>
5860
this.logger = l;
5961
this.cmdMap = new CMap();
6062
this.baseCmd = new CMap();
63+
this.statics = new CMap();
6164
const props = { logger: this.logger, handler: this };
6265
this.addBaseCmd(
6366
new HelpAction(props),
@@ -66,6 +69,17 @@ export default abstract class CommandHandler<X = any>
6669
);
6770
}
6871

72+
setStatic(key: string, value: any): void {
73+
this.statics.set(key, value);
74+
}
75+
76+
getStatic(key: string): string {
77+
if (!this.statics.has(key)) {
78+
throw this.lError(`Static key ${key} not found`);
79+
}
80+
return this.statics.get(key)!;
81+
}
82+
6983
getCmdName(): string {
7084
return this.cmdName;
7185
}

src/class/ShellComand.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,8 @@ export abstract class ShellCommand<T = any> extends CoreLogChannel {
9292
}
9393
return absPath;
9494
}
95+
96+
protected getStatic(key: string): string | undefined {
97+
return this.handler.getStatic(key);
98+
}
9599
}

src/lib/types.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ export interface IHandler<X = any> {
3333
* get data from the command handler
3434
*/
3535
getData(): X | null;
36+
37+
/**
38+
* Set a static value
39+
* @param key
40+
* @param value
41+
*/
42+
setStatic(key: string, value: any): void;
43+
/**
44+
*
45+
* @param key
46+
*/
47+
getStatic(key: string): string;
3648
}
3749

3850
export interface IArgs {

src/utils/Version.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
import Path from 'path';
22
import * as fs from 'fs';
3-
import * as url from 'url';
43

5-
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
64
export default function getVersion(): string {
75
const parentFile = Path.join(
8-
__dirname,
6+
import.meta.dirname,
97
'..',
108
'..',
119
'..',
1210
'..',
1311
'..',
1412
'package.json',
1513
);
16-
const file = Path.join(__dirname, '..', '..', 'package.json');
14+
const file = Path.join(import.meta.dirname, '..', '..', 'package.json');
1715

1816
let pck;
1917
if (fs.existsSync(parentFile)) {

0 commit comments

Comments
 (0)