@optique/run 0.9.0-dev.176 → 0.9.0-dev.178
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/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/valueparser.cjs +20 -1
- package/dist/valueparser.d.cts +104 -42
- package/dist/valueparser.d.ts +104 -42
- package/dist/valueparser.js +20 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { RunOptions, run } from "./run.cjs";
|
|
2
|
-
import { PathOptions, path } from "./valueparser.cjs";
|
|
2
|
+
import { PathErrorOptions, PathOptions, PathOptionsBase, PathOptionsMustExist, PathOptionsMustNotExist, PathOptionsNoExistenceCheck, path } from "./valueparser.cjs";
|
|
3
3
|
import { PrintErrorOptions, PrintOptions, Printer, PrinterOptions, createPrinter, print, printError } from "./print.cjs";
|
|
4
|
-
export { PathOptions, PrintErrorOptions, PrintOptions, Printer, PrinterOptions, RunOptions, createPrinter, path, print, printError, run };
|
|
4
|
+
export { PathErrorOptions, PathOptions, PathOptionsBase, PathOptionsMustExist, PathOptionsMustNotExist, PathOptionsNoExistenceCheck, PrintErrorOptions, PrintOptions, Printer, PrinterOptions, RunOptions, createPrinter, path, print, printError, run };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { RunOptions, run } from "./run.js";
|
|
2
|
-
import { PathOptions, path } from "./valueparser.js";
|
|
2
|
+
import { PathErrorOptions, PathOptions, PathOptionsBase, PathOptionsMustExist, PathOptionsMustNotExist, PathOptionsNoExistenceCheck, path } from "./valueparser.js";
|
|
3
3
|
import { PrintErrorOptions, PrintOptions, Printer, PrinterOptions, createPrinter, print, printError } from "./print.js";
|
|
4
|
-
export { PathOptions, PrintErrorOptions, PrintOptions, Printer, PrinterOptions, RunOptions, createPrinter, path, print, printError, run };
|
|
4
|
+
export { PathErrorOptions, PathOptions, PathOptionsBase, PathOptionsMustExist, PathOptionsMustNotExist, PathOptionsNoExistenceCheck, PrintErrorOptions, PrintOptions, Printer, PrinterOptions, RunOptions, createPrinter, path, print, printError, run };
|
package/dist/valueparser.cjs
CHANGED
|
@@ -40,7 +40,9 @@ const node_fs = require_rolldown_runtime.__toESM(require("node:fs"));
|
|
|
40
40
|
* ```
|
|
41
41
|
*/
|
|
42
42
|
function path(options = {}) {
|
|
43
|
-
const { metavar = "PATH",
|
|
43
|
+
const { metavar = "PATH", type = "either", allowCreate = false, extensions } = options;
|
|
44
|
+
const mustExist = "mustExist" in options ? options.mustExist : false;
|
|
45
|
+
const mustNotExist = "mustNotExist" in options ? options.mustNotExist : false;
|
|
44
46
|
return {
|
|
45
47
|
metavar,
|
|
46
48
|
parse(input) {
|
|
@@ -54,6 +56,23 @@ function path(options = {}) {
|
|
|
54
56
|
};
|
|
55
57
|
}
|
|
56
58
|
}
|
|
59
|
+
if (mustNotExist) {
|
|
60
|
+
if ((0, node_fs.existsSync)(input)) return {
|
|
61
|
+
success: false,
|
|
62
|
+
error: options.errors?.pathAlreadyExists ? typeof options.errors.pathAlreadyExists === "function" ? options.errors.pathAlreadyExists(input) : options.errors.pathAlreadyExists : __optique_core_message.message`Path ${(0, __optique_core_message.text)(input)} already exists.`
|
|
63
|
+
};
|
|
64
|
+
if (allowCreate) {
|
|
65
|
+
const parentDir = (0, node_path.dirname)(input);
|
|
66
|
+
if (!(0, node_fs.existsSync)(parentDir)) return {
|
|
67
|
+
success: false,
|
|
68
|
+
error: options.errors?.parentNotFound ? typeof options.errors.parentNotFound === "function" ? options.errors.parentNotFound(parentDir) : options.errors.parentNotFound : __optique_core_message.message`Parent directory ${(0, __optique_core_message.text)(parentDir)} does not exist.`
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
success: true,
|
|
73
|
+
value: input
|
|
74
|
+
};
|
|
75
|
+
}
|
|
57
76
|
if (mustExist) {
|
|
58
77
|
if (!(0, node_fs.existsSync)(input)) return {
|
|
59
78
|
success: false,
|
package/dist/valueparser.d.cts
CHANGED
|
@@ -4,28 +4,69 @@ import { ValueParser } from "@optique/core/valueparser";
|
|
|
4
4
|
//#region src/valueparser.d.ts
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Custom error messages for path validation failures.
|
|
8
|
+
* @since 0.5.0
|
|
8
9
|
*/
|
|
9
|
-
interface
|
|
10
|
+
interface PathErrorOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Custom error message when file extension is invalid.
|
|
13
|
+
* Can be a static message or a function that receives input, expected
|
|
14
|
+
* extensions, and actual extension.
|
|
15
|
+
* @since 0.5.0
|
|
16
|
+
*/
|
|
17
|
+
invalidExtension?: Message | ((input: string, extensions: readonly string[], actualExtension: string) => Message);
|
|
18
|
+
/**
|
|
19
|
+
* Custom error message when path does not exist.
|
|
20
|
+
* Can be a static message or a function that receives the input path.
|
|
21
|
+
* @since 0.5.0
|
|
22
|
+
*/
|
|
23
|
+
pathNotFound?: Message | ((input: string) => Message);
|
|
24
|
+
/**
|
|
25
|
+
* Custom error message when path already exists (used with
|
|
26
|
+
* {@link PathOptions.mustNotExist}).
|
|
27
|
+
* Can be a static message or a function that receives the input path.
|
|
28
|
+
* @since 0.9.0
|
|
29
|
+
*/
|
|
30
|
+
pathAlreadyExists?: Message | ((input: string) => Message);
|
|
31
|
+
/**
|
|
32
|
+
* Custom error message when path is expected to be a file but isn't.
|
|
33
|
+
* Can be a static message or a function that receives the input path.
|
|
34
|
+
* @since 0.5.0
|
|
35
|
+
*/
|
|
36
|
+
notAFile?: Message | ((input: string) => Message);
|
|
37
|
+
/**
|
|
38
|
+
* Custom error message when path is expected to be a directory but isn't.
|
|
39
|
+
* Can be a static message or a function that receives the input path.
|
|
40
|
+
* @since 0.5.0
|
|
41
|
+
*/
|
|
42
|
+
notADirectory?: Message | ((input: string) => Message);
|
|
43
|
+
/**
|
|
44
|
+
* Custom error message when parent directory does not exist for new files.
|
|
45
|
+
* Can be a static message or a function that receives the parent directory
|
|
46
|
+
* path.
|
|
47
|
+
* @since 0.5.0
|
|
48
|
+
*/
|
|
49
|
+
parentNotFound?: Message | ((parentDir: string) => Message);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Base configuration options shared by all {@link PathOptions} variants.
|
|
53
|
+
*/
|
|
54
|
+
interface PathOptionsBase {
|
|
10
55
|
/**
|
|
11
56
|
* The metavariable name for this parser, e.g., `"FILE"`, `"DIR"`.
|
|
12
57
|
* @default "PATH"
|
|
13
58
|
*/
|
|
14
59
|
readonly metavar?: string;
|
|
15
|
-
/**
|
|
16
|
-
* Whether the path must exist on the filesystem.
|
|
17
|
-
* @default false
|
|
18
|
-
*/
|
|
19
|
-
readonly mustExist?: boolean;
|
|
20
60
|
/**
|
|
21
61
|
* Expected type of path (file, directory, or either).
|
|
22
|
-
* Only checked when {@link mustExist} is true
|
|
62
|
+
* Only checked when {@link PathOptionsMustExist.mustExist} is `true`.
|
|
23
63
|
* @default "either"
|
|
24
64
|
*/
|
|
25
65
|
readonly type?: "file" | "directory" | "either";
|
|
26
66
|
/**
|
|
27
67
|
* Whether to allow creating new files/directories.
|
|
28
|
-
* When true and mustExist is false
|
|
68
|
+
* When `true` and {@link PathOptionsMustExist.mustExist} is `false`,
|
|
69
|
+
* validates that parent directory exists.
|
|
29
70
|
* @default false
|
|
30
71
|
*/
|
|
31
72
|
readonly allowCreate?: boolean;
|
|
@@ -38,39 +79,60 @@ interface PathOptions {
|
|
|
38
79
|
* Custom error messages for path validation failures.
|
|
39
80
|
* @since 0.5.0
|
|
40
81
|
*/
|
|
41
|
-
readonly errors?:
|
|
42
|
-
/**
|
|
43
|
-
* Custom error message when file extension is invalid.
|
|
44
|
-
* Can be a static message or a function that receives input, expected extensions, and actual extension.
|
|
45
|
-
* @since 0.5.0
|
|
46
|
-
*/
|
|
47
|
-
invalidExtension?: Message | ((input: string, extensions: readonly string[], actualExtension: string) => Message);
|
|
48
|
-
/**
|
|
49
|
-
* Custom error message when path does not exist.
|
|
50
|
-
* Can be a static message or a function that receives the input path.
|
|
51
|
-
* @since 0.5.0
|
|
52
|
-
*/
|
|
53
|
-
pathNotFound?: Message | ((input: string) => Message);
|
|
54
|
-
/**
|
|
55
|
-
* Custom error message when path is expected to be a file but isn't.
|
|
56
|
-
* Can be a static message or a function that receives the input path.
|
|
57
|
-
* @since 0.5.0
|
|
58
|
-
*/
|
|
59
|
-
notAFile?: Message | ((input: string) => Message);
|
|
60
|
-
/**
|
|
61
|
-
* Custom error message when path is expected to be a directory but isn't.
|
|
62
|
-
* Can be a static message or a function that receives the input path.
|
|
63
|
-
* @since 0.5.0
|
|
64
|
-
*/
|
|
65
|
-
notADirectory?: Message | ((input: string) => Message);
|
|
66
|
-
/**
|
|
67
|
-
* Custom error message when parent directory does not exist for new files.
|
|
68
|
-
* Can be a static message or a function that receives the parent directory path.
|
|
69
|
-
* @since 0.5.0
|
|
70
|
-
*/
|
|
71
|
-
parentNotFound?: Message | ((parentDir: string) => Message);
|
|
72
|
-
};
|
|
82
|
+
readonly errors?: PathErrorOptions;
|
|
73
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Configuration options for when the path must exist.
|
|
86
|
+
*/
|
|
87
|
+
interface PathOptionsMustExist extends PathOptionsBase {
|
|
88
|
+
/**
|
|
89
|
+
* When `true`, the path must exist on the filesystem.
|
|
90
|
+
*/
|
|
91
|
+
readonly mustExist: true;
|
|
92
|
+
/**
|
|
93
|
+
* Cannot be used together with {@link mustExist}.
|
|
94
|
+
*/
|
|
95
|
+
readonly mustNotExist?: never;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Configuration options for when the path must not exist.
|
|
99
|
+
* @since 0.9.0
|
|
100
|
+
*/
|
|
101
|
+
interface PathOptionsMustNotExist extends PathOptionsBase {
|
|
102
|
+
/**
|
|
103
|
+
* Cannot be used together with {@link mustNotExist}.
|
|
104
|
+
*/
|
|
105
|
+
readonly mustExist?: never;
|
|
106
|
+
/**
|
|
107
|
+
* When `true`, the path must not exist on the filesystem.
|
|
108
|
+
* Useful for output files to prevent accidental overwrites.
|
|
109
|
+
* @since 0.9.0
|
|
110
|
+
*/
|
|
111
|
+
readonly mustNotExist: true;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Configuration options when no existence check is required.
|
|
115
|
+
*/
|
|
116
|
+
interface PathOptionsNoExistenceCheck extends PathOptionsBase {
|
|
117
|
+
/**
|
|
118
|
+
* Whether the path must exist on the filesystem.
|
|
119
|
+
* @default false
|
|
120
|
+
*/
|
|
121
|
+
readonly mustExist?: false;
|
|
122
|
+
/**
|
|
123
|
+
* Whether the path must not exist on the filesystem.
|
|
124
|
+
* @default false
|
|
125
|
+
*/
|
|
126
|
+
readonly mustNotExist?: false;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Configuration options for the {@link path} value parser.
|
|
130
|
+
*
|
|
131
|
+
* Note that {@link PathOptionsMustExist.mustExist} and
|
|
132
|
+
* {@link PathOptionsMustNotExist.mustNotExist} are mutually exclusive;
|
|
133
|
+
* you cannot set both to `true` at the same time.
|
|
134
|
+
*/
|
|
135
|
+
type PathOptions = PathOptionsMustExist | PathOptionsMustNotExist | PathOptionsNoExistenceCheck;
|
|
74
136
|
/**
|
|
75
137
|
* Creates a ValueParser for file system paths with validation options.
|
|
76
138
|
*
|
|
@@ -108,4 +170,4 @@ interface PathOptions {
|
|
|
108
170
|
*/
|
|
109
171
|
declare function path(options?: PathOptions): ValueParser<string>;
|
|
110
172
|
//#endregion
|
|
111
|
-
export { PathOptions, path };
|
|
173
|
+
export { PathErrorOptions, PathOptions, PathOptionsBase, PathOptionsMustExist, PathOptionsMustNotExist, PathOptionsNoExistenceCheck, path };
|
package/dist/valueparser.d.ts
CHANGED
|
@@ -4,28 +4,69 @@ import { ValueParser } from "@optique/core/valueparser";
|
|
|
4
4
|
//#region src/valueparser.d.ts
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Custom error messages for path validation failures.
|
|
8
|
+
* @since 0.5.0
|
|
8
9
|
*/
|
|
9
|
-
interface
|
|
10
|
+
interface PathErrorOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Custom error message when file extension is invalid.
|
|
13
|
+
* Can be a static message or a function that receives input, expected
|
|
14
|
+
* extensions, and actual extension.
|
|
15
|
+
* @since 0.5.0
|
|
16
|
+
*/
|
|
17
|
+
invalidExtension?: Message | ((input: string, extensions: readonly string[], actualExtension: string) => Message);
|
|
18
|
+
/**
|
|
19
|
+
* Custom error message when path does not exist.
|
|
20
|
+
* Can be a static message or a function that receives the input path.
|
|
21
|
+
* @since 0.5.0
|
|
22
|
+
*/
|
|
23
|
+
pathNotFound?: Message | ((input: string) => Message);
|
|
24
|
+
/**
|
|
25
|
+
* Custom error message when path already exists (used with
|
|
26
|
+
* {@link PathOptions.mustNotExist}).
|
|
27
|
+
* Can be a static message or a function that receives the input path.
|
|
28
|
+
* @since 0.9.0
|
|
29
|
+
*/
|
|
30
|
+
pathAlreadyExists?: Message | ((input: string) => Message);
|
|
31
|
+
/**
|
|
32
|
+
* Custom error message when path is expected to be a file but isn't.
|
|
33
|
+
* Can be a static message or a function that receives the input path.
|
|
34
|
+
* @since 0.5.0
|
|
35
|
+
*/
|
|
36
|
+
notAFile?: Message | ((input: string) => Message);
|
|
37
|
+
/**
|
|
38
|
+
* Custom error message when path is expected to be a directory but isn't.
|
|
39
|
+
* Can be a static message or a function that receives the input path.
|
|
40
|
+
* @since 0.5.0
|
|
41
|
+
*/
|
|
42
|
+
notADirectory?: Message | ((input: string) => Message);
|
|
43
|
+
/**
|
|
44
|
+
* Custom error message when parent directory does not exist for new files.
|
|
45
|
+
* Can be a static message or a function that receives the parent directory
|
|
46
|
+
* path.
|
|
47
|
+
* @since 0.5.0
|
|
48
|
+
*/
|
|
49
|
+
parentNotFound?: Message | ((parentDir: string) => Message);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Base configuration options shared by all {@link PathOptions} variants.
|
|
53
|
+
*/
|
|
54
|
+
interface PathOptionsBase {
|
|
10
55
|
/**
|
|
11
56
|
* The metavariable name for this parser, e.g., `"FILE"`, `"DIR"`.
|
|
12
57
|
* @default "PATH"
|
|
13
58
|
*/
|
|
14
59
|
readonly metavar?: string;
|
|
15
|
-
/**
|
|
16
|
-
* Whether the path must exist on the filesystem.
|
|
17
|
-
* @default false
|
|
18
|
-
*/
|
|
19
|
-
readonly mustExist?: boolean;
|
|
20
60
|
/**
|
|
21
61
|
* Expected type of path (file, directory, or either).
|
|
22
|
-
* Only checked when {@link mustExist} is true
|
|
62
|
+
* Only checked when {@link PathOptionsMustExist.mustExist} is `true`.
|
|
23
63
|
* @default "either"
|
|
24
64
|
*/
|
|
25
65
|
readonly type?: "file" | "directory" | "either";
|
|
26
66
|
/**
|
|
27
67
|
* Whether to allow creating new files/directories.
|
|
28
|
-
* When true and mustExist is false
|
|
68
|
+
* When `true` and {@link PathOptionsMustExist.mustExist} is `false`,
|
|
69
|
+
* validates that parent directory exists.
|
|
29
70
|
* @default false
|
|
30
71
|
*/
|
|
31
72
|
readonly allowCreate?: boolean;
|
|
@@ -38,39 +79,60 @@ interface PathOptions {
|
|
|
38
79
|
* Custom error messages for path validation failures.
|
|
39
80
|
* @since 0.5.0
|
|
40
81
|
*/
|
|
41
|
-
readonly errors?:
|
|
42
|
-
/**
|
|
43
|
-
* Custom error message when file extension is invalid.
|
|
44
|
-
* Can be a static message or a function that receives input, expected extensions, and actual extension.
|
|
45
|
-
* @since 0.5.0
|
|
46
|
-
*/
|
|
47
|
-
invalidExtension?: Message | ((input: string, extensions: readonly string[], actualExtension: string) => Message);
|
|
48
|
-
/**
|
|
49
|
-
* Custom error message when path does not exist.
|
|
50
|
-
* Can be a static message or a function that receives the input path.
|
|
51
|
-
* @since 0.5.0
|
|
52
|
-
*/
|
|
53
|
-
pathNotFound?: Message | ((input: string) => Message);
|
|
54
|
-
/**
|
|
55
|
-
* Custom error message when path is expected to be a file but isn't.
|
|
56
|
-
* Can be a static message or a function that receives the input path.
|
|
57
|
-
* @since 0.5.0
|
|
58
|
-
*/
|
|
59
|
-
notAFile?: Message | ((input: string) => Message);
|
|
60
|
-
/**
|
|
61
|
-
* Custom error message when path is expected to be a directory but isn't.
|
|
62
|
-
* Can be a static message or a function that receives the input path.
|
|
63
|
-
* @since 0.5.0
|
|
64
|
-
*/
|
|
65
|
-
notADirectory?: Message | ((input: string) => Message);
|
|
66
|
-
/**
|
|
67
|
-
* Custom error message when parent directory does not exist for new files.
|
|
68
|
-
* Can be a static message or a function that receives the parent directory path.
|
|
69
|
-
* @since 0.5.0
|
|
70
|
-
*/
|
|
71
|
-
parentNotFound?: Message | ((parentDir: string) => Message);
|
|
72
|
-
};
|
|
82
|
+
readonly errors?: PathErrorOptions;
|
|
73
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Configuration options for when the path must exist.
|
|
86
|
+
*/
|
|
87
|
+
interface PathOptionsMustExist extends PathOptionsBase {
|
|
88
|
+
/**
|
|
89
|
+
* When `true`, the path must exist on the filesystem.
|
|
90
|
+
*/
|
|
91
|
+
readonly mustExist: true;
|
|
92
|
+
/**
|
|
93
|
+
* Cannot be used together with {@link mustExist}.
|
|
94
|
+
*/
|
|
95
|
+
readonly mustNotExist?: never;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Configuration options for when the path must not exist.
|
|
99
|
+
* @since 0.9.0
|
|
100
|
+
*/
|
|
101
|
+
interface PathOptionsMustNotExist extends PathOptionsBase {
|
|
102
|
+
/**
|
|
103
|
+
* Cannot be used together with {@link mustNotExist}.
|
|
104
|
+
*/
|
|
105
|
+
readonly mustExist?: never;
|
|
106
|
+
/**
|
|
107
|
+
* When `true`, the path must not exist on the filesystem.
|
|
108
|
+
* Useful for output files to prevent accidental overwrites.
|
|
109
|
+
* @since 0.9.0
|
|
110
|
+
*/
|
|
111
|
+
readonly mustNotExist: true;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Configuration options when no existence check is required.
|
|
115
|
+
*/
|
|
116
|
+
interface PathOptionsNoExistenceCheck extends PathOptionsBase {
|
|
117
|
+
/**
|
|
118
|
+
* Whether the path must exist on the filesystem.
|
|
119
|
+
* @default false
|
|
120
|
+
*/
|
|
121
|
+
readonly mustExist?: false;
|
|
122
|
+
/**
|
|
123
|
+
* Whether the path must not exist on the filesystem.
|
|
124
|
+
* @default false
|
|
125
|
+
*/
|
|
126
|
+
readonly mustNotExist?: false;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Configuration options for the {@link path} value parser.
|
|
130
|
+
*
|
|
131
|
+
* Note that {@link PathOptionsMustExist.mustExist} and
|
|
132
|
+
* {@link PathOptionsMustNotExist.mustNotExist} are mutually exclusive;
|
|
133
|
+
* you cannot set both to `true` at the same time.
|
|
134
|
+
*/
|
|
135
|
+
type PathOptions = PathOptionsMustExist | PathOptionsMustNotExist | PathOptionsNoExistenceCheck;
|
|
74
136
|
/**
|
|
75
137
|
* Creates a ValueParser for file system paths with validation options.
|
|
76
138
|
*
|
|
@@ -108,4 +170,4 @@ interface PathOptions {
|
|
|
108
170
|
*/
|
|
109
171
|
declare function path(options?: PathOptions): ValueParser<string>;
|
|
110
172
|
//#endregion
|
|
111
|
-
export { PathOptions, path };
|
|
173
|
+
export { PathErrorOptions, PathOptions, PathOptionsBase, PathOptionsMustExist, PathOptionsMustNotExist, PathOptionsNoExistenceCheck, path };
|
package/dist/valueparser.js
CHANGED
|
@@ -39,7 +39,9 @@ import { existsSync, statSync } from "node:fs";
|
|
|
39
39
|
* ```
|
|
40
40
|
*/
|
|
41
41
|
function path(options = {}) {
|
|
42
|
-
const { metavar = "PATH",
|
|
42
|
+
const { metavar = "PATH", type = "either", allowCreate = false, extensions } = options;
|
|
43
|
+
const mustExist = "mustExist" in options ? options.mustExist : false;
|
|
44
|
+
const mustNotExist = "mustNotExist" in options ? options.mustNotExist : false;
|
|
43
45
|
return {
|
|
44
46
|
metavar,
|
|
45
47
|
parse(input) {
|
|
@@ -53,6 +55,23 @@ function path(options = {}) {
|
|
|
53
55
|
};
|
|
54
56
|
}
|
|
55
57
|
}
|
|
58
|
+
if (mustNotExist) {
|
|
59
|
+
if (existsSync(input)) return {
|
|
60
|
+
success: false,
|
|
61
|
+
error: options.errors?.pathAlreadyExists ? typeof options.errors.pathAlreadyExists === "function" ? options.errors.pathAlreadyExists(input) : options.errors.pathAlreadyExists : message`Path ${text(input)} already exists.`
|
|
62
|
+
};
|
|
63
|
+
if (allowCreate) {
|
|
64
|
+
const parentDir = dirname(input);
|
|
65
|
+
if (!existsSync(parentDir)) return {
|
|
66
|
+
success: false,
|
|
67
|
+
error: options.errors?.parentNotFound ? typeof options.errors.parentNotFound === "function" ? options.errors.parentNotFound(parentDir) : options.errors.parentNotFound : message`Parent directory ${text(parentDir)} does not exist.`
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
success: true,
|
|
72
|
+
value: input
|
|
73
|
+
};
|
|
74
|
+
}
|
|
56
75
|
if (mustExist) {
|
|
57
76
|
if (!existsSync(input)) return {
|
|
58
77
|
success: false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@optique/run",
|
|
3
|
-
"version": "0.9.0-dev.
|
|
3
|
+
"version": "0.9.0-dev.178+732cc3ad",
|
|
4
4
|
"description": "Type-safe combinatorial command-line interface parser",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CLI",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
},
|
|
71
71
|
"sideEffects": false,
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@optique/core": "0.9.0-dev.
|
|
73
|
+
"@optique/core": "0.9.0-dev.178+732cc3ad"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@types/node": "^20.19.9",
|