@henderea/arg-helper 1.2.4 → 1.2.6

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@henderea/arg-helper",
3
- "version": "1.2.4",
3
+ "version": "1.2.6",
4
4
  "description": "A utility wrapper around the arg command-line parser",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -18,12 +18,12 @@
18
18
  "escalade": "^3.1.1"
19
19
  },
20
20
  "devDependencies": {
21
- "@typescript-eslint/eslint-plugin": "^5.58.0",
22
- "@typescript-eslint/parser": "^5.58.0",
23
- "eslint": "^8.38.0",
24
- "eslint-config-henderea": "1.1.7",
25
- "eslint-plugin-import": "^2.27.5",
26
- "typescript": "^5.0.4"
21
+ "@typescript-eslint/eslint-plugin": "^6.11.0",
22
+ "@typescript-eslint/parser": "^6.11.0",
23
+ "eslint": "^8.54.0",
24
+ "eslint-config-henderea": "^1.1.18",
25
+ "eslint-plugin-import": "^2.29.0",
26
+ "typescript": "^5.2.2"
27
27
  },
28
28
  "files": [
29
29
  "src/**/*"
package/src/index.d.ts CHANGED
@@ -18,9 +18,9 @@ declare namespace argHelper {
18
18
  helpText(helpText: string, ...names: Array<string>): this;
19
19
  findVersion(callerPath: string, ...names: Array<string>): this;
20
20
  version(packageJsonFile: string, ...names: Array<string>): this;
21
+ withVersion(version: string, ...names: Array<string>): this;
21
22
  parse(argv?: Array<any> | null): Map<any>;
22
23
  get argv(): Map<any>;
23
- static terminalWidth(multiplier?: number): number;
24
24
  }
25
25
 
26
26
  export interface argParser {
package/src/index.js CHANGED
@@ -8,6 +8,7 @@ class ArgParser {
8
8
  this._names = {};
9
9
  this._helpText = null;
10
10
  this._packageJsonFile = null;
11
+ this._version = null;
11
12
  }
12
13
 
13
14
  flag(name, ...names) {
@@ -49,6 +50,10 @@ class ArgParser {
49
50
  this._packageJsonFile = packageJsonFile;
50
51
  return this.bool('version', ...names);
51
52
  }
53
+ withVersion(version, ...names) {
54
+ this._version = version;
55
+ return this.bool('version', ...names);
56
+ }
52
57
 
53
58
  parse(argv = null) {
54
59
  let config = { permissive: true };
@@ -65,11 +70,16 @@ class ArgParser {
65
70
  console.log(this._helpText);
66
71
  process.exit(0);
67
72
  }
68
- if(rv.version && this._packageJsonFile && fs.existsSync(this._packageJsonFile)) {
69
- const packageJson = JSON.parse(fs.readFileSync(this._packageJsonFile));
70
- const version = packageJson.version;
71
- if(version) {
72
- console.log(version);
73
+ if(rv.version) {
74
+ if(this._packageJsonFile && fs.existsSync(this._packageJsonFile)) {
75
+ const packageJson = JSON.parse(fs.readFileSync(this._packageJsonFile));
76
+ const version = packageJson.version;
77
+ if(version) {
78
+ console.log(version);
79
+ process.exit(0);
80
+ }
81
+ } else if(this._version) {
82
+ console.log(this._version);
73
83
  process.exit(0);
74
84
  }
75
85
  }