@duplojs/server 0.0.0-stage → 0.1.0-beta.10
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/README.md +8 -2
- package/dist/_virtual/_rolldown/runtime.cjs +33 -0
- package/dist/_virtual/_rolldown/runtime.mjs +17 -0
- package/dist/command/argument.cjs +27 -0
- package/dist/command/argument.d.ts +18 -0
- package/dist/command/argument.mjs +24 -0
- package/dist/command/create.cjs +102 -0
- package/dist/command/create.d.ts +47 -0
- package/dist/command/create.mjs +96 -0
- package/dist/command/error.cjs +206 -0
- package/dist/command/error.d.ts +61 -0
- package/dist/command/error.mjs +193 -0
- package/dist/command/exec.cjs +19 -0
- package/dist/command/exec.d.ts +14 -0
- package/dist/command/exec.mjs +17 -0
- package/dist/command/execOptions.cjs +41 -0
- package/dist/command/execOptions.d.ts +14 -0
- package/dist/command/execOptions.mjs +37 -0
- package/dist/command/help.cjs +250 -0
- package/dist/command/help.d.ts +10 -0
- package/dist/command/help.mjs +237 -0
- package/dist/command/index.cjs +82 -0
- package/dist/command/index.d.ts +8 -0
- package/dist/command/index.mjs +47 -0
- package/dist/command/kind.cjs +7 -0
- package/dist/command/kind.d.ts +2 -0
- package/dist/command/kind.mjs +5 -0
- package/dist/command/options/base.cjs +76 -0
- package/dist/command/options/base.d.ts +30 -0
- package/dist/command/options/base.mjs +69 -0
- package/dist/command/options/defaults/array.cjs +35 -0
- package/dist/command/options/defaults/array.d.ts +26 -0
- package/dist/command/options/defaults/array.mjs +29 -0
- package/dist/command/options/defaults/boolean.cjs +28 -0
- package/dist/command/options/defaults/boolean.d.ts +14 -0
- package/dist/command/options/defaults/boolean.mjs +25 -0
- package/dist/command/options/defaults/index.d.ts +3 -0
- package/dist/command/options/defaults/simple.cjs +25 -0
- package/dist/command/options/defaults/simple.d.ts +18 -0
- package/dist/command/options/defaults/simple.mjs +22 -0
- package/dist/command/options/identifier.cjs +7 -0
- package/dist/command/options/identifier.d.ts +4 -0
- package/dist/command/options/identifier.mjs +5 -0
- package/dist/command/options/index.d.ts +4 -0
- package/dist/command/options/types/index.d.ts +1 -0
- package/dist/command/options/types/options.d.ts +9 -0
- package/dist/command/types/eligibleType.d.ts +4 -0
- package/dist/command/types/forbiddenDuplicateName.d.ts +11 -0
- package/dist/command/types/forbiddenInvalidIdentifier.d.ts +6 -0
- package/dist/command/types/index.d.ts +3 -0
- package/dist/common/environmentVariable/expandEnvironmentVariables.cjs +27 -0
- package/dist/common/environmentVariable/expandEnvironmentVariables.d.ts +2 -0
- package/dist/common/environmentVariable/expandEnvironmentVariables.mjs +22 -0
- package/dist/common/environmentVariable/index.cjs +47 -0
- package/dist/common/environmentVariable/index.d.ts +16 -0
- package/dist/common/environmentVariable/index.mjs +41 -0
- package/dist/common/environmentVariable/overrideEnvironmentVariables.cjs +13 -0
- package/dist/common/environmentVariable/overrideEnvironmentVariables.d.ts +3 -0
- package/dist/common/environmentVariable/overrideEnvironmentVariables.mjs +9 -0
- package/dist/common/environmentVariable/parseEnvironmentFiles.cjs +32 -0
- package/dist/common/environmentVariable/parseEnvironmentFiles.d.ts +5 -0
- package/dist/common/environmentVariable/parseEnvironmentFiles.mjs +26 -0
- package/dist/common/environmentVariableOrThrow.cjs +23 -0
- package/dist/common/environmentVariableOrThrow.d.ts +12 -0
- package/dist/common/environmentVariableOrThrow.mjs +19 -0
- package/dist/common/exitProcess.cjs +7 -0
- package/dist/common/exitProcess.d.ts +6 -0
- package/dist/common/exitProcess.mjs +8 -0
- package/dist/common/getCurrentWorkDirectory.cjs +15 -0
- package/dist/common/getCurrentWorkDirectory.d.ts +8 -0
- package/dist/common/getCurrentWorkDirectory.mjs +11 -0
- package/dist/common/getCurrentWorkDirectoryOrThrow.cjs +25 -0
- package/dist/common/getCurrentWorkDirectoryOrThrow.d.ts +8 -0
- package/dist/common/getCurrentWorkDirectoryOrThrow.mjs +20 -0
- package/dist/common/getProcessArguments.cjs +18 -0
- package/dist/common/getProcessArguments.d.ts +6 -0
- package/dist/common/getProcessArguments.mjs +18 -0
- package/dist/common/index.cjs +44 -0
- package/dist/common/index.d.ts +9 -0
- package/dist/common/index.mjs +27 -0
- package/dist/common/meta/getCurrentDirectoryName.cjs +10 -0
- package/dist/common/meta/getCurrentDirectoryName.d.ts +7 -0
- package/dist/common/meta/getCurrentDirectoryName.mjs +7 -0
- package/dist/common/meta/index.d.ts +7 -0
- package/dist/common/setCurrentWorkingDirectory.cjs +11 -0
- package/dist/common/setCurrentWorkingDirectory.d.ts +8 -0
- package/dist/common/setCurrentWorkingDirectory.mjs +9 -0
- package/dist/common/setCurrentWorkingDirectoryOrThrow.cjs +23 -0
- package/dist/common/setCurrentWorkingDirectoryOrThrow.d.ts +8 -0
- package/dist/common/setCurrentWorkingDirectoryOrThrow.mjs +18 -0
- package/dist/dataStructure/common/codec/defaults/index.d.ts +2 -0
- package/dist/dataStructure/common/codec/defaults/json.cjs +25 -0
- package/dist/dataStructure/common/codec/defaults/json.d.ts +9 -0
- package/dist/dataStructure/common/codec/defaults/json.mjs +22 -0
- package/dist/dataStructure/common/codec/defaults/string.cjs +25 -0
- package/dist/dataStructure/common/codec/defaults/string.d.ts +13 -0
- package/dist/dataStructure/common/codec/defaults/string.mjs +22 -0
- package/dist/dataStructure/common/codec/index.d.ts +1 -0
- package/dist/dataStructure/common/error/defaultInterpreter.cjs +29 -0
- package/dist/dataStructure/common/error/defaultInterpreter.d.ts +69 -0
- package/dist/dataStructure/common/error/defaultInterpreter.mjs +26 -0
- package/dist/dataStructure/common/error/index.d.ts +1 -0
- package/dist/dataStructure/common/index.d.ts +2 -0
- package/dist/dataStructure/constraint/fileExist.cjs +19 -0
- package/dist/dataStructure/constraint/fileExist.d.ts +10 -0
- package/dist/dataStructure/constraint/fileExist.mjs +15 -0
- package/dist/dataStructure/constraint/folderExist.cjs +19 -0
- package/dist/dataStructure/constraint/folderExist.d.ts +10 -0
- package/dist/dataStructure/constraint/folderExist.mjs +15 -0
- package/dist/dataStructure/constraint/index.d.ts +5 -0
- package/dist/dataStructure/constraint/mimeType.cjs +18 -0
- package/dist/dataStructure/constraint/mimeType.d.ts +11 -0
- package/dist/dataStructure/constraint/mimeType.mjs +14 -0
- package/dist/dataStructure/constraint/size.cjs +29 -0
- package/dist/dataStructure/constraint/size.d.ts +16 -0
- package/dist/dataStructure/constraint/size.mjs +24 -0
- package/dist/dataStructure/constraint/types/constraints.d.ts +12 -0
- package/dist/dataStructure/constraint/types/index.d.ts +1 -0
- package/dist/dataStructure/fundamentalType/file.cjs +11 -0
- package/dist/dataStructure/fundamentalType/file.d.ts +8 -0
- package/dist/dataStructure/fundamentalType/file.mjs +8 -0
- package/dist/dataStructure/fundamentalType/folder.cjs +11 -0
- package/dist/dataStructure/fundamentalType/folder.d.ts +8 -0
- package/dist/dataStructure/fundamentalType/folder.mjs +8 -0
- package/dist/dataStructure/fundamentalType/index.d.ts +3 -0
- package/dist/dataStructure/fundamentalType/types/fundamentalTypes.d.ts +8 -0
- package/dist/dataStructure/fundamentalType/types/index.d.ts +1 -0
- package/dist/dataStructure/helper/file.cjs +10 -0
- package/dist/dataStructure/helper/file.d.ts +3 -0
- package/dist/dataStructure/helper/file.mjs +8 -0
- package/dist/dataStructure/helper/fileExist.cjs +7 -0
- package/dist/dataStructure/helper/fileExist.d.ts +2 -0
- package/dist/dataStructure/helper/fileExist.mjs +7 -0
- package/dist/dataStructure/helper/folder.cjs +10 -0
- package/dist/dataStructure/helper/folder.d.ts +3 -0
- package/dist/dataStructure/helper/folder.mjs +8 -0
- package/dist/dataStructure/helper/folderExist.cjs +7 -0
- package/dist/dataStructure/helper/folderExist.d.ts +2 -0
- package/dist/dataStructure/helper/folderExist.mjs +7 -0
- package/dist/dataStructure/helper/index.d.ts +6 -0
- package/dist/dataStructure/helper/mimeType.cjs +7 -0
- package/dist/dataStructure/helper/mimeType.d.ts +2 -0
- package/dist/dataStructure/helper/mimeType.mjs +7 -0
- package/dist/dataStructure/helper/size.cjs +7 -0
- package/dist/dataStructure/helper/size.d.ts +2 -0
- package/dist/dataStructure/helper/size.mjs +7 -0
- package/dist/dataStructure/index.cjs +83 -0
- package/dist/dataStructure/index.d.ts +6 -0
- package/dist/dataStructure/index.mjs +51 -0
- package/dist/dataStructure/kind.cjs +7 -0
- package/dist/dataStructure/kind.d.ts +2 -0
- package/dist/dataStructure/kind.mjs +5 -0
- package/dist/dataStructure/type/file.cjs +14 -0
- package/dist/dataStructure/type/file.d.ts +11 -0
- package/dist/dataStructure/type/file.mjs +11 -0
- package/dist/dataStructure/type/folder.cjs +14 -0
- package/dist/dataStructure/type/folder.d.ts +11 -0
- package/dist/dataStructure/type/folder.mjs +11 -0
- package/dist/dataStructure/type/index.d.ts +3 -0
- package/dist/dataStructure/type/types/index.d.ts +1 -0
- package/dist/dataStructure/type/types/types.d.ts +8 -0
- package/dist/file/appendFile.cjs +67 -0
- package/dist/file/appendFile.d.ts +43 -0
- package/dist/file/appendFile.mjs +54 -0
- package/dist/file/appendTextFile.cjs +67 -0
- package/dist/file/appendTextFile.d.ts +43 -0
- package/dist/file/appendTextFile.mjs +54 -0
- package/dist/file/copy.cjs +53 -0
- package/dist/file/copy.d.ts +43 -0
- package/dist/file/copy.mjs +40 -0
- package/dist/file/createEntryInterface.cjs +19 -0
- package/dist/file/createEntryInterface.d.ts +3 -0
- package/dist/file/createEntryInterface.mjs +15 -0
- package/dist/file/ensureDirectory.cjs +52 -0
- package/dist/file/ensureDirectory.d.ts +36 -0
- package/dist/file/ensureDirectory.mjs +41 -0
- package/dist/file/ensureFile.cjs +60 -0
- package/dist/file/ensureFile.d.ts +39 -0
- package/dist/file/ensureFile.mjs +48 -0
- package/dist/file/exists.cjs +43 -0
- package/dist/file/exists.d.ts +27 -0
- package/dist/file/exists.mjs +35 -0
- package/dist/file/fileInterface.cjs +76 -0
- package/dist/file/fileInterface.d.ts +31 -0
- package/dist/file/fileInterface.mjs +70 -0
- package/dist/file/folderInterface.cjs +76 -0
- package/dist/file/folderInterface.d.ts +33 -0
- package/dist/file/folderInterface.mjs +70 -0
- package/dist/file/index.cjs +634 -0
- package/dist/file/index.d.ts +35 -0
- package/dist/file/index.mjs +335 -0
- package/dist/file/link.cjs +70 -0
- package/dist/file/link.d.ts +46 -0
- package/dist/file/link.mjs +56 -0
- package/dist/file/linkStat.cjs +98 -0
- package/dist/file/linkStat.d.ts +31 -0
- package/dist/file/linkStat.mjs +88 -0
- package/dist/file/makeDirectory.cjs +60 -0
- package/dist/file/makeDirectory.d.ts +45 -0
- package/dist/file/makeDirectory.mjs +47 -0
- package/dist/file/makeTemporaryDirectory.cjs +48 -0
- package/dist/file/makeTemporaryDirectory.d.ts +32 -0
- package/dist/file/makeTemporaryDirectory.mjs +38 -0
- package/dist/file/makeTemporaryFile.cjs +62 -0
- package/dist/file/makeTemporaryFile.d.ts +36 -0
- package/dist/file/makeTemporaryFile.mjs +50 -0
- package/dist/file/move.cjs +71 -0
- package/dist/file/move.d.ts +46 -0
- package/dist/file/move.mjs +57 -0
- package/dist/file/readDirectory.cjs +44 -0
- package/dist/file/readDirectory.d.ts +35 -0
- package/dist/file/readDirectory.mjs +33 -0
- package/dist/file/readFile.cjs +51 -0
- package/dist/file/readFile.d.ts +33 -0
- package/dist/file/readFile.mjs +41 -0
- package/dist/file/readJsonFile.cjs +51 -0
- package/dist/file/readJsonFile.d.ts +33 -0
- package/dist/file/readJsonFile.mjs +41 -0
- package/dist/file/readLink.cjs +46 -0
- package/dist/file/readLink.d.ts +30 -0
- package/dist/file/readLink.mjs +37 -0
- package/dist/file/readTextFile.cjs +51 -0
- package/dist/file/readTextFile.d.ts +33 -0
- package/dist/file/readTextFile.mjs +41 -0
- package/dist/file/realPath.cjs +42 -0
- package/dist/file/realPath.d.ts +27 -0
- package/dist/file/realPath.mjs +34 -0
- package/dist/file/relocate.cjs +83 -0
- package/dist/file/relocate.d.ts +46 -0
- package/dist/file/relocate.mjs +68 -0
- package/dist/file/remove.cjs +60 -0
- package/dist/file/remove.d.ts +42 -0
- package/dist/file/remove.mjs +48 -0
- package/dist/file/rename.cjs +83 -0
- package/dist/file/rename.d.ts +46 -0
- package/dist/file/rename.mjs +68 -0
- package/dist/file/setMode.cjs +65 -0
- package/dist/file/setMode.d.ts +45 -0
- package/dist/file/setMode.mjs +56 -0
- package/dist/file/setOwner.cjs +53 -0
- package/dist/file/setOwner.d.ts +35 -0
- package/dist/file/setOwner.mjs +44 -0
- package/dist/file/setTime.cjs +55 -0
- package/dist/file/setTime.d.ts +36 -0
- package/dist/file/setTime.mjs +45 -0
- package/dist/file/stat.cjs +99 -0
- package/dist/file/stat.d.ts +62 -0
- package/dist/file/stat.mjs +89 -0
- package/dist/file/symlink.cjs +64 -0
- package/dist/file/symlink.d.ts +48 -0
- package/dist/file/symlink.mjs +52 -0
- package/dist/file/truncate.cjs +60 -0
- package/dist/file/truncate.d.ts +42 -0
- package/dist/file/truncate.mjs +47 -0
- package/dist/file/unknownEntryInterface.cjs +40 -0
- package/dist/file/unknownEntryInterface.d.ts +17 -0
- package/dist/file/unknownEntryInterface.mjs +35 -0
- package/dist/file/walkDirectory.cjs +57 -0
- package/dist/file/walkDirectory.d.ts +37 -0
- package/dist/file/walkDirectory.mjs +45 -0
- package/dist/file/writeFile.cjs +68 -0
- package/dist/file/writeFile.d.ts +43 -0
- package/dist/file/writeFile.mjs +55 -0
- package/dist/file/writeJsonFile.cjs +77 -0
- package/dist/file/writeJsonFile.d.ts +46 -0
- package/dist/file/writeJsonFile.mjs +64 -0
- package/dist/file/writeTextFile.cjs +68 -0
- package/dist/file/writeTextFile.d.ts +43 -0
- package/dist/file/writeTextFile.mjs +55 -0
- package/dist/implementor.cjs +67 -0
- package/dist/implementor.d.ts +35 -0
- package/dist/implementor.mjs +55 -0
- package/dist/index.cjs +76 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.mjs +15 -0
- package/dist/kind.cjs +7 -0
- package/dist/kind.d.ts +2 -0
- package/dist/kind.mjs +5 -0
- package/dist/override.d.ts +8 -0
- package/package.json +81 -3
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { fileExistConstraintKind } from "../dataStructure/constraint/fileExist.mjs";
|
|
2
|
+
import { folderExistConstraintKind } from "../dataStructure/constraint/folderExist.mjs";
|
|
3
|
+
import { mimeTypeConstraintKind } from "../dataStructure/constraint/mimeType.mjs";
|
|
4
|
+
import { sizeConstraintKind } from "../dataStructure/constraint/size.mjs";
|
|
5
|
+
import { fileTypeKind } from "../dataStructure/type/file.mjs";
|
|
6
|
+
import { folderTypeKind } from "../dataStructure/type/folder.mjs";
|
|
7
|
+
import { arrayOptionKind } from "./options/defaults/array.mjs";
|
|
8
|
+
import { booleanOptionKind, createBooleanOption } from "./options/defaults/boolean.mjs";
|
|
9
|
+
import { simpleOptionKind } from "./options/defaults/simple.mjs";
|
|
10
|
+
import * as DCommon from "@duplojs/lang/common";
|
|
11
|
+
import * as DPattern from "@duplojs/lang/pattern";
|
|
12
|
+
import * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
13
|
+
import * as DArray from "@duplojs/lang/array";
|
|
14
|
+
import * as DString from "@duplojs/lang/string";
|
|
15
|
+
import * as DPrinter from "@duplojs/lang/printer";
|
|
16
|
+
//#region scripts/command/help.ts
|
|
17
|
+
const helpOption = createBooleanOption("help", { aliases: ["h"] });
|
|
18
|
+
const syntax = (input) => DPrinter.colorized(input, "gray");
|
|
19
|
+
const section = (input, color) => DPrinter.colorizedBold(input, color);
|
|
20
|
+
const name = (input) => DPrinter.colorizedBold(input, "cyan");
|
|
21
|
+
const typeLabel = (input) => DPrinter.colorized(input, "blue");
|
|
22
|
+
const literal = (input) => DPrinter.colorized(input, "yellow");
|
|
23
|
+
const marker = (input) => DPrinter.colorized(input, "yellow");
|
|
24
|
+
const secondary = (input) => DPrinter.colorized(input, "gray");
|
|
25
|
+
const constraintLabel = (input) => DPrinter.colorized(input, "magenta");
|
|
26
|
+
function renderInline(input, depth = 0) {
|
|
27
|
+
return DPrinter.renderLine(input, {
|
|
28
|
+
joinCharacter: "",
|
|
29
|
+
indent: DPrinter.Indent.tab,
|
|
30
|
+
indentLevel: depth
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function formatLiteral(value) {
|
|
34
|
+
if (typeof value === "string") return JSON.stringify(value);
|
|
35
|
+
if (typeof value === "bigint") return `${value.toString()}n`;
|
|
36
|
+
return String(value);
|
|
37
|
+
}
|
|
38
|
+
function formatBytes(value) {
|
|
39
|
+
const units = [
|
|
40
|
+
"B",
|
|
41
|
+
"KB",
|
|
42
|
+
"MB",
|
|
43
|
+
"GB",
|
|
44
|
+
"TB"
|
|
45
|
+
];
|
|
46
|
+
let size = value;
|
|
47
|
+
let index = 0;
|
|
48
|
+
while (size >= 1024 && index < units.length - 1) {
|
|
49
|
+
size = size / 1024;
|
|
50
|
+
index++;
|
|
51
|
+
}
|
|
52
|
+
return `${Number.isInteger(size) ? size : size.toFixed(1)} ${units[index]}`;
|
|
53
|
+
}
|
|
54
|
+
function renderType(type) {
|
|
55
|
+
return DPattern.match(type).when(DDataStructure.typeIdentifier(DDataStructure.stringLiteralTypeKind), ({ definition }) => [literal(formatLiteral(definition.value))]).when(DDataStructure.typeIdentifier(DDataStructure.numberLiteralTypeKind), ({ definition }) => [literal(formatLiteral(definition.value))]).when(DDataStructure.typeIdentifier(DDataStructure.bigintLiteralTypeKind), ({ definition }) => [literal(formatLiteral(definition.value))]).when(DDataStructure.typeIdentifier(DDataStructure.booleanLiteralTypeKind), ({ definition }) => [literal(formatLiteral(definition.value))]).when(DDataStructure.typeIdentifier(DDataStructure.nullTypeKind), DCommon.justReturn([literal("null")])).when(DDataStructure.typeIdentifier(DDataStructure.undefinedTypeKind), DCommon.justReturn([literal("undefined")])).when(DDataStructure.typeIdentifier(DDataStructure.stringTypeKind), DCommon.justReturn([typeLabel("string")])).when(DDataStructure.typeIdentifier(DDataStructure.numberTypeKind), DCommon.justReturn([typeLabel("number")])).when(DDataStructure.typeIdentifier(DDataStructure.bigintTypeKind), DCommon.justReturn([typeLabel("bigint")])).when(DDataStructure.typeIdentifier(DDataStructure.booleanTypeKind), DCommon.justReturn([typeLabel("boolean")])).when(DDataStructure.typeIdentifier(DDataStructure.dateTypeKind), DCommon.justReturn([typeLabel("date")])).when(DDataStructure.typeIdentifier(DDataStructure.timeTypeKind), DCommon.justReturn([typeLabel("time")])).when(DDataStructure.typeIdentifier(fileTypeKind), DCommon.justReturn([typeLabel("file")])).when(DDataStructure.typeIdentifier(folderTypeKind), DCommon.justReturn([typeLabel("folder")])).otherwise(DCommon.justReturn([typeLabel("unknown")]));
|
|
56
|
+
}
|
|
57
|
+
function renderStringLength(constraints) {
|
|
58
|
+
const equal = DArray.find(constraints, DDataStructure.constraintIdentifier(DDataStructure.stringLengthEqualConstraintKind));
|
|
59
|
+
const min = DArray.find(constraints, DDataStructure.constraintIdentifier(DDataStructure.minCharactersConstraintKind));
|
|
60
|
+
const max = DArray.find(constraints, DDataStructure.constraintIdentifier(DDataStructure.maxCharactersConstraintKind));
|
|
61
|
+
if (equal) return [constraintLabel("length "), literal(String(equal.definition.length))];
|
|
62
|
+
if (min && max) return [constraintLabel("length "), literal(`${min.definition.min}..${max.definition.max}`)];
|
|
63
|
+
if (min) return [constraintLabel("min length "), literal(String(min.definition.min))];
|
|
64
|
+
if (max) return [constraintLabel("max length "), literal(String(max.definition.max))];
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
function renderArrayLength(constraints) {
|
|
68
|
+
const equal = DArray.find(constraints, DDataStructure.constraintIdentifier(DDataStructure.arrayLengthEqualConstraintKind));
|
|
69
|
+
const min = DArray.find(constraints, DDataStructure.constraintIdentifier(DDataStructure.minElementsConstraintKind));
|
|
70
|
+
const max = DArray.find(constraints, DDataStructure.constraintIdentifier(DDataStructure.maxElementsConstraintKind));
|
|
71
|
+
if (equal) return [constraintLabel("items "), literal(String(equal.definition.length))];
|
|
72
|
+
if (min && max) return [constraintLabel("items "), literal(`${min.definition.min}..${max.definition.max}`)];
|
|
73
|
+
if (min) return [constraintLabel("min items "), literal(String(min.definition.min))];
|
|
74
|
+
if (max) return [constraintLabel("max items "), literal(String(max.definition.max))];
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
function renderNumberBounds(constraints) {
|
|
78
|
+
const greaterThan = DArray.find(constraints, DDataStructure.constraintIdentifier(DDataStructure.greaterThanConstraintKind));
|
|
79
|
+
const greaterThanOrEqual = DArray.find(constraints, DDataStructure.constraintIdentifier(DDataStructure.greaterThanOrEqualConstraintKind));
|
|
80
|
+
const lessThan = DArray.find(constraints, DDataStructure.constraintIdentifier(DDataStructure.lessThanConstraintKind));
|
|
81
|
+
const lessThanOrEqual = DArray.find(constraints, DDataStructure.constraintIdentifier(DDataStructure.lessThanOrEqualConstraintKind));
|
|
82
|
+
return DArray.filter([greaterThan ? [constraintLabel("> "), literal(String(greaterThan.definition.threshold))] : greaterThanOrEqual ? [constraintLabel("min "), literal(String(greaterThanOrEqual.definition.threshold))] : null, lessThan ? [constraintLabel("< "), literal(String(lessThan.definition.threshold))] : lessThanOrEqual ? [constraintLabel("max "), literal(String(lessThanOrEqual.definition.threshold))] : null], DCommon.truthy);
|
|
83
|
+
}
|
|
84
|
+
function renderSimpleConstraint(constraint) {
|
|
85
|
+
return DPattern.match(constraint).when(DDataStructure.constraintIdentifier(DDataStructure.emailConstraintKind), DCommon.justReturn([constraintLabel("email")])).when(DDataStructure.constraintIdentifier(DDataStructure.urlConstraintKind), DCommon.justReturn([constraintLabel("url")])).when(DDataStructure.constraintIdentifier(DDataStructure.uuidConstraintKind), DCommon.justReturn([constraintLabel("uuid")])).when(DDataStructure.constraintIdentifier(DDataStructure.integerConstraintKind), DCommon.justReturn([constraintLabel("integer")])).when(DDataStructure.constraintIdentifier(DDataStructure.trimmedConstraintKind), DCommon.justReturn([constraintLabel("trimmed")])).when(DDataStructure.constraintIdentifier(DDataStructure.notEmptyConstraintKind), DCommon.justReturn([constraintLabel("not empty")])).when(DDataStructure.constraintIdentifier(DDataStructure.numberInStringConstraintKind), DCommon.justReturn([constraintLabel("number in string")])).when(DDataStructure.constraintIdentifier(DDataStructure.evenConstraintKind), DCommon.justReturn([constraintLabel("even")])).when(DDataStructure.constraintIdentifier(DDataStructure.oddConstraintKind), DCommon.justReturn([constraintLabel("odd")])).when(DDataStructure.constraintIdentifier(DDataStructure.positiveConstraintKind), DCommon.justReturn([constraintLabel("positive")])).when(DDataStructure.constraintIdentifier(DDataStructure.negativeConstraintKind), DCommon.justReturn([constraintLabel("negative")])).when(DDataStructure.constraintIdentifier(DDataStructure.notZeroConstraintKind), DCommon.justReturn([constraintLabel("not zero")])).when(DDataStructure.constraintIdentifier(DDataStructure.safeConstraintKind), DCommon.justReturn([constraintLabel("safe number")])).when(DDataStructure.constraintIdentifier(DDataStructure.pathConstraintKind), DCommon.justReturn([constraintLabel("path")])).when(DDataStructure.constraintIdentifier(DDataStructure.absolutePathConstraintKind), DCommon.justReturn([constraintLabel("absolute path")])).when(DDataStructure.constraintIdentifier(DDataStructure.segmentPathConstraintKind), DCommon.justReturn([constraintLabel("path segment")])).when(DDataStructure.constraintIdentifier(fileExistConstraintKind), DCommon.justReturn([constraintLabel("exists")])).when(DDataStructure.constraintIdentifier(folderExistConstraintKind), DCommon.justReturn([constraintLabel("exists")])).when(DDataStructure.constraintIdentifier(DDataStructure.strictPositiveConstraintKind), DCommon.justReturn([constraintLabel("> "), literal("0")])).when(DDataStructure.constraintIdentifier(DDataStructure.strictNegativeConstraintKind), DCommon.justReturn([constraintLabel("< "), literal("0")])).when(DDataStructure.constraintIdentifier(DDataStructure.betweenThanConstraintKind), ({ definition }) => [
|
|
86
|
+
constraintLabel("> "),
|
|
87
|
+
literal(String(definition.greater)),
|
|
88
|
+
secondary(" and "),
|
|
89
|
+
constraintLabel("< "),
|
|
90
|
+
literal(String(definition.less))
|
|
91
|
+
]).when(DDataStructure.constraintIdentifier(DDataStructure.betweenThanOrEqualConstraintKind), ({ definition }) => [constraintLabel("range "), literal(`${definition.greater}..${definition.less}`)]).when(DDataStructure.constraintIdentifier(DDataStructure.multipleOfConstraintKind), ({ definition }) => [constraintLabel("multiple of "), literal(String(definition.multiple))]).when(DDataStructure.constraintIdentifier(DDataStructure.regexConstraintKind), ({ definition }) => [constraintLabel("pattern "), literal(definition.regex.toString())]).when(DDataStructure.constraintIdentifier(mimeTypeConstraintKind), ({ definition }) => [constraintLabel("mime "), literal(definition.regex.toString())]).when(DDataStructure.constraintIdentifier(sizeConstraintKind), (constraint) => {
|
|
92
|
+
const { min, max } = constraint.definition;
|
|
93
|
+
if (min && max) return [constraintLabel("size "), literal(`${formatBytes(min)}..${formatBytes(max)}`)];
|
|
94
|
+
if (min) return [constraintLabel("min size "), literal(formatBytes(min))];
|
|
95
|
+
if (max) return [constraintLabel("max size "), literal(formatBytes(max))];
|
|
96
|
+
return null;
|
|
97
|
+
}).otherwise(DCommon.justReturn(null));
|
|
98
|
+
}
|
|
99
|
+
function renderConstraints(constraints) {
|
|
100
|
+
return DArray.filter([
|
|
101
|
+
renderStringLength(constraints),
|
|
102
|
+
renderArrayLength(constraints),
|
|
103
|
+
...renderNumberBounds(constraints),
|
|
104
|
+
...DArray.map(constraints, renderSimpleConstraint)
|
|
105
|
+
], DCommon.truthy);
|
|
106
|
+
}
|
|
107
|
+
function renderDataStructure(dataStructure) {
|
|
108
|
+
const constraints = renderConstraints(dataStructure.definition.constraints);
|
|
109
|
+
if (DDataStructure.structureIdentifier(dataStructure, DDataStructure.lazyStructureKind)) {
|
|
110
|
+
const inner = renderDataStructure(dataStructure.definition.getter.value);
|
|
111
|
+
return {
|
|
112
|
+
main: inner.main,
|
|
113
|
+
constraints: [...inner.constraints, ...constraints]
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
if (DDataStructure.structureIdentifier(dataStructure, DDataStructure.typeStructureKind)) return {
|
|
117
|
+
main: renderType(dataStructure.definition.type),
|
|
118
|
+
constraints
|
|
119
|
+
};
|
|
120
|
+
if (DDataStructure.structureIdentifier(dataStructure, DDataStructure.arrayStructureKind)) {
|
|
121
|
+
const element = renderDataStructure(dataStructure.definition.element);
|
|
122
|
+
return {
|
|
123
|
+
main: [...element.main, typeLabel("[]")],
|
|
124
|
+
constraints: [...DArray.map(element.constraints, (constraint) => [constraintLabel("item "), constraint]), ...constraints]
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
if (DDataStructure.structureIdentifier(dataStructure, DDataStructure.unionStructureKind)) {
|
|
128
|
+
const values = DCommon.pipe(dataStructure.definition.values.value, DArray.filter((structure) => !DDataStructure.isUndefinedStructure(structure)), DArray.map(renderDataStructure));
|
|
129
|
+
if (values.length === 0) return {
|
|
130
|
+
main: [literal("undefined")],
|
|
131
|
+
constraints
|
|
132
|
+
};
|
|
133
|
+
if (values.length === 1) return {
|
|
134
|
+
main: values[0].main,
|
|
135
|
+
constraints: [...values[0].constraints, ...constraints]
|
|
136
|
+
};
|
|
137
|
+
return {
|
|
138
|
+
main: DArray.reduce(DArray.map(values, ({ main }) => main), DArray.reduceFrom([]), ({ element, index, lastValue, next }) => next([
|
|
139
|
+
...lastValue,
|
|
140
|
+
index === 0 ? null : [secondary(" | ")],
|
|
141
|
+
element
|
|
142
|
+
])),
|
|
143
|
+
constraints
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
main: [typeLabel("unknown")],
|
|
148
|
+
constraints
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function renderMetadata(help, markerValue) {
|
|
152
|
+
return renderInline([
|
|
153
|
+
...help.main,
|
|
154
|
+
secondary(" · "),
|
|
155
|
+
markerValue === "required" ? marker(markerValue) : secondary(markerValue)
|
|
156
|
+
]);
|
|
157
|
+
}
|
|
158
|
+
function renderConstraintLines(constraints, depth) {
|
|
159
|
+
return DArray.map(constraints, (constraint) => renderInline([secondary("↳ "), constraint], depth));
|
|
160
|
+
}
|
|
161
|
+
function renderDescriptionLine(description, depth) {
|
|
162
|
+
return description ? renderInline([secondary(description)], depth) : null;
|
|
163
|
+
}
|
|
164
|
+
function renderUsage(command) {
|
|
165
|
+
const args = command.subject?.type === "argument" ? DArray.map(command.subject.args, (argument) => argument.optional ? `[${argument.name}]` : `<${argument.name}>`) : command.subject?.type === "subCommand" ? ["<command>"] : [];
|
|
166
|
+
return DCommon.pipe([
|
|
167
|
+
command.name,
|
|
168
|
+
...args,
|
|
169
|
+
command.options.length > 0 ? "[options]" : null
|
|
170
|
+
], DArray.filter(DCommon.truthy), DString.join(" "));
|
|
171
|
+
}
|
|
172
|
+
function renderOptionSignature(option) {
|
|
173
|
+
return [
|
|
174
|
+
DArray.map(option.aliases, (alias) => [
|
|
175
|
+
syntax("-"),
|
|
176
|
+
name(alias),
|
|
177
|
+
syntax(", ")
|
|
178
|
+
]),
|
|
179
|
+
syntax("--"),
|
|
180
|
+
name(option.name),
|
|
181
|
+
simpleOptionKind.has(option) ? syntax(" <value>") : null,
|
|
182
|
+
arrayOptionKind.has(option) ? syntax(" <value...>") : null
|
|
183
|
+
];
|
|
184
|
+
}
|
|
185
|
+
function renderOptionDetails(option, depth) {
|
|
186
|
+
if (simpleOptionKind.has(option) || arrayOptionKind.has(option)) {
|
|
187
|
+
const help = renderDataStructure(option.dataStructure);
|
|
188
|
+
return DArray.filter([
|
|
189
|
+
renderInline([renderMetadata(help, option.required ? "required" : "optional")], depth),
|
|
190
|
+
...renderConstraintLines(help.constraints, depth),
|
|
191
|
+
renderDescriptionLine(option.description, depth)
|
|
192
|
+
], DCommon.truthy);
|
|
193
|
+
}
|
|
194
|
+
if (booleanOptionKind.has(option)) return DArray.filter([renderInline([typeLabel("boolean")], depth), renderDescriptionLine(option.description, depth)], DCommon.truthy);
|
|
195
|
+
return DArray.filter([renderDescriptionLine(option.description, depth)], DCommon.truthy);
|
|
196
|
+
}
|
|
197
|
+
function renderOptionsHelp(options, depth) {
|
|
198
|
+
return DPrinter.renderParagraph([renderInline([section("OPTIONS", "magenta")], depth), DArray.map(options, (option) => DPrinter.renderParagraph([renderInline([renderOptionSignature(option)], depth + 1), renderOptionDetails(option, depth + 2)]))]);
|
|
199
|
+
}
|
|
200
|
+
function renderArgumentsHelp(args, depth) {
|
|
201
|
+
return DPrinter.renderParagraph([renderInline([section("ARGUMENTS", "cyan")], depth), DArray.map(args, (argument) => {
|
|
202
|
+
const help = renderDataStructure(argument.dataStructure);
|
|
203
|
+
return DPrinter.renderParagraph([
|
|
204
|
+
renderInline([name(argument.name.padEnd(12)), renderMetadata(help, argument.optional ? "optional" : "required")], depth + 1),
|
|
205
|
+
renderConstraintLines(help.constraints, depth + 2),
|
|
206
|
+
renderDescriptionLine(argument.description, depth + 2)
|
|
207
|
+
]);
|
|
208
|
+
})]);
|
|
209
|
+
}
|
|
210
|
+
function renderSubCommandsHelp(commands, depth) {
|
|
211
|
+
return DPrinter.renderParagraph([renderInline([section("COMMANDS", "green")], depth), DArray.map(commands, (command) => renderInline([name(command.name.padEnd(16)), command.description ? secondary(command.description) : null], depth + 1))]);
|
|
212
|
+
}
|
|
213
|
+
function renderCommandHelp(command, depth) {
|
|
214
|
+
return [...DArray.filter([
|
|
215
|
+
renderInline([
|
|
216
|
+
section("COMMAND", "green"),
|
|
217
|
+
" ",
|
|
218
|
+
DPrinter.colorizedBold(command.name, "cyan")
|
|
219
|
+
], depth),
|
|
220
|
+
renderDescriptionLine(command.description, depth + 1),
|
|
221
|
+
DPrinter.renderParagraph([renderInline([section("USAGE", "blue")], depth), renderInline([syntax(renderUsage(command))], depth + 1)]),
|
|
222
|
+
command.subject?.type === "argument" ? renderArgumentsHelp(command.subject.args, depth) : null,
|
|
223
|
+
command.subject?.type === "subCommand" ? renderSubCommandsHelp(command.subject.subCommands, depth) : null,
|
|
224
|
+
DArray.minElements(command.options, 1) ? renderOptionsHelp(command.options, depth) : null
|
|
225
|
+
], DCommon.truthy)];
|
|
226
|
+
}
|
|
227
|
+
function logCommandHelp(command) {
|
|
228
|
+
console.log(DPrinter.renderParagraph(renderCommandHelp(command, 0)));
|
|
229
|
+
}
|
|
230
|
+
function renderExecOptionHelp(options, depth) {
|
|
231
|
+
return [renderInline([section("EXEC OPTIONS", "green")], depth), renderOptionsHelp(options, depth)];
|
|
232
|
+
}
|
|
233
|
+
function logExecOptionHelp(options) {
|
|
234
|
+
console.log(DPrinter.renderParagraph(renderExecOptionHelp(options, 0)));
|
|
235
|
+
}
|
|
236
|
+
//#endregion
|
|
237
|
+
export { helpOption, logCommandHelp, logExecOptionHelp, renderArgumentsHelp, renderCommandHelp, renderExecOptionHelp, renderOptionsHelp };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_argument = require("./argument.cjs");
|
|
3
|
+
const require_error = require("./error.cjs");
|
|
4
|
+
const require_base = require("./options/base.cjs");
|
|
5
|
+
const require_array = require("./options/defaults/array.cjs");
|
|
6
|
+
const require_boolean = require("./options/defaults/boolean.cjs");
|
|
7
|
+
const require_simple = require("./options/defaults/simple.cjs");
|
|
8
|
+
const require_identifier = require("./options/identifier.cjs");
|
|
9
|
+
const require_help = require("./help.cjs");
|
|
10
|
+
const require_create = require("./create.cjs");
|
|
11
|
+
const require_exec = require("./exec.cjs");
|
|
12
|
+
const require_execOptions = require("./execOptions.cjs");
|
|
13
|
+
//#region scripts/command/index.ts
|
|
14
|
+
var command_exports = /* @__PURE__ */ require_runtime.__exportAll({
|
|
15
|
+
SymbolCommandError: () => require_error.SymbolCommandError,
|
|
16
|
+
argumentKind: () => require_argument.argumentKind,
|
|
17
|
+
arrayOptionKind: () => require_array.arrayOptionKind,
|
|
18
|
+
booleanOptionKind: () => require_boolean.booleanOptionKind,
|
|
19
|
+
constructOption: () => require_base.constructOption,
|
|
20
|
+
create: () => require_create.create,
|
|
21
|
+
createArgument: () => require_argument.createArgument,
|
|
22
|
+
createArrayOption: () => require_array.createArrayOption,
|
|
23
|
+
createBooleanOption: () => require_boolean.createBooleanOption,
|
|
24
|
+
createError: () => require_error.createError,
|
|
25
|
+
createOption: () => require_simple.createOption,
|
|
26
|
+
exec: () => require_exec.exec,
|
|
27
|
+
execOptions: () => require_execOptions.execOptions,
|
|
28
|
+
findOptionToken: () => require_base.findOptionToken,
|
|
29
|
+
helpOption: () => require_help.helpOption,
|
|
30
|
+
interpretDataStructureError: () => require_error.interpretDataStructureError,
|
|
31
|
+
interpretErrorIssues: () => require_error.interpretErrorIssues,
|
|
32
|
+
interpretExecCommandError: () => require_error.interpretExecCommandError,
|
|
33
|
+
interpretExecOptionsError: () => require_error.interpretExecOptionsError,
|
|
34
|
+
isCommands: () => require_create.isCommands,
|
|
35
|
+
isOptionToken: () => require_base.isOptionToken,
|
|
36
|
+
logCommandHelp: () => require_help.logCommandHelp,
|
|
37
|
+
logExecOptionHelp: () => require_help.logExecOptionHelp,
|
|
38
|
+
optionIdentifier: () => require_identifier.optionIdentifier,
|
|
39
|
+
optionKind: () => require_base.optionKind,
|
|
40
|
+
renderArgumentsHelp: () => require_help.renderArgumentsHelp,
|
|
41
|
+
renderCommandHelp: () => require_help.renderCommandHelp,
|
|
42
|
+
renderExecOptionHelp: () => require_help.renderExecOptionHelp,
|
|
43
|
+
renderOptionsHelp: () => require_help.renderOptionsHelp,
|
|
44
|
+
simpleOptionKind: () => require_simple.simpleOptionKind
|
|
45
|
+
});
|
|
46
|
+
//#endregion
|
|
47
|
+
exports.SymbolCommandError = require_error.SymbolCommandError;
|
|
48
|
+
exports.argumentKind = require_argument.argumentKind;
|
|
49
|
+
exports.arrayOptionKind = require_array.arrayOptionKind;
|
|
50
|
+
exports.booleanOptionKind = require_boolean.booleanOptionKind;
|
|
51
|
+
Object.defineProperty(exports, "command_exports", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function() {
|
|
54
|
+
return command_exports;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
exports.constructOption = require_base.constructOption;
|
|
58
|
+
exports.create = require_create.create;
|
|
59
|
+
exports.createArgument = require_argument.createArgument;
|
|
60
|
+
exports.createArrayOption = require_array.createArrayOption;
|
|
61
|
+
exports.createBooleanOption = require_boolean.createBooleanOption;
|
|
62
|
+
exports.createError = require_error.createError;
|
|
63
|
+
exports.createOption = require_simple.createOption;
|
|
64
|
+
exports.exec = require_exec.exec;
|
|
65
|
+
exports.execOptions = require_execOptions.execOptions;
|
|
66
|
+
exports.findOptionToken = require_base.findOptionToken;
|
|
67
|
+
exports.helpOption = require_help.helpOption;
|
|
68
|
+
exports.interpretDataStructureError = require_error.interpretDataStructureError;
|
|
69
|
+
exports.interpretErrorIssues = require_error.interpretErrorIssues;
|
|
70
|
+
exports.interpretExecCommandError = require_error.interpretExecCommandError;
|
|
71
|
+
exports.interpretExecOptionsError = require_error.interpretExecOptionsError;
|
|
72
|
+
exports.isCommands = require_create.isCommands;
|
|
73
|
+
exports.isOptionToken = require_base.isOptionToken;
|
|
74
|
+
exports.logCommandHelp = require_help.logCommandHelp;
|
|
75
|
+
exports.logExecOptionHelp = require_help.logExecOptionHelp;
|
|
76
|
+
exports.optionIdentifier = require_identifier.optionIdentifier;
|
|
77
|
+
exports.optionKind = require_base.optionKind;
|
|
78
|
+
exports.renderArgumentsHelp = require_help.renderArgumentsHelp;
|
|
79
|
+
exports.renderCommandHelp = require_help.renderCommandHelp;
|
|
80
|
+
exports.renderExecOptionHelp = require_help.renderExecOptionHelp;
|
|
81
|
+
exports.renderOptionsHelp = require_help.renderOptionsHelp;
|
|
82
|
+
exports.simpleOptionKind = require_simple.simpleOptionKind;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.mjs";
|
|
2
|
+
import { argumentKind, createArgument } from "./argument.mjs";
|
|
3
|
+
import { SymbolCommandError, createError, interpretDataStructureError, interpretErrorIssues, interpretExecCommandError, interpretExecOptionsError } from "./error.mjs";
|
|
4
|
+
import { constructOption, findOptionToken, isOptionToken, optionKind } from "./options/base.mjs";
|
|
5
|
+
import { arrayOptionKind, createArrayOption } from "./options/defaults/array.mjs";
|
|
6
|
+
import { booleanOptionKind, createBooleanOption } from "./options/defaults/boolean.mjs";
|
|
7
|
+
import { createOption, simpleOptionKind } from "./options/defaults/simple.mjs";
|
|
8
|
+
import { optionIdentifier } from "./options/identifier.mjs";
|
|
9
|
+
import { helpOption, logCommandHelp, logExecOptionHelp, renderArgumentsHelp, renderCommandHelp, renderExecOptionHelp, renderOptionsHelp } from "./help.mjs";
|
|
10
|
+
import { create, isCommands } from "./create.mjs";
|
|
11
|
+
import { exec } from "./exec.mjs";
|
|
12
|
+
import { execOptions } from "./execOptions.mjs";
|
|
13
|
+
//#region scripts/command/index.ts
|
|
14
|
+
var command_exports = /* @__PURE__ */ __exportAll({
|
|
15
|
+
SymbolCommandError: () => SymbolCommandError,
|
|
16
|
+
argumentKind: () => argumentKind,
|
|
17
|
+
arrayOptionKind: () => arrayOptionKind,
|
|
18
|
+
booleanOptionKind: () => booleanOptionKind,
|
|
19
|
+
constructOption: () => constructOption,
|
|
20
|
+
create: () => create,
|
|
21
|
+
createArgument: () => createArgument,
|
|
22
|
+
createArrayOption: () => createArrayOption,
|
|
23
|
+
createBooleanOption: () => createBooleanOption,
|
|
24
|
+
createError: () => createError,
|
|
25
|
+
createOption: () => createOption,
|
|
26
|
+
exec: () => exec,
|
|
27
|
+
execOptions: () => execOptions,
|
|
28
|
+
findOptionToken: () => findOptionToken,
|
|
29
|
+
helpOption: () => helpOption,
|
|
30
|
+
interpretDataStructureError: () => interpretDataStructureError,
|
|
31
|
+
interpretErrorIssues: () => interpretErrorIssues,
|
|
32
|
+
interpretExecCommandError: () => interpretExecCommandError,
|
|
33
|
+
interpretExecOptionsError: () => interpretExecOptionsError,
|
|
34
|
+
isCommands: () => isCommands,
|
|
35
|
+
isOptionToken: () => isOptionToken,
|
|
36
|
+
logCommandHelp: () => logCommandHelp,
|
|
37
|
+
logExecOptionHelp: () => logExecOptionHelp,
|
|
38
|
+
optionIdentifier: () => optionIdentifier,
|
|
39
|
+
optionKind: () => optionKind,
|
|
40
|
+
renderArgumentsHelp: () => renderArgumentsHelp,
|
|
41
|
+
renderCommandHelp: () => renderCommandHelp,
|
|
42
|
+
renderExecOptionHelp: () => renderExecOptionHelp,
|
|
43
|
+
renderOptionsHelp: () => renderOptionsHelp,
|
|
44
|
+
simpleOptionKind: () => simpleOptionKind
|
|
45
|
+
});
|
|
46
|
+
//#endregion
|
|
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 };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
let _duplojs_lang_kind = require("@duplojs/lang/kind");
|
|
3
|
+
_duplojs_lang_kind = require_runtime.__toESM(_duplojs_lang_kind, 1);
|
|
4
|
+
//#region scripts/command/kind.ts
|
|
5
|
+
const createKind = _duplojs_lang_kind.createNamespace("DuplojsServerCommand");
|
|
6
|
+
//#endregion
|
|
7
|
+
exports.createKind = createKind;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import * as DKind from "@duplojs/lang/kind";
|
|
2
|
+
export declare const createKind: <GenericName extends string, GenericKindValue extends unknown = unknown>(name: GenericName & import('@duplojs/lang/string').ForbiddenContain<GenericName, DKind.ForbiddenKindNameCharacter>) => DKind.Handler<DKind.Definition<`@DuplojsServerCommand/${GenericName}`, GenericKindValue>>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const require_runtime = require("../../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_kind = require("../kind.cjs");
|
|
3
|
+
const require_error = require("../error.cjs");
|
|
4
|
+
let _duplojs_lang_common = require("@duplojs/lang/common");
|
|
5
|
+
_duplojs_lang_common = require_runtime.__toESM(_duplojs_lang_common, 1);
|
|
6
|
+
let _duplojs_lang_array = require("@duplojs/lang/array");
|
|
7
|
+
_duplojs_lang_array = require_runtime.__toESM(_duplojs_lang_array, 1);
|
|
8
|
+
let _duplojs_lang_string = require("@duplojs/lang/string");
|
|
9
|
+
_duplojs_lang_string = require_runtime.__toESM(_duplojs_lang_string, 1);
|
|
10
|
+
//#region scripts/command/options/base.ts
|
|
11
|
+
const optionKind = require_kind.createKind("command-option");
|
|
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
|
+
}
|
|
29
|
+
function constructOption(kindHandler, createConstructor) {
|
|
30
|
+
return createConstructor({ init: (name, execute, params, ...rest) => {
|
|
31
|
+
const self = {
|
|
32
|
+
...Object.fromEntries(Object.entries(rest[0] ?? {}).map(([key, prop]) => typeof prop === "function" ? [key, (...args) => prop(self, ...args)] : [key, prop])),
|
|
33
|
+
name,
|
|
34
|
+
execute: async (args, error) => {
|
|
35
|
+
const result = findOptionToken(args, self);
|
|
36
|
+
const { value, argumentRest } = _duplojs_lang_common.justExec(() => {
|
|
37
|
+
if (!result) return {
|
|
38
|
+
value: null,
|
|
39
|
+
argumentRest: args
|
|
40
|
+
};
|
|
41
|
+
if (result.value === void 0) {
|
|
42
|
+
const nextArg = args[result.index + 1];
|
|
43
|
+
if (nextArg === void 0 || isOptionToken(nextArg)) return {
|
|
44
|
+
value: void 0,
|
|
45
|
+
argumentRest: _duplojs_lang_array.spliceDelete(args, result.index, 1)
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
value: nextArg,
|
|
49
|
+
argumentRest: _duplojs_lang_array.spliceDelete(args, result.index, 2)
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
value: result.value,
|
|
54
|
+
argumentRest: _duplojs_lang_array.spliceDelete(args, result.index, 1)
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
const executeResult = await execute(self, value, error);
|
|
58
|
+
if (executeResult === require_error.SymbolCommandError) return require_error.SymbolCommandError;
|
|
59
|
+
return {
|
|
60
|
+
result: executeResult,
|
|
61
|
+
argumentRest
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
aliases: params?.aliases ?? [],
|
|
65
|
+
description: params?.description ?? null,
|
|
66
|
+
[optionKind.runTimeKey]: null,
|
|
67
|
+
[kindHandler.runTimeKey]: null
|
|
68
|
+
};
|
|
69
|
+
return self;
|
|
70
|
+
} });
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
exports.constructOption = constructOption;
|
|
74
|
+
exports.findOptionToken = findOptionToken;
|
|
75
|
+
exports.isOptionToken = isOptionToken;
|
|
76
|
+
exports.optionKind = optionKind;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Error, SymbolCommandError } from '../error';
|
|
2
|
+
import * as DCommon from "@duplojs/lang/common";
|
|
3
|
+
import type * as DKind from "@duplojs/lang/kind";
|
|
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;
|
|
11
|
+
export interface Option<GenericName extends string = string, GenericValue extends unknown = unknown> extends DKind.Kind<typeof optionKind> {
|
|
12
|
+
readonly name: GenericName;
|
|
13
|
+
readonly description: string | null;
|
|
14
|
+
readonly aliases: readonly string[];
|
|
15
|
+
execute(args: readonly string[], error: Error): Promise<{
|
|
16
|
+
result: GenericValue;
|
|
17
|
+
argumentRest: readonly string[];
|
|
18
|
+
} | SymbolCommandError>;
|
|
19
|
+
}
|
|
20
|
+
export interface CreateOptionInitParams {
|
|
21
|
+
description: string | null;
|
|
22
|
+
aliases: readonly string[];
|
|
23
|
+
}
|
|
24
|
+
export type CreateOptionInitRest<GenericOption extends Option = Option> = {
|
|
25
|
+
[Prop in Exclude<keyof GenericOption, keyof Option>]: GenericOption[Prop] extends DCommon.AnyFunction ? (self: GenericOption, ...args: Parameters<GenericOption[Prop]>) => ReturnType<GenericOption[Prop]> : GenericOption[Prop];
|
|
26
|
+
};
|
|
27
|
+
export interface CreateOptionConstructorParams<GenericKindHandler extends DKind.Handler = DKind.Handler> {
|
|
28
|
+
init<GenericOption extends (Option & DKind.Kind<GenericKindHandler>)>(name: GenericOption["name"], execute: (self: GenericOption, value: string | undefined | null, error: Error) => DCommon.MaybePromise<Extract<Awaited<ReturnType<GenericOption["execute"]>>, object>["result"] | SymbolCommandError>, params: CreateOptionInitParams, ...args: DCommon.IsNever<Exclude<keyof GenericOption, keyof Option>> extends true ? [] : [rest: CreateOptionInitRest<GenericOption>]): NoInfer<GenericOption>;
|
|
29
|
+
}
|
|
30
|
+
export declare function constructOption<GenericKindHandler extends DKind.Handler, GenericConstructor extends ((...args: any[]) => (Option & DKind.Kind<GenericKindHandler>))>(kindHandler: GenericKindHandler, createConstructor: (params: CreateOptionConstructorParams<GenericKindHandler>) => GenericConstructor): GenericConstructor;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { createKind } from "../kind.mjs";
|
|
2
|
+
import { SymbolCommandError } from "../error.mjs";
|
|
3
|
+
import * as DCommon from "@duplojs/lang/common";
|
|
4
|
+
import * as DArray from "@duplojs/lang/array";
|
|
5
|
+
import * as DString from "@duplojs/lang/string";
|
|
6
|
+
//#region scripts/command/options/base.ts
|
|
7
|
+
const optionKind = createKind("command-option");
|
|
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
|
+
}
|
|
25
|
+
function constructOption(kindHandler, createConstructor) {
|
|
26
|
+
return createConstructor({ init: (name, execute, params, ...rest) => {
|
|
27
|
+
const self = {
|
|
28
|
+
...Object.fromEntries(Object.entries(rest[0] ?? {}).map(([key, prop]) => typeof prop === "function" ? [key, (...args) => prop(self, ...args)] : [key, prop])),
|
|
29
|
+
name,
|
|
30
|
+
execute: async (args, error) => {
|
|
31
|
+
const result = findOptionToken(args, self);
|
|
32
|
+
const { value, argumentRest } = DCommon.justExec(() => {
|
|
33
|
+
if (!result) return {
|
|
34
|
+
value: null,
|
|
35
|
+
argumentRest: args
|
|
36
|
+
};
|
|
37
|
+
if (result.value === void 0) {
|
|
38
|
+
const nextArg = args[result.index + 1];
|
|
39
|
+
if (nextArg === void 0 || isOptionToken(nextArg)) return {
|
|
40
|
+
value: void 0,
|
|
41
|
+
argumentRest: DArray.spliceDelete(args, result.index, 1)
|
|
42
|
+
};
|
|
43
|
+
return {
|
|
44
|
+
value: nextArg,
|
|
45
|
+
argumentRest: DArray.spliceDelete(args, result.index, 2)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
value: result.value,
|
|
50
|
+
argumentRest: DArray.spliceDelete(args, result.index, 1)
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
const executeResult = await execute(self, value, error);
|
|
54
|
+
if (executeResult === SymbolCommandError) return SymbolCommandError;
|
|
55
|
+
return {
|
|
56
|
+
result: executeResult,
|
|
57
|
+
argumentRest
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
aliases: params?.aliases ?? [],
|
|
61
|
+
description: params?.description ?? null,
|
|
62
|
+
[optionKind.runTimeKey]: null,
|
|
63
|
+
[kindHandler.runTimeKey]: null
|
|
64
|
+
};
|
|
65
|
+
return self;
|
|
66
|
+
} });
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
export { constructOption, findOptionToken, isOptionToken, optionKind };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const require_runtime = require("../../../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_string = require("../../../dataStructure/common/codec/defaults/string.cjs");
|
|
3
|
+
const require_kind = require("../../kind.cjs");
|
|
4
|
+
const require_base = require("../base.cjs");
|
|
5
|
+
let _duplojs_lang_common = require("@duplojs/lang/common");
|
|
6
|
+
_duplojs_lang_common = require_runtime.__toESM(_duplojs_lang_common, 1);
|
|
7
|
+
let _duplojs_lang_either = require("@duplojs/lang/either");
|
|
8
|
+
_duplojs_lang_either = require_runtime.__toESM(_duplojs_lang_either, 1);
|
|
9
|
+
let _duplojs_lang_dataStructure = require("@duplojs/lang/dataStructure");
|
|
10
|
+
_duplojs_lang_dataStructure = require_runtime.__toESM(_duplojs_lang_dataStructure, 1);
|
|
11
|
+
let _duplojs_lang_string = require("@duplojs/lang/string");
|
|
12
|
+
_duplojs_lang_string = require_runtime.__toESM(_duplojs_lang_string, 1);
|
|
13
|
+
//#region scripts/command/options/defaults/array.ts
|
|
14
|
+
const defaultSeparator = ",";
|
|
15
|
+
const arrayOptionKind = require_kind.createKind("command-array-option");
|
|
16
|
+
const createArrayOption = require_base.constructOption(arrayOptionKind, ({ init }) => (name, dataStructure, params) => init(name, async (self, value, error) => {
|
|
17
|
+
if (value === null && self.required === true) return error.addRequiredOptionIssue(self.name);
|
|
18
|
+
if (value === null) return;
|
|
19
|
+
if (value === void 0) return error.addRequiredOptionValueIssue(self.name);
|
|
20
|
+
const result = await self.dataStructure.asyncDecode(require_string.codecsString, _duplojs_lang_string.split(value, self.separator));
|
|
21
|
+
if (_duplojs_lang_either.isLeft(result)) return error.addDataStructureOptionIssue(self.name, value, _duplojs_lang_either.unwrapLeft(result));
|
|
22
|
+
return _duplojs_lang_either.unwrapRight(result);
|
|
23
|
+
}, {
|
|
24
|
+
description: params?.description ?? null,
|
|
25
|
+
aliases: params?.aliases ?? []
|
|
26
|
+
}, {
|
|
27
|
+
dataStructure: _duplojs_lang_common.justExec(() => _duplojs_lang_common.pipe(dataStructure, _duplojs_lang_dataStructure.array, (dataStructure) => params?.min !== void 0 ? dataStructure.addConstraint(_duplojs_lang_dataStructure.minElements(params.min)) : dataStructure, (dataStructure) => params?.max !== void 0 ? dataStructure.addConstraint(_duplojs_lang_dataStructure.maxElements(params.max)) : dataStructure)),
|
|
28
|
+
required: params?.required ?? false,
|
|
29
|
+
min: params?.min,
|
|
30
|
+
max: params?.max,
|
|
31
|
+
separator: params?.separator ?? defaultSeparator
|
|
32
|
+
}));
|
|
33
|
+
//#endregion
|
|
34
|
+
exports.arrayOptionKind = arrayOptionKind;
|
|
35
|
+
exports.createArrayOption = createArrayOption;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Option } from '../base';
|
|
2
|
+
import { EligibleType, ForbiddenInvalidIdentifier } from '../../types';
|
|
3
|
+
import * as DCommon from "@duplojs/lang/common";
|
|
4
|
+
import type * as DKind from "@duplojs/lang/kind";
|
|
5
|
+
import * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
6
|
+
import type * as DNumber from "@duplojs/lang/number";
|
|
7
|
+
import type * as DArray from "@duplojs/lang/array";
|
|
8
|
+
export declare const arrayOptionKind: DKind.Handler<DKind.Definition<"@DuplojsServerCommand/command-array-option", unknown>>;
|
|
9
|
+
export interface ArrayOption<GenericName extends string = string, GenericValue extends (readonly EligibleType[] | undefined) = (readonly EligibleType[] | undefined)> extends DCommon.Forward<Option<GenericName, GenericValue> & DKind.Kind<typeof arrayOptionKind>> {
|
|
10
|
+
readonly dataStructure: DDataStructure.Structure<GenericValue>;
|
|
11
|
+
readonly required: boolean;
|
|
12
|
+
readonly separator: string;
|
|
13
|
+
readonly min?: number;
|
|
14
|
+
readonly max?: number;
|
|
15
|
+
}
|
|
16
|
+
export interface CreateArrayOptionParams<GenericAliases extends readonly string[] = readonly string[]> {
|
|
17
|
+
description?: string;
|
|
18
|
+
aliases?: (GenericAliases & {
|
|
19
|
+
readonly [Index in keyof GenericAliases]: ForbiddenInvalidIdentifier<GenericAliases[Index]>;
|
|
20
|
+
});
|
|
21
|
+
min?: number;
|
|
22
|
+
max?: number;
|
|
23
|
+
required?: boolean;
|
|
24
|
+
separator?: string;
|
|
25
|
+
}
|
|
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))>;
|