@vertaaux/cli 0.2.1 → 0.2.2
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/commands/audit.js +2 -2
- package/dist/utils/validators.d.ts +3 -3
- package/dist/utils/validators.js +11 -11
- package/package.json +1 -1
package/dist/commands/audit.js
CHANGED
|
@@ -403,7 +403,7 @@ async function executeAudit(targetUrl, options, config) {
|
|
|
403
403
|
if (format === "json") {
|
|
404
404
|
if (options.output) {
|
|
405
405
|
const output = JSON.stringify(createEnvelope(created, "audit"), null, 2);
|
|
406
|
-
const filePath = writeOutputToFile(output, options.output
|
|
406
|
+
const filePath = writeOutputToFile(output, options.output);
|
|
407
407
|
if (filePath && !quiet) {
|
|
408
408
|
console.error(`Report written to: ${filePath}`);
|
|
409
409
|
}
|
|
@@ -528,7 +528,7 @@ async function executeAudit(targetUrl, options, config) {
|
|
|
528
528
|
if (format === "json") {
|
|
529
529
|
if (options.output) {
|
|
530
530
|
const jsonStr = JSON.stringify(createEnvelope(filteredResult, "audit"), null, 2);
|
|
531
|
-
const filePath = writeOutputToFile(jsonStr, options.output
|
|
531
|
+
const filePath = writeOutputToFile(jsonStr, options.output);
|
|
532
532
|
if (filePath && !quiet) {
|
|
533
533
|
console.error(`Report written to: ${filePath}`);
|
|
534
534
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Pure validation functions for CLI option parsing.
|
|
3
3
|
*
|
|
4
|
-
* All validators throw Commander's
|
|
4
|
+
* All validators throw Commander's InvalidOptionArgumentError on failure,
|
|
5
5
|
* which integrates with Commander's built-in error handling pipeline.
|
|
6
6
|
* No process.exit calls -- callers decide error handling.
|
|
7
7
|
*
|
|
@@ -19,14 +19,14 @@ export interface NumericConstraint {
|
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Validate and parse a numeric string value.
|
|
22
|
-
* Throws
|
|
22
|
+
* Throws InvalidOptionArgumentError with descriptive message on failure.
|
|
23
23
|
*
|
|
24
24
|
* Uses Number() (not parseInt) to reject partial parses like "12abc".
|
|
25
25
|
*/
|
|
26
26
|
export declare function validateNumeric(value: string, name: string, constraints?: NumericConstraint): number;
|
|
27
27
|
/**
|
|
28
28
|
* Validate a string value against an allowed set.
|
|
29
|
-
* Throws
|
|
29
|
+
* Throws InvalidOptionArgumentError with "Did you mean?" suggestion on typos.
|
|
30
30
|
*/
|
|
31
31
|
export declare function validateEnum(value: string, name: string, allowed: readonly string[]): string;
|
|
32
32
|
export declare function parseTimeout(value: string): number;
|
package/dist/utils/validators.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Pure validation functions for CLI option parsing.
|
|
3
3
|
*
|
|
4
|
-
* All validators throw Commander's
|
|
4
|
+
* All validators throw Commander's InvalidOptionArgumentError on failure,
|
|
5
5
|
* which integrates with Commander's built-in error handling pipeline.
|
|
6
6
|
* No process.exit calls -- callers decide error handling.
|
|
7
7
|
*
|
|
8
8
|
* Includes Levenshtein distance for "Did you mean?" suggestions on enum typos.
|
|
9
9
|
*/
|
|
10
|
-
import {
|
|
10
|
+
import { InvalidOptionArgumentError } from "commander";
|
|
11
11
|
// ---------------------------------------------------------------------------
|
|
12
12
|
// Levenshtein distance (private)
|
|
13
13
|
// ---------------------------------------------------------------------------
|
|
@@ -52,26 +52,26 @@ export function closestMatch(input, candidates, maxDistance = 3) {
|
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
54
|
* Validate and parse a numeric string value.
|
|
55
|
-
* Throws
|
|
55
|
+
* Throws InvalidOptionArgumentError with descriptive message on failure.
|
|
56
56
|
*
|
|
57
57
|
* Uses Number() (not parseInt) to reject partial parses like "12abc".
|
|
58
58
|
*/
|
|
59
59
|
export function validateNumeric(value, name, constraints = {}) {
|
|
60
60
|
if (value.trim() === "") {
|
|
61
|
-
throw new
|
|
61
|
+
throw new InvalidOptionArgumentError(`Invalid value for --${name}: "${value}" is not a number`);
|
|
62
62
|
}
|
|
63
63
|
const parsed = Number(value);
|
|
64
64
|
if (Number.isNaN(parsed)) {
|
|
65
|
-
throw new
|
|
65
|
+
throw new InvalidOptionArgumentError(`Invalid value for --${name}: "${value}" is not a number`);
|
|
66
66
|
}
|
|
67
67
|
if (constraints.integer && !Number.isInteger(parsed)) {
|
|
68
|
-
throw new
|
|
68
|
+
throw new InvalidOptionArgumentError(`Invalid value for --${name}: "${value}" must be an integer`);
|
|
69
69
|
}
|
|
70
70
|
if (constraints.min !== undefined && parsed < constraints.min) {
|
|
71
|
-
throw new
|
|
71
|
+
throw new InvalidOptionArgumentError(`Invalid value for --${name}: ${parsed} is below minimum ${constraints.min}`);
|
|
72
72
|
}
|
|
73
73
|
if (constraints.max !== undefined && parsed > constraints.max) {
|
|
74
|
-
throw new
|
|
74
|
+
throw new InvalidOptionArgumentError(`Invalid value for --${name}: ${parsed} exceeds maximum ${constraints.max}`);
|
|
75
75
|
}
|
|
76
76
|
return parsed;
|
|
77
77
|
}
|
|
@@ -80,20 +80,20 @@ export function validateNumeric(value, name, constraints = {}) {
|
|
|
80
80
|
// ---------------------------------------------------------------------------
|
|
81
81
|
/**
|
|
82
82
|
* Validate a string value against an allowed set.
|
|
83
|
-
* Throws
|
|
83
|
+
* Throws InvalidOptionArgumentError with "Did you mean?" suggestion on typos.
|
|
84
84
|
*/
|
|
85
85
|
export function validateEnum(value, name, allowed) {
|
|
86
86
|
if (allowed.includes(value))
|
|
87
87
|
return value;
|
|
88
88
|
const suggestion = closestMatch(value, allowed);
|
|
89
89
|
const hint = suggestion ? ` Did you mean "${suggestion}"?` : "";
|
|
90
|
-
throw new
|
|
90
|
+
throw new InvalidOptionArgumentError(`Unknown value "${value}" for --${name}.${hint} Valid values: ${allowed.join(", ")}`);
|
|
91
91
|
}
|
|
92
92
|
// ---------------------------------------------------------------------------
|
|
93
93
|
// Convenience Commander parser factories
|
|
94
94
|
// ---------------------------------------------------------------------------
|
|
95
95
|
// These are used as the 3rd argument to Commander's .option() method.
|
|
96
|
-
// Commander catches
|
|
96
|
+
// Commander catches InvalidOptionArgumentError and routes it through configureOutput.
|
|
97
97
|
export function parseTimeout(value) {
|
|
98
98
|
return validateNumeric(value, "timeout", { min: 1, max: 300000, integer: true });
|
|
99
99
|
}
|