@duplojs/server 0.1.0-beta.3 → 0.1.0-beta.4
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/command/argument.d.ts +2 -2
- package/dist/command/create.cjs +7 -1
- package/dist/command/create.d.ts +3 -3
- package/dist/command/create.mjs +7 -1
- package/dist/command/error.cjs +24 -0
- package/dist/command/error.d.ts +9 -1
- package/dist/command/error.mjs +24 -0
- package/dist/command/exec.d.ts +4 -3
- package/dist/command/help.d.ts +1 -1
- package/dist/command/index.cjs +4 -0
- package/dist/command/index.mjs +4 -2
- package/dist/command/options/base.cjs +21 -13
- package/dist/command/options/base.d.ts +6 -0
- package/dist/command/options/base.mjs +20 -14
- package/dist/command/options/defaults/array.d.ts +6 -4
- package/dist/command/options/defaults/boolean.cjs +21 -7
- package/dist/command/options/defaults/boolean.d.ts +6 -3
- package/dist/command/options/defaults/boolean.mjs +20 -8
- package/dist/command/options/defaults/simple.d.ts +6 -4
- package/dist/command/types/forbiddenInvalidIdentifier.d.ts +6 -0
- package/dist/command/types/index.d.ts +1 -0
- package/dist/common/environmentVariable/index.d.ts +1 -1
- package/dist/common/environmentVariable/overrideEnvironmentVariables.d.ts +1 -1
- package/dist/common/environmentVariable/parseEnvironmentFiles.d.ts +1 -1
- package/dist/dataStructure/helper/file.d.ts +1 -1
- package/dist/dataStructure/helper/folder.d.ts +1 -1
- package/dist/file/appendFile.cjs +10 -0
- package/dist/file/appendFile.d.ts +13 -13
- package/dist/file/appendFile.mjs +1 -1
- package/dist/file/appendTextFile.cjs +10 -0
- package/dist/file/appendTextFile.d.ts +13 -13
- package/dist/file/appendTextFile.mjs +1 -1
- package/dist/file/copy.cjs +10 -0
- package/dist/file/copy.d.ts +13 -13
- package/dist/file/copy.mjs +1 -1
- package/dist/file/createEntryInterface.cjs +4 -1
- package/dist/file/createEntryInterface.d.ts +1 -1
- package/dist/file/createEntryInterface.mjs +3 -1
- package/dist/file/ensureDirectory.cjs +8 -0
- package/dist/file/ensureDirectory.d.ts +10 -10
- package/dist/file/ensureDirectory.mjs +1 -1
- package/dist/file/ensureFile.cjs +9 -0
- package/dist/file/ensureFile.d.ts +11 -11
- package/dist/file/ensureFile.mjs +1 -1
- package/dist/file/exists.cjs +5 -0
- package/dist/file/exists.d.ts +7 -7
- package/dist/file/exists.mjs +1 -1
- package/dist/file/fileInterface.cjs +1 -1
- package/dist/file/fileInterface.d.ts +5 -6
- package/dist/file/fileInterface.mjs +1 -1
- package/dist/file/folderInterface.cjs +1 -1
- package/dist/file/folderInterface.d.ts +5 -6
- package/dist/file/folderInterface.mjs +1 -1
- package/dist/file/index.cjs +506 -0
- package/dist/file/index.mjs +285 -32
- package/dist/file/link.cjs +11 -0
- package/dist/file/link.d.ts +14 -14
- package/dist/file/link.mjs +1 -1
- package/dist/file/linkStat.cjs +6 -0
- package/dist/file/linkStat.d.ts +8 -8
- package/dist/file/linkStat.mjs +1 -1
- package/dist/file/makeDirectory.cjs +10 -0
- package/dist/file/makeDirectory.d.ts +12 -12
- package/dist/file/makeDirectory.mjs +1 -1
- package/dist/file/makeTemporaryDirectory.cjs +7 -0
- package/dist/file/makeTemporaryDirectory.d.ts +7 -7
- package/dist/file/makeTemporaryDirectory.mjs +1 -1
- package/dist/file/makeTemporaryFile.cjs +8 -0
- package/dist/file/makeTemporaryFile.d.ts +8 -8
- package/dist/file/makeTemporaryFile.mjs +1 -1
- package/dist/file/move.cjs +11 -0
- package/dist/file/move.d.ts +14 -14
- package/dist/file/move.mjs +1 -1
- package/dist/file/readDirectory.cjs +6 -0
- package/dist/file/readDirectory.d.ts +8 -8
- package/dist/file/readDirectory.mjs +1 -1
- package/dist/file/readFile.cjs +7 -0
- package/dist/file/readFile.d.ts +9 -9
- package/dist/file/readFile.mjs +1 -1
- package/dist/file/readJsonFile.cjs +7 -0
- package/dist/file/readJsonFile.d.ts +9 -9
- package/dist/file/readJsonFile.mjs +1 -1
- package/dist/file/readLink.cjs +6 -0
- package/dist/file/readLink.d.ts +8 -8
- package/dist/file/readLink.mjs +1 -1
- package/dist/file/readTextFile.cjs +7 -0
- package/dist/file/readTextFile.d.ts +9 -9
- package/dist/file/readTextFile.mjs +1 -1
- package/dist/file/realPath.cjs +5 -0
- package/dist/file/realPath.d.ts +7 -7
- package/dist/file/realPath.mjs +1 -1
- package/dist/file/relocate.cjs +11 -0
- package/dist/file/relocate.d.ts +14 -14
- package/dist/file/relocate.mjs +1 -1
- package/dist/file/remove.cjs +9 -0
- package/dist/file/remove.d.ts +11 -11
- package/dist/file/remove.mjs +1 -1
- package/dist/file/rename.cjs +11 -0
- package/dist/file/rename.d.ts +14 -14
- package/dist/file/rename.mjs +1 -1
- package/dist/file/setMode.cjs +6 -0
- package/dist/file/setMode.d.ts +9 -9
- package/dist/file/setMode.mjs +1 -1
- package/dist/file/setOwner.cjs +6 -0
- package/dist/file/setOwner.d.ts +9 -9
- package/dist/file/setOwner.mjs +1 -1
- package/dist/file/setTime.cjs +6 -0
- package/dist/file/setTime.d.ts +9 -9
- package/dist/file/setTime.mjs +1 -1
- package/dist/file/stat.cjs +6 -0
- package/dist/file/stat.d.ts +8 -8
- package/dist/file/stat.mjs +1 -1
- package/dist/file/symlink.cjs +9 -0
- package/dist/file/symlink.d.ts +12 -12
- package/dist/file/symlink.mjs +1 -1
- package/dist/file/truncate.cjs +10 -0
- package/dist/file/truncate.d.ts +12 -12
- package/dist/file/truncate.mjs +1 -1
- package/dist/file/unknownEntryInterface.cjs +3 -1
- package/dist/file/unknownEntryInterface.d.ts +4 -4
- package/dist/file/unknownEntryInterface.mjs +2 -1
- package/dist/file/walkDirectory.cjs +11 -1
- package/dist/file/walkDirectory.d.ts +9 -9
- package/dist/file/walkDirectory.mjs +6 -2
- package/dist/file/writeFile.cjs +10 -0
- package/dist/file/writeFile.d.ts +13 -13
- package/dist/file/writeFile.mjs +1 -1
- package/dist/file/writeJsonFile.cjs +10 -0
- package/dist/file/writeJsonFile.d.ts +13 -13
- package/dist/file/writeJsonFile.mjs +1 -1
- package/dist/file/writeTextFile.cjs +10 -0
- package/dist/file/writeTextFile.d.ts +13 -13
- package/dist/file/writeTextFile.mjs +1 -1
- package/dist/override.d.ts +8 -0
- package/package.json +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Error, SymbolCommandError } from './error';
|
|
2
|
-
import { EligibleType } from './types';
|
|
2
|
+
import { EligibleType, ForbiddenInvalidIdentifier } from './types';
|
|
3
3
|
import type * as DCommon from "@duplojs/lang/common";
|
|
4
4
|
import type * as DKind from "@duplojs/lang/kind";
|
|
5
5
|
import type * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
@@ -15,4 +15,4 @@ export interface CreateArgumentParams {
|
|
|
15
15
|
readonly description?: string;
|
|
16
16
|
readonly optional?: boolean;
|
|
17
17
|
}
|
|
18
|
-
export declare function createArgument<GenericName extends string, GenericStructure extends DDataStructure.Structure<EligibleType>, GenericValue extends DDataStructure.StructureValue<GenericStructure>, const GenericParams extends CreateArgumentParams = {}>(name: GenericName
|
|
18
|
+
export declare function createArgument<GenericName extends string, GenericStructure extends DDataStructure.Structure<EligibleType>, GenericValue extends DDataStructure.StructureValue<GenericStructure>, const GenericParams extends CreateArgumentParams = {}>(name: GenericName & ForbiddenInvalidIdentifier<GenericName>, dataStructure: GenericStructure, params?: GenericParams): Argument<GenericName, (GenericValue | (DCommon.IsEqual<GenericParams["optional"], true> extends true ? undefined : never))>;
|
package/dist/command/create.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
2
|
const require_kind = require("./kind.cjs");
|
|
3
3
|
const require_error = require("./error.cjs");
|
|
4
|
+
const require_base = require("./options/base.cjs");
|
|
4
5
|
const require_help = require("./help.cjs");
|
|
5
6
|
let _duplojs_lang_common = require("@duplojs/lang/common");
|
|
6
7
|
_duplojs_lang_common = require_runtime.__toESM(_duplojs_lang_common, 1);
|
|
@@ -63,6 +64,8 @@ function create(...args) {
|
|
|
63
64
|
});
|
|
64
65
|
});
|
|
65
66
|
if (commandOptions.hasError === true) return require_error.SymbolCommandError;
|
|
67
|
+
const unknownOptions = _duplojs_lang_array.filter(commandOptions.restArgs, require_base.isOptionToken);
|
|
68
|
+
if (unknownOptions.length > 0) return error.addUnknownOptionIssue(unknownOptions);
|
|
66
69
|
if (self.subject?.type === "argument") {
|
|
67
70
|
if (self.subject.args.length < commandOptions.restArgs.length) return error.addTooMuchCommandArgumentIssue(self.subject.args.length, commandOptions.restArgs.length);
|
|
68
71
|
const commandArgs = await _duplojs_lang_generator.asyncReduce(self.subject.args, _duplojs_lang_generator.reduceFrom({
|
|
@@ -83,7 +86,10 @@ function create(...args) {
|
|
|
83
86
|
args: commandArgs.args
|
|
84
87
|
});
|
|
85
88
|
} else {
|
|
86
|
-
if (commandOptions.restArgs.length > 0)
|
|
89
|
+
if (commandOptions.restArgs.length > 0) {
|
|
90
|
+
if (self.subject?.type === "subCommand") return error.addUnknownSubCommandIssue(commandOptions.restArgs[0]);
|
|
91
|
+
return error.addTooMuchCommandArgumentIssue(0, commandOptions.restArgs.length);
|
|
92
|
+
}
|
|
87
93
|
await execute({ options: commandOptions.options });
|
|
88
94
|
}
|
|
89
95
|
},
|
package/dist/command/create.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Option } from './options';
|
|
2
2
|
import { SymbolCommandError, Error } from './error';
|
|
3
3
|
import { Argument } from './argument';
|
|
4
|
-
import { ForbiddenDuplicateName } from './types';
|
|
4
|
+
import { ForbiddenDuplicateName, ForbiddenInvalidIdentifier } from './types';
|
|
5
5
|
import * as DCommon from "@duplojs/lang/common";
|
|
6
6
|
import type * as DKind from "@duplojs/lang/kind";
|
|
7
7
|
declare const commandKind: DKind.Handler<DKind.Definition<"@DuplojsServerCommand/command", unknown>>;
|
|
@@ -42,6 +42,6 @@ export type CreateCommandExecuteParams<GenericOptions extends DCommon.AnyTuple<O
|
|
|
42
42
|
readonly [GenericArgument in GenericArguments[number] as GenericArgument["name"]]: Exclude<Awaited<ReturnType<GenericArgument["execute"]>>, SymbolCommandError>;
|
|
43
43
|
};
|
|
44
44
|
}));
|
|
45
|
-
export declare function create<GenericName extends string>(name: GenericName
|
|
46
|
-
export declare function create<GenericName extends string, const GenericOptions extends DCommon.AnyTuple<Option> = never, GenericSubjects extends Subjects = never>(name: GenericName
|
|
45
|
+
export declare function create<GenericName extends string>(name: GenericName & ForbiddenInvalidIdentifier<GenericName>, execute: () => void): Command<GenericName>;
|
|
46
|
+
export declare function create<GenericName extends string, const GenericOptions extends DCommon.AnyTuple<Option> = never, GenericSubjects extends Subjects = never>(name: GenericName & ForbiddenInvalidIdentifier<GenericName>, params: CreateCommandParams<GenericOptions, GenericSubjects>, execute: (params: CreateCommandExecuteParams<GenericOptions, Extract<GenericSubjects, DCommon.AnyTuple<Argument>>>) => DCommon.MaybePromise<void>): Command<GenericName>;
|
|
47
47
|
export {};
|
package/dist/command/create.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createKind } from "./kind.mjs";
|
|
2
2
|
import { SymbolCommandError } from "./error.mjs";
|
|
3
|
+
import { isOptionToken } from "./options/base.mjs";
|
|
3
4
|
import { helpOption, logCommandHelp } from "./help.mjs";
|
|
4
5
|
import * as DCommon from "@duplojs/lang/common";
|
|
5
6
|
import * as DObject from "@duplojs/lang/object";
|
|
@@ -58,6 +59,8 @@ function create(...args) {
|
|
|
58
59
|
});
|
|
59
60
|
});
|
|
60
61
|
if (commandOptions.hasError === true) return SymbolCommandError;
|
|
62
|
+
const unknownOptions = DArray.filter(commandOptions.restArgs, isOptionToken);
|
|
63
|
+
if (unknownOptions.length > 0) return error.addUnknownOptionIssue(unknownOptions);
|
|
61
64
|
if (self.subject?.type === "argument") {
|
|
62
65
|
if (self.subject.args.length < commandOptions.restArgs.length) return error.addTooMuchCommandArgumentIssue(self.subject.args.length, commandOptions.restArgs.length);
|
|
63
66
|
const commandArgs = await DGenerator.asyncReduce(self.subject.args, DGenerator.reduceFrom({
|
|
@@ -78,7 +81,10 @@ function create(...args) {
|
|
|
78
81
|
args: commandArgs.args
|
|
79
82
|
});
|
|
80
83
|
} else {
|
|
81
|
-
if (commandOptions.restArgs.length > 0)
|
|
84
|
+
if (commandOptions.restArgs.length > 0) {
|
|
85
|
+
if (self.subject?.type === "subCommand") return error.addUnknownSubCommandIssue(commandOptions.restArgs[0]);
|
|
86
|
+
return error.addTooMuchCommandArgumentIssue(0, commandOptions.restArgs.length);
|
|
87
|
+
}
|
|
82
88
|
await execute({ options: commandOptions.options });
|
|
83
89
|
}
|
|
84
90
|
},
|
package/dist/command/error.cjs
CHANGED
|
@@ -23,6 +23,20 @@ function createError(commandName) {
|
|
|
23
23
|
issues,
|
|
24
24
|
currentPath,
|
|
25
25
|
pushPath: (path) => void currentPath.push(path),
|
|
26
|
+
addUnknownOptionIssue: (optionTokens) => {
|
|
27
|
+
issues.push(_duplojs_lang_modeling.taggedObject("UnknownOptionIssue", {
|
|
28
|
+
optionTokens,
|
|
29
|
+
path: _duplojs_lang_string.join(currentPath, ".")
|
|
30
|
+
}));
|
|
31
|
+
return SymbolCommandError;
|
|
32
|
+
},
|
|
33
|
+
addUnknownSubCommandIssue: (subCommandName) => {
|
|
34
|
+
issues.push(_duplojs_lang_modeling.taggedObject("UnknownSubCommandIssue", {
|
|
35
|
+
subCommandName,
|
|
36
|
+
path: _duplojs_lang_string.join(currentPath, ".")
|
|
37
|
+
}));
|
|
38
|
+
return SymbolCommandError;
|
|
39
|
+
},
|
|
26
40
|
addRequiredOptionIssue: (optionName) => {
|
|
27
41
|
issues.push(_duplojs_lang_modeling.taggedObject("RequiredOptionIssue", {
|
|
28
42
|
optionName,
|
|
@@ -94,6 +108,16 @@ function interpretDataStructureError(error, dataStructureErrorInterpreter) {
|
|
|
94
108
|
}
|
|
95
109
|
function interpretErrorIssues(issues, dataStructureErrorInterpreter) {
|
|
96
110
|
return _duplojs_lang_printer.renderParagraph([_duplojs_lang_array.map(issues, _duplojs_lang_pattern.matchWithTaggedObject({
|
|
111
|
+
UnknownOptionIssue: ({ optionTokens }) => [_duplojs_lang_printer.render([
|
|
112
|
+
_duplojs_lang_printer.indent(1),
|
|
113
|
+
_duplojs_lang_printer.colorizedBold("OPTION: ", "blue"),
|
|
114
|
+
_duplojs_lang_string.join(optionTokens, ", ")
|
|
115
|
+
], ""), `${_duplojs_lang_printer.indent(1)}↳ Unknown Option`],
|
|
116
|
+
UnknownSubCommandIssue: ({ subCommandName }) => [_duplojs_lang_printer.render([
|
|
117
|
+
_duplojs_lang_printer.indent(1),
|
|
118
|
+
_duplojs_lang_printer.colorizedBold("SUB-COMMAND: ", "cyan"),
|
|
119
|
+
subCommandName
|
|
120
|
+
], ""), `${_duplojs_lang_printer.indent(1)}↳ Unknown Sub-command`],
|
|
97
121
|
DataStructureArgumentIssue: ({ argumentName, dataStructureError }) => [_duplojs_lang_printer.render([
|
|
98
122
|
_duplojs_lang_printer.indent(1),
|
|
99
123
|
_duplojs_lang_printer.colorizedBold("ARGUMENT: ", "magenta"),
|
package/dist/command/error.d.ts
CHANGED
|
@@ -27,17 +27,25 @@ export interface DataStructureArgumentIssue extends ArgumentIssueBase, DModeling
|
|
|
27
27
|
export interface CommandArgumentIssueBase {
|
|
28
28
|
readonly path: string;
|
|
29
29
|
}
|
|
30
|
+
export interface UnknownOptionIssue extends CommandArgumentIssueBase, DModeling.ObjectTag<"UnknownOptionIssue"> {
|
|
31
|
+
readonly optionTokens: readonly string[];
|
|
32
|
+
}
|
|
33
|
+
export interface UnknownSubCommandIssue extends CommandArgumentIssueBase, DModeling.ObjectTag<"UnknownSubCommandIssue"> {
|
|
34
|
+
readonly subCommandName: string;
|
|
35
|
+
}
|
|
30
36
|
export interface TooMuchCommandArgumentIssue extends CommandArgumentIssueBase, DModeling.ObjectTag<"TooMuchCommandArgumentIssue"> {
|
|
31
37
|
readonly expect: number;
|
|
32
38
|
readonly receive: number;
|
|
33
39
|
}
|
|
34
|
-
export type Issues = (RequiredOptionIssue | RequiredOptionValueIssue | UnexpectedOptionValueIssue | DataStructureOptionIssue | RequiredArgumentIssue | DataStructureArgumentIssue | TooMuchCommandArgumentIssue);
|
|
40
|
+
export type Issues = (RequiredOptionIssue | RequiredOptionValueIssue | UnexpectedOptionValueIssue | DataStructureOptionIssue | RequiredArgumentIssue | DataStructureArgumentIssue | TooMuchCommandArgumentIssue | UnknownOptionIssue | UnknownSubCommandIssue);
|
|
35
41
|
export declare const SymbolCommandError: unique symbol;
|
|
36
42
|
export type SymbolCommandError = typeof SymbolCommandError;
|
|
37
43
|
export interface Error {
|
|
38
44
|
readonly issues: readonly Issues[];
|
|
39
45
|
readonly currentPath: readonly string[];
|
|
40
46
|
pushPath(path: string): void;
|
|
47
|
+
addUnknownOptionIssue(optionTokens: readonly string[]): SymbolCommandError;
|
|
48
|
+
addUnknownSubCommandIssue(subCommandName: string): SymbolCommandError;
|
|
41
49
|
addRequiredOptionIssue(optionName: string): SymbolCommandError;
|
|
42
50
|
addRequiredOptionValueIssue(optionName: string): SymbolCommandError;
|
|
43
51
|
addUnexpectedOptionValueIssue(optionName: string, data: unknown): SymbolCommandError;
|
package/dist/command/error.mjs
CHANGED
|
@@ -15,6 +15,20 @@ function createError(commandName) {
|
|
|
15
15
|
issues,
|
|
16
16
|
currentPath,
|
|
17
17
|
pushPath: (path) => void currentPath.push(path),
|
|
18
|
+
addUnknownOptionIssue: (optionTokens) => {
|
|
19
|
+
issues.push(DModeling.taggedObject("UnknownOptionIssue", {
|
|
20
|
+
optionTokens,
|
|
21
|
+
path: DString.join(currentPath, ".")
|
|
22
|
+
}));
|
|
23
|
+
return SymbolCommandError;
|
|
24
|
+
},
|
|
25
|
+
addUnknownSubCommandIssue: (subCommandName) => {
|
|
26
|
+
issues.push(DModeling.taggedObject("UnknownSubCommandIssue", {
|
|
27
|
+
subCommandName,
|
|
28
|
+
path: DString.join(currentPath, ".")
|
|
29
|
+
}));
|
|
30
|
+
return SymbolCommandError;
|
|
31
|
+
},
|
|
18
32
|
addRequiredOptionIssue: (optionName) => {
|
|
19
33
|
issues.push(DModeling.taggedObject("RequiredOptionIssue", {
|
|
20
34
|
optionName,
|
|
@@ -86,6 +100,16 @@ function interpretDataStructureError(error, dataStructureErrorInterpreter) {
|
|
|
86
100
|
}
|
|
87
101
|
function interpretErrorIssues(issues, dataStructureErrorInterpreter) {
|
|
88
102
|
return DPrinter.renderParagraph([DArray.map(issues, DPattern.matchWithTaggedObject({
|
|
103
|
+
UnknownOptionIssue: ({ optionTokens }) => [DPrinter.render([
|
|
104
|
+
DPrinter.indent(1),
|
|
105
|
+
DPrinter.colorizedBold("OPTION: ", "blue"),
|
|
106
|
+
DString.join(optionTokens, ", ")
|
|
107
|
+
], ""), `${DPrinter.indent(1)}↳ Unknown Option`],
|
|
108
|
+
UnknownSubCommandIssue: ({ subCommandName }) => [DPrinter.render([
|
|
109
|
+
DPrinter.indent(1),
|
|
110
|
+
DPrinter.colorizedBold("SUB-COMMAND: ", "cyan"),
|
|
111
|
+
subCommandName
|
|
112
|
+
], ""), `${DPrinter.indent(1)}↳ Unknown Sub-command`],
|
|
89
113
|
DataStructureArgumentIssue: ({ argumentName, dataStructureError }) => [DPrinter.render([
|
|
90
114
|
DPrinter.indent(1),
|
|
91
115
|
DPrinter.colorizedBold("ARGUMENT: ", "magenta"),
|
package/dist/command/exec.d.ts
CHANGED
|
@@ -2,12 +2,13 @@ import { CreateCommandExecuteParams, CreateCommandParams, Subjects } from './cre
|
|
|
2
2
|
import { Error } from './error';
|
|
3
3
|
import { Option } from './options';
|
|
4
4
|
import { Argument } from './argument';
|
|
5
|
+
import { ForbiddenInvalidIdentifier } from './types';
|
|
5
6
|
import type * as DCommon from "@duplojs/lang/common";
|
|
6
7
|
import * as DEither from "@duplojs/lang/either";
|
|
7
8
|
import type * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
8
|
-
export interface ExecCommandParams<GenericOptions extends DCommon.AnyTuple<Option> = DCommon.AnyTuple<Option>, GenericSubjects extends Subjects = Subjects> extends CreateCommandParams<GenericOptions, GenericSubjects> {
|
|
9
|
-
displayName?:
|
|
9
|
+
export interface ExecCommandParams<GenericOptions extends DCommon.AnyTuple<Option> = DCommon.AnyTuple<Option>, GenericSubjects extends Subjects = Subjects, GenericDisplayName extends string = string> extends CreateCommandParams<GenericOptions, GenericSubjects> {
|
|
10
|
+
displayName?: GenericDisplayName & ForbiddenInvalidIdentifier<GenericDisplayName>;
|
|
10
11
|
dataStructureErrorInterpreter?: DDataStructure.ErrorInterpreter;
|
|
11
12
|
}
|
|
12
13
|
export declare function exec(execute: () => void): Promise<DEither.Ok | DEither.Error<Error>>;
|
|
13
|
-
export declare function exec<const GenericOptions extends DCommon.AnyTuple<Option> = never, GenericSubjects extends Subjects = never>(params: ExecCommandParams<GenericOptions, GenericSubjects>, execute: (params: CreateCommandExecuteParams<GenericOptions, Extract<GenericSubjects, DCommon.AnyTuple<Argument>>>) => DCommon.MaybePromise<void>): Promise<DEither.Ok | DEither.Error<Error>>;
|
|
14
|
+
export declare function exec<const GenericOptions extends DCommon.AnyTuple<Option> = never, GenericSubjects extends Subjects = never, const GenericDisplayName extends string = string>(params: ExecCommandParams<GenericOptions, GenericSubjects, GenericDisplayName>, execute: (params: CreateCommandExecuteParams<GenericOptions, Extract<GenericSubjects, DCommon.AnyTuple<Argument>>>) => DCommon.MaybePromise<void>): Promise<DEither.Ok | DEither.Error<Error>>;
|
package/dist/command/help.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Command } from './create';
|
|
2
2
|
import { Argument } from './argument';
|
|
3
3
|
import { Options } from './options';
|
|
4
|
-
export declare const helpOption:
|
|
4
|
+
export declare const helpOption: import('./options').BooleanOption<"help">;
|
|
5
5
|
export declare function renderOptionsHelp(options: readonly Options[], depth: number): string;
|
|
6
6
|
export declare function renderArgumentsHelp(args: readonly Argument[], depth: number): string;
|
|
7
7
|
export declare function renderCommandHelp(command: Command, depth: number): string[];
|
package/dist/command/index.cjs
CHANGED
|
@@ -25,12 +25,14 @@ var command_exports = /* @__PURE__ */ require_runtime.__exportAll({
|
|
|
25
25
|
createOption: () => require_simple.createOption,
|
|
26
26
|
exec: () => require_exec.exec,
|
|
27
27
|
execOptions: () => require_execOptions.execOptions,
|
|
28
|
+
findOptionToken: () => require_base.findOptionToken,
|
|
28
29
|
helpOption: () => require_help.helpOption,
|
|
29
30
|
interpretDataStructureError: () => require_error.interpretDataStructureError,
|
|
30
31
|
interpretErrorIssues: () => require_error.interpretErrorIssues,
|
|
31
32
|
interpretExecCommandError: () => require_error.interpretExecCommandError,
|
|
32
33
|
interpretExecOptionsError: () => require_error.interpretExecOptionsError,
|
|
33
34
|
isCommands: () => require_create.isCommands,
|
|
35
|
+
isOptionToken: () => require_base.isOptionToken,
|
|
34
36
|
logCommandHelp: () => require_help.logCommandHelp,
|
|
35
37
|
logExecOptionHelp: () => require_help.logExecOptionHelp,
|
|
36
38
|
optionIdentifier: () => require_identifier.optionIdentifier,
|
|
@@ -61,12 +63,14 @@ exports.createError = require_error.createError;
|
|
|
61
63
|
exports.createOption = require_simple.createOption;
|
|
62
64
|
exports.exec = require_exec.exec;
|
|
63
65
|
exports.execOptions = require_execOptions.execOptions;
|
|
66
|
+
exports.findOptionToken = require_base.findOptionToken;
|
|
64
67
|
exports.helpOption = require_help.helpOption;
|
|
65
68
|
exports.interpretDataStructureError = require_error.interpretDataStructureError;
|
|
66
69
|
exports.interpretErrorIssues = require_error.interpretErrorIssues;
|
|
67
70
|
exports.interpretExecCommandError = require_error.interpretExecCommandError;
|
|
68
71
|
exports.interpretExecOptionsError = require_error.interpretExecOptionsError;
|
|
69
72
|
exports.isCommands = require_create.isCommands;
|
|
73
|
+
exports.isOptionToken = require_base.isOptionToken;
|
|
70
74
|
exports.logCommandHelp = require_help.logCommandHelp;
|
|
71
75
|
exports.logExecOptionHelp = require_help.logExecOptionHelp;
|
|
72
76
|
exports.optionIdentifier = require_identifier.optionIdentifier;
|
package/dist/command/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __exportAll } from "../_virtual/_rolldown/runtime.mjs";
|
|
2
2
|
import { argumentKind, createArgument } from "./argument.mjs";
|
|
3
3
|
import { SymbolCommandError, createError, interpretDataStructureError, interpretErrorIssues, interpretExecCommandError, interpretExecOptionsError } from "./error.mjs";
|
|
4
|
-
import { constructOption, optionKind } from "./options/base.mjs";
|
|
4
|
+
import { constructOption, findOptionToken, isOptionToken, optionKind } from "./options/base.mjs";
|
|
5
5
|
import { arrayOptionKind, createArrayOption } from "./options/defaults/array.mjs";
|
|
6
6
|
import { booleanOptionKind, createBooleanOption } from "./options/defaults/boolean.mjs";
|
|
7
7
|
import { createOption, simpleOptionKind } from "./options/defaults/simple.mjs";
|
|
@@ -25,12 +25,14 @@ var command_exports = /* @__PURE__ */ __exportAll({
|
|
|
25
25
|
createOption: () => createOption,
|
|
26
26
|
exec: () => exec,
|
|
27
27
|
execOptions: () => execOptions,
|
|
28
|
+
findOptionToken: () => findOptionToken,
|
|
28
29
|
helpOption: () => helpOption,
|
|
29
30
|
interpretDataStructureError: () => interpretDataStructureError,
|
|
30
31
|
interpretErrorIssues: () => interpretErrorIssues,
|
|
31
32
|
interpretExecCommandError: () => interpretExecCommandError,
|
|
32
33
|
interpretExecOptionsError: () => interpretExecOptionsError,
|
|
33
34
|
isCommands: () => isCommands,
|
|
35
|
+
isOptionToken: () => isOptionToken,
|
|
34
36
|
logCommandHelp: () => logCommandHelp,
|
|
35
37
|
logExecOptionHelp: () => logExecOptionHelp,
|
|
36
38
|
optionIdentifier: () => optionIdentifier,
|
|
@@ -42,4 +44,4 @@ var command_exports = /* @__PURE__ */ __exportAll({
|
|
|
42
44
|
simpleOptionKind: () => simpleOptionKind
|
|
43
45
|
});
|
|
44
46
|
//#endregion
|
|
45
|
-
export { SymbolCommandError, argumentKind, arrayOptionKind, booleanOptionKind, command_exports, constructOption, create, createArgument, createArrayOption, createBooleanOption, createError, createOption, exec, execOptions, helpOption, interpretDataStructureError, interpretErrorIssues, interpretExecCommandError, interpretExecOptionsError, isCommands, logCommandHelp, logExecOptionHelp, optionIdentifier, optionKind, renderArgumentsHelp, renderCommandHelp, renderExecOptionHelp, renderOptionsHelp, simpleOptionKind };
|
|
47
|
+
export { SymbolCommandError, argumentKind, arrayOptionKind, booleanOptionKind, command_exports, constructOption, create, createArgument, createArrayOption, createBooleanOption, createError, createOption, exec, execOptions, findOptionToken, helpOption, interpretDataStructureError, interpretErrorIssues, interpretExecCommandError, interpretExecOptionsError, isCommands, isOptionToken, logCommandHelp, logExecOptionHelp, optionIdentifier, optionKind, renderArgumentsHelp, renderCommandHelp, renderExecOptionHelp, renderOptionsHelp, simpleOptionKind };
|
|
@@ -9,24 +9,30 @@ let _duplojs_lang_string = require("@duplojs/lang/string");
|
|
|
9
9
|
_duplojs_lang_string = require_runtime.__toESM(_duplojs_lang_string, 1);
|
|
10
10
|
//#region scripts/command/options/base.ts
|
|
11
11
|
const optionKind = require_kind.createKind("command-option");
|
|
12
|
-
const regexOption = /^(?<dashes>-{1,2})(?<key>[A-Za-z0-9][A-Za-z0-9_-]*)(?:=(?<value>.*))?$/;
|
|
12
|
+
const regexOption = /^(?<dashes>-{1,2})(?<key>(?![0-9]+(?:=|$))[A-Za-z0-9][A-Za-z0-9_-]*)(?:=(?<value>.*))?$/;
|
|
13
|
+
function isOptionToken(input) {
|
|
14
|
+
return _duplojs_lang_string.test(input, regexOption);
|
|
15
|
+
}
|
|
16
|
+
function findOptionToken(args, option) {
|
|
17
|
+
return _duplojs_lang_array.reduce(args, _duplojs_lang_array.reduceFrom(null), ({ element, next, exit, index }) => {
|
|
18
|
+
const extractResult = _duplojs_lang_string.extract(element, regexOption);
|
|
19
|
+
if (!extractResult) return next(null);
|
|
20
|
+
const key = extractResult.namedGroups.key;
|
|
21
|
+
if (option.name !== key && (!_duplojs_lang_array.includes(option.aliases, key) || extractResult.namedGroups?.dashes !== "-")) return next(null);
|
|
22
|
+
return exit({
|
|
23
|
+
key,
|
|
24
|
+
value: extractResult.namedGroups?.value,
|
|
25
|
+
index
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
13
29
|
function constructOption(kindHandler, createConstructor) {
|
|
14
30
|
return createConstructor({ init: (name, execute, params, ...rest) => {
|
|
15
31
|
const self = {
|
|
16
32
|
...Object.fromEntries(Object.entries(rest[0] ?? {}).map(([key, prop]) => typeof prop === "function" ? [key, (...args) => prop(self, ...args)] : [key, prop])),
|
|
17
33
|
name,
|
|
18
34
|
execute: async (args, error) => {
|
|
19
|
-
const result =
|
|
20
|
-
const extractResult = _duplojs_lang_string.extract(element, regexOption);
|
|
21
|
-
if (!extractResult) return next(null);
|
|
22
|
-
const result = {
|
|
23
|
-
key: extractResult.namedGroups.key,
|
|
24
|
-
value: extractResult.namedGroups?.value,
|
|
25
|
-
index
|
|
26
|
-
};
|
|
27
|
-
if (self.name !== result.key && (!_duplojs_lang_array.includes(self.aliases, result.key) || extractResult.namedGroups?.dashes !== "-")) return next(null);
|
|
28
|
-
return exit(result);
|
|
29
|
-
});
|
|
35
|
+
const result = findOptionToken(args, self);
|
|
30
36
|
const { value, argumentRest } = _duplojs_lang_common.justExec(() => {
|
|
31
37
|
if (!result) return {
|
|
32
38
|
value: null,
|
|
@@ -34,7 +40,7 @@ function constructOption(kindHandler, createConstructor) {
|
|
|
34
40
|
};
|
|
35
41
|
if (result.value === void 0) {
|
|
36
42
|
const nextArg = args[result.index + 1];
|
|
37
|
-
if (nextArg === void 0 ||
|
|
43
|
+
if (nextArg === void 0 || isOptionToken(nextArg)) return {
|
|
38
44
|
value: void 0,
|
|
39
45
|
argumentRest: _duplojs_lang_array.spliceDelete(args, result.index, 1)
|
|
40
46
|
};
|
|
@@ -65,4 +71,6 @@ function constructOption(kindHandler, createConstructor) {
|
|
|
65
71
|
}
|
|
66
72
|
//#endregion
|
|
67
73
|
exports.constructOption = constructOption;
|
|
74
|
+
exports.findOptionToken = findOptionToken;
|
|
75
|
+
exports.isOptionToken = isOptionToken;
|
|
68
76
|
exports.optionKind = optionKind;
|
|
@@ -2,6 +2,12 @@ import { Error, SymbolCommandError } from '../error';
|
|
|
2
2
|
import * as DCommon from "@duplojs/lang/common";
|
|
3
3
|
import type * as DKind from "@duplojs/lang/kind";
|
|
4
4
|
export declare const optionKind: DKind.Handler<DKind.Definition<"@DuplojsServerCommand/command-option", unknown>>;
|
|
5
|
+
export declare function isOptionToken(input: string): boolean;
|
|
6
|
+
export declare function findOptionToken(args: readonly string[], option: Pick<Option, "name" | "aliases">): {
|
|
7
|
+
key: string;
|
|
8
|
+
value: string | undefined;
|
|
9
|
+
index: number;
|
|
10
|
+
} | null;
|
|
5
11
|
export interface Option<GenericName extends string = string, GenericValue extends unknown = unknown> extends DKind.Kind<typeof optionKind> {
|
|
6
12
|
readonly name: GenericName;
|
|
7
13
|
readonly description: string | null;
|
|
@@ -5,24 +5,30 @@ import * as DArray from "@duplojs/lang/array";
|
|
|
5
5
|
import * as DString from "@duplojs/lang/string";
|
|
6
6
|
//#region scripts/command/options/base.ts
|
|
7
7
|
const optionKind = createKind("command-option");
|
|
8
|
-
const regexOption = /^(?<dashes>-{1,2})(?<key>[A-Za-z0-9][A-Za-z0-9_-]*)(?:=(?<value>.*))?$/;
|
|
8
|
+
const regexOption = /^(?<dashes>-{1,2})(?<key>(?![0-9]+(?:=|$))[A-Za-z0-9][A-Za-z0-9_-]*)(?:=(?<value>.*))?$/;
|
|
9
|
+
function isOptionToken(input) {
|
|
10
|
+
return DString.test(input, regexOption);
|
|
11
|
+
}
|
|
12
|
+
function findOptionToken(args, option) {
|
|
13
|
+
return DArray.reduce(args, DArray.reduceFrom(null), ({ element, next, exit, index }) => {
|
|
14
|
+
const extractResult = DString.extract(element, regexOption);
|
|
15
|
+
if (!extractResult) return next(null);
|
|
16
|
+
const key = extractResult.namedGroups.key;
|
|
17
|
+
if (option.name !== key && (!DArray.includes(option.aliases, key) || extractResult.namedGroups?.dashes !== "-")) return next(null);
|
|
18
|
+
return exit({
|
|
19
|
+
key,
|
|
20
|
+
value: extractResult.namedGroups?.value,
|
|
21
|
+
index
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
9
25
|
function constructOption(kindHandler, createConstructor) {
|
|
10
26
|
return createConstructor({ init: (name, execute, params, ...rest) => {
|
|
11
27
|
const self = {
|
|
12
28
|
...Object.fromEntries(Object.entries(rest[0] ?? {}).map(([key, prop]) => typeof prop === "function" ? [key, (...args) => prop(self, ...args)] : [key, prop])),
|
|
13
29
|
name,
|
|
14
30
|
execute: async (args, error) => {
|
|
15
|
-
const result =
|
|
16
|
-
const extractResult = DString.extract(element, regexOption);
|
|
17
|
-
if (!extractResult) return next(null);
|
|
18
|
-
const result = {
|
|
19
|
-
key: extractResult.namedGroups.key,
|
|
20
|
-
value: extractResult.namedGroups?.value,
|
|
21
|
-
index
|
|
22
|
-
};
|
|
23
|
-
if (self.name !== result.key && (!DArray.includes(self.aliases, result.key) || extractResult.namedGroups?.dashes !== "-")) return next(null);
|
|
24
|
-
return exit(result);
|
|
25
|
-
});
|
|
31
|
+
const result = findOptionToken(args, self);
|
|
26
32
|
const { value, argumentRest } = DCommon.justExec(() => {
|
|
27
33
|
if (!result) return {
|
|
28
34
|
value: null,
|
|
@@ -30,7 +36,7 @@ function constructOption(kindHandler, createConstructor) {
|
|
|
30
36
|
};
|
|
31
37
|
if (result.value === void 0) {
|
|
32
38
|
const nextArg = args[result.index + 1];
|
|
33
|
-
if (nextArg === void 0 ||
|
|
39
|
+
if (nextArg === void 0 || isOptionToken(nextArg)) return {
|
|
34
40
|
value: void 0,
|
|
35
41
|
argumentRest: DArray.spliceDelete(args, result.index, 1)
|
|
36
42
|
};
|
|
@@ -60,4 +66,4 @@ function constructOption(kindHandler, createConstructor) {
|
|
|
60
66
|
} });
|
|
61
67
|
}
|
|
62
68
|
//#endregion
|
|
63
|
-
export { constructOption, optionKind };
|
|
69
|
+
export { constructOption, findOptionToken, isOptionToken, optionKind };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Option } from '../base';
|
|
2
|
-
import { EligibleType } from '../../types';
|
|
2
|
+
import { EligibleType, ForbiddenInvalidIdentifier } from '../../types';
|
|
3
3
|
import * as DCommon from "@duplojs/lang/common";
|
|
4
4
|
import type * as DKind from "@duplojs/lang/kind";
|
|
5
5
|
import * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
@@ -13,12 +13,14 @@ export interface ArrayOption<GenericName extends string = string, GenericValue e
|
|
|
13
13
|
readonly min?: number;
|
|
14
14
|
readonly max?: number;
|
|
15
15
|
}
|
|
16
|
-
export interface CreateArrayOptionParams {
|
|
16
|
+
export interface CreateArrayOptionParams<GenericAliases extends readonly string[] = readonly string[]> {
|
|
17
17
|
description?: string;
|
|
18
|
-
aliases?:
|
|
18
|
+
aliases?: (GenericAliases & {
|
|
19
|
+
readonly [Index in keyof GenericAliases]: ForbiddenInvalidIdentifier<GenericAliases[Index]>;
|
|
20
|
+
});
|
|
19
21
|
min?: number;
|
|
20
22
|
max?: number;
|
|
21
23
|
required?: boolean;
|
|
22
24
|
separator?: string;
|
|
23
25
|
}
|
|
24
|
-
export declare const createArrayOption: <GenericName extends string, GenericStructure extends DDataStructure.Structure<EligibleType>, GenericValue extends DDataStructure.StructureValue<GenericStructure>, const GenericParams extends CreateArrayOptionParams = {}>(name: GenericName
|
|
26
|
+
export declare const createArrayOption: <GenericName extends string, GenericStructure extends DDataStructure.Structure<EligibleType>, GenericValue extends DDataStructure.StructureValue<GenericStructure>, const GenericAliases extends readonly string[] = readonly string[], const GenericParams extends CreateArrayOptionParams<GenericAliases> = {}>(name: GenericName & ForbiddenInvalidIdentifier<GenericName>, dataStructure: GenericStructure, params?: GenericParams & CreateArrayOptionParams<GenericAliases>) => ArrayOption<GenericName, ((readonly GenericValue[] & (DNumber.IsLiteral<Extract<GenericParams["min"], number>> extends true ? DArray.MinElements<Extract<GenericParams["min"], number>> : unknown) & (DNumber.IsLiteral<Extract<GenericParams["max"], number>> extends true ? DArray.MaxElements<Extract<GenericParams["max"], number>> : unknown)) | (DCommon.IsEqual<GenericParams["required"], true> extends true ? never : undefined))>;
|
|
@@ -1,14 +1,28 @@
|
|
|
1
|
+
const require_runtime = require("../../../_virtual/_rolldown/runtime.cjs");
|
|
1
2
|
const require_kind = require("../../kind.cjs");
|
|
2
3
|
const require_base = require("../base.cjs");
|
|
4
|
+
let _duplojs_lang_array = require("@duplojs/lang/array");
|
|
5
|
+
_duplojs_lang_array = require_runtime.__toESM(_duplojs_lang_array, 1);
|
|
3
6
|
//#region scripts/command/options/defaults/boolean.ts
|
|
4
7
|
const booleanOptionKind = require_kind.createKind("command-boolean-option");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
function createBooleanOption(name, params) {
|
|
9
|
+
const self = {
|
|
10
|
+
name,
|
|
11
|
+
description: params?.description ?? null,
|
|
12
|
+
aliases: params?.aliases ?? [],
|
|
13
|
+
execute: (args, error) => {
|
|
14
|
+
const token = require_base.findOptionToken(args, self);
|
|
15
|
+
if (token?.value !== void 0) return Promise.resolve(error.addUnexpectedOptionValueIssue(self.name, token.value));
|
|
16
|
+
return Promise.resolve({
|
|
17
|
+
result: token !== null,
|
|
18
|
+
argumentRest: token ? _duplojs_lang_array.spliceDelete(args, token.index, 1) : args
|
|
19
|
+
});
|
|
20
|
+
},
|
|
21
|
+
[require_base.optionKind.runTimeKey]: null,
|
|
22
|
+
[booleanOptionKind.runTimeKey]: null
|
|
23
|
+
};
|
|
24
|
+
return self;
|
|
25
|
+
}
|
|
12
26
|
//#endregion
|
|
13
27
|
exports.booleanOptionKind = booleanOptionKind;
|
|
14
28
|
exports.createBooleanOption = createBooleanOption;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { Option } from '../base';
|
|
2
|
+
import { ForbiddenInvalidIdentifier } from '../../types';
|
|
2
3
|
import type * as DCommon from "@duplojs/lang/common";
|
|
3
4
|
import type * as DKind from "@duplojs/lang/kind";
|
|
4
5
|
export declare const booleanOptionKind: DKind.Handler<DKind.Definition<"@DuplojsServerCommand/command-boolean-option", unknown>>;
|
|
5
6
|
export interface BooleanOption<GenericName extends string = string> extends DCommon.Forward<Option<GenericName, boolean> & DKind.Kind<typeof booleanOptionKind>> {
|
|
6
7
|
}
|
|
7
|
-
export interface CreateBooleanOptionParams {
|
|
8
|
+
export interface CreateBooleanOptionParams<GenericAliases extends readonly string[] = readonly string[]> {
|
|
8
9
|
description?: string;
|
|
9
|
-
aliases?:
|
|
10
|
+
aliases?: (GenericAliases & {
|
|
11
|
+
readonly [Index in keyof GenericAliases]: ForbiddenInvalidIdentifier<GenericAliases[Index]>;
|
|
12
|
+
});
|
|
10
13
|
}
|
|
11
|
-
export declare
|
|
14
|
+
export declare function createBooleanOption<GenericName extends string, const GenericAliases extends readonly string[] = readonly string[]>(name: GenericName & ForbiddenInvalidIdentifier<GenericName>, params?: CreateBooleanOptionParams<GenericAliases>): BooleanOption<GenericName>;
|
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
import { createKind } from "../../kind.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { findOptionToken, optionKind } from "../base.mjs";
|
|
3
|
+
import * as DArray from "@duplojs/lang/array";
|
|
3
4
|
//#region scripts/command/options/defaults/boolean.ts
|
|
4
5
|
const booleanOptionKind = createKind("command-boolean-option");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
function createBooleanOption(name, params) {
|
|
7
|
+
const self = {
|
|
8
|
+
name,
|
|
9
|
+
description: params?.description ?? null,
|
|
10
|
+
aliases: params?.aliases ?? [],
|
|
11
|
+
execute: (args, error) => {
|
|
12
|
+
const token = findOptionToken(args, self);
|
|
13
|
+
if (token?.value !== void 0) return Promise.resolve(error.addUnexpectedOptionValueIssue(self.name, token.value));
|
|
14
|
+
return Promise.resolve({
|
|
15
|
+
result: token !== null,
|
|
16
|
+
argumentRest: token ? DArray.spliceDelete(args, token.index, 1) : args
|
|
17
|
+
});
|
|
18
|
+
},
|
|
19
|
+
[optionKind.runTimeKey]: null,
|
|
20
|
+
[booleanOptionKind.runTimeKey]: null
|
|
21
|
+
};
|
|
22
|
+
return self;
|
|
23
|
+
}
|
|
12
24
|
//#endregion
|
|
13
25
|
export { booleanOptionKind, createBooleanOption };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Option } from '../base';
|
|
2
|
-
import { EligibleType } from '../../types';
|
|
2
|
+
import { EligibleType, ForbiddenInvalidIdentifier } from '../../types';
|
|
3
3
|
import type * as DCommon from "@duplojs/lang/common";
|
|
4
4
|
import type * as DKind from "@duplojs/lang/kind";
|
|
5
5
|
import type * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
@@ -8,9 +8,11 @@ export interface SimpleOption<GenericName extends string = string, GenericValue
|
|
|
8
8
|
readonly dataStructure: DDataStructure.Structure<GenericValue>;
|
|
9
9
|
readonly required: boolean;
|
|
10
10
|
}
|
|
11
|
-
export interface CreateSimpleOptionParams {
|
|
11
|
+
export interface CreateSimpleOptionParams<GenericAliases extends readonly string[] = readonly string[]> {
|
|
12
12
|
description?: string;
|
|
13
|
-
aliases?:
|
|
13
|
+
aliases?: (GenericAliases & {
|
|
14
|
+
readonly [Index in keyof GenericAliases]: ForbiddenInvalidIdentifier<GenericAliases[Index]>;
|
|
15
|
+
});
|
|
14
16
|
required?: boolean;
|
|
15
17
|
}
|
|
16
|
-
export declare const createOption: <GenericName extends string, GenericStructure extends DDataStructure.Structure<EligibleType>, GenericValue extends DDataStructure.StructureValue<GenericStructure>, const GenericParams extends CreateSimpleOptionParams = {}>(name: GenericName
|
|
18
|
+
export declare const createOption: <GenericName extends string, GenericStructure extends DDataStructure.Structure<EligibleType>, GenericValue extends DDataStructure.StructureValue<GenericStructure>, const GenericAliases extends readonly string[] = readonly string[], const GenericParams extends CreateSimpleOptionParams<GenericAliases> = {}>(name: GenericName & ForbiddenInvalidIdentifier<GenericName>, dataStructure: GenericStructure, params?: GenericParams & CreateSimpleOptionParams<GenericAliases>) => SimpleOption<GenericName, (GenericValue | (DCommon.IsEqual<GenericParams["required"], true> extends true ? never : undefined))>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type * as DCommon from "@duplojs/lang/common";
|
|
2
|
+
import type * as DString from "@duplojs/lang/string";
|
|
3
|
+
type AlphanumericCharacter = (DString.CharactersRangeStore["a-z" | "A-Z"] | DString.Digit);
|
|
4
|
+
type AllowedIdentifierCharacter = (AlphanumericCharacter | "_" | "-");
|
|
5
|
+
export type ForbiddenInvalidIdentifier<GenericName extends string> = DCommon.ContainExtends<GenericName, DCommon.BaseConstraint> extends true ? DCommon.ComputedTypeError<"Identifier cannot be a constrained string."> : DString.IsLiteral<GenericName> extends true ? DCommon.IsUnion<GenericName> extends true ? DCommon.ComputedTypeError<"Identifier must be a single string literal."> : DCommon.IsEqual<GenericName, ""> extends true ? DCommon.ComputedTypeError<"Identifier cannot be empty."> : DString.StartsWith<GenericName, AlphanumericCharacter> extends true ? DString.IsAllowedString<GenericName, AllowedIdentifierCharacter> extends true ? DString.IsAllowedString<GenericName, DString.Digit> extends false ? unknown : DCommon.ComputedTypeError<`Identifier "${GenericName}" cannot contain only digits.`> : DCommon.ComputedTypeError<`Identifier "${GenericName}" contains invalid characters (allowed: A-Z, a-z, 0-9, "_" and "-").`> : DCommon.ComputedTypeError<`Identifier "${GenericName}" must start with a letter or digit.`> : DCommon.ComputedTypeError<"Identifier must be a known string literal.">;
|
|
6
|
+
export {};
|
|
@@ -3,7 +3,7 @@ import * as DEither from "@duplojs/lang/either";
|
|
|
3
3
|
import type * as DPath from "@duplojs/lang/path";
|
|
4
4
|
import type * as DSFile from '../../file';
|
|
5
5
|
export interface EnvironmentVariableFileParams {
|
|
6
|
-
includedEnvironmentFiles?:
|
|
6
|
+
includedEnvironmentFiles?: DPath.AnyPath[];
|
|
7
7
|
override?: boolean;
|
|
8
8
|
justRead?: boolean;
|
|
9
9
|
codecs?: DDataStructure.Codecs;
|
|
@@ -2,4 +2,4 @@ import type * as DPath from "@duplojs/lang/path";
|
|
|
2
2
|
import * as DEither from "@duplojs/lang/either";
|
|
3
3
|
import * as DSFile from '../../file';
|
|
4
4
|
export declare function parseEnvironmentLine(line: string): Record<string, string>;
|
|
5
|
-
export declare function parseEnvironmentFiles(baseEnv: Record<string, string>, paths:
|
|
5
|
+
export declare function parseEnvironmentFiles(baseEnv: Record<string, string>, paths: DPath.AnyPath[]): Promise<DEither.Left<"file-system-read-text-file-error", DSFile.ReadTextFileErrors> | readonly Record<string, string>[]>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
2
2
|
import type * as DSFile from '../../file';
|
|
3
|
-
export declare function file<const GenericConstraints extends readonly DDataStructure.Constraint<DSFile.FileInterface>[] = readonly []>(constraints?: GenericConstraints): NoInfer<DDataStructure.TypeStructure<DSFile.FileInterface<
|
|
3
|
+
export declare function file<const GenericConstraints extends readonly DDataStructure.Constraint<DSFile.FileInterface>[] = readonly []>(constraints?: GenericConstraints): NoInfer<DDataStructure.TypeStructure<DSFile.FileInterface<import('@duplojs/lang/path').AnyPath>, readonly [...GenericConstraints]>>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
2
2
|
import type * as DSFile from '../../file';
|
|
3
|
-
export declare function folder<const GenericConstraints extends readonly DDataStructure.Constraint<DSFile.FolderInterface>[] = readonly []>(constraints?: GenericConstraints): NoInfer<DDataStructure.TypeStructure<DSFile.FolderInterface<
|
|
3
|
+
export declare function folder<const GenericConstraints extends readonly DDataStructure.Constraint<DSFile.FolderInterface>[] = readonly []>(constraints?: GenericConstraints): NoInfer<DDataStructure.TypeStructure<DSFile.FolderInterface<import('@duplojs/lang/path').AnyPath>, readonly [...GenericConstraints]>>;
|