@duplojs/server 0.1.0-beta.1 → 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/dist/_virtual/_rolldown/runtime.mjs +5 -1
- package/dist/command/argument.d.ts +2 -2
- package/dist/command/create.cjs +18 -10
- package/dist/command/create.d.ts +3 -3
- package/dist/command/create.mjs +18 -10
- package/dist/command/error.cjs +96 -43
- package/dist/command/error.d.ts +9 -1
- package/dist/command/error.mjs +95 -42
- package/dist/command/exec.d.ts +4 -3
- package/dist/command/help.cjs +28 -35
- package/dist/command/help.d.ts +1 -1
- package/dist/command/help.mjs +27 -34
- 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 +2 -1
- package/dist/common/index.cjs +3 -0
- package/dist/common/index.d.ts +1 -0
- package/dist/common/index.mjs +3 -1
- 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/dataStructure/common/codec/defaults/json.cjs +12 -1
- package/dist/dataStructure/common/codec/defaults/json.d.ts +2 -2
- package/dist/dataStructure/common/codec/defaults/json.mjs +12 -1
- package/dist/dataStructure/common/codec/defaults/string.cjs +12 -1
- package/dist/dataStructure/common/codec/defaults/string.d.ts +2 -2
- package/dist/dataStructure/common/codec/defaults/string.mjs +12 -1
- package/dist/dataStructure/common/error/defaultInterpreter.cjs +3 -1
- package/dist/dataStructure/common/error/defaultInterpreter.d.ts +7 -2
- package/dist/dataStructure/common/error/defaultInterpreter.mjs +3 -1
- package/dist/dataStructure/constraint/{exist.cjs → fileExist.cjs} +5 -5
- package/dist/dataStructure/constraint/fileExist.d.ts +10 -0
- package/dist/dataStructure/constraint/{exist.mjs → fileExist.mjs} +4 -4
- 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 +2 -1
- package/dist/dataStructure/constraint/mimeType.cjs +1 -1
- package/dist/dataStructure/constraint/mimeType.mjs +1 -1
- package/dist/dataStructure/constraint/types/constraints.d.ts +4 -2
- 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 +1 -0
- package/dist/dataStructure/fundamentalType/types/fundamentalTypes.d.ts +2 -0
- package/dist/dataStructure/helper/file.d.ts +1 -1
- 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 +3 -1
- package/dist/dataStructure/index.cjs +29 -8
- package/dist/dataStructure/index.mjs +19 -6
- 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 +1 -0
- package/dist/dataStructure/type/types/types.d.ts +2 -0
- package/dist/file/appendFile.cjs +46 -22
- package/dist/file/appendFile.d.ts +37 -5
- package/dist/file/appendFile.mjs +36 -23
- package/dist/file/appendTextFile.cjs +44 -20
- package/dist/file/appendTextFile.d.ts +37 -5
- package/dist/file/appendTextFile.mjs +34 -21
- package/dist/file/copy.cjs +36 -14
- package/dist/file/copy.d.ts +37 -5
- package/dist/file/copy.mjs +26 -15
- package/dist/file/createEntryInterface.cjs +6 -3
- package/dist/file/createEntryInterface.d.ts +1 -1
- package/dist/file/createEntryInterface.mjs +4 -2
- package/dist/file/ensureDirectory.cjs +37 -17
- package/dist/file/ensureDirectory.d.ts +30 -4
- package/dist/file/ensureDirectory.mjs +29 -18
- package/dist/file/ensureFile.cjs +41 -19
- package/dist/file/ensureFile.d.ts +33 -4
- package/dist/file/ensureFile.mjs +32 -20
- package/dist/file/exists.cjs +28 -14
- package/dist/file/exists.d.ts +21 -4
- package/dist/file/exists.mjs +23 -15
- package/dist/file/fileInterface.cjs +3 -1
- package/dist/file/fileInterface.d.ts +10 -9
- package/dist/file/fileInterface.mjs +3 -2
- package/dist/file/folderInterface.cjs +3 -1
- package/dist/file/folderInterface.d.ts +9 -8
- package/dist/file/folderInterface.mjs +3 -2
- package/dist/file/index.cjs +512 -0
- package/dist/file/index.d.ts +0 -1
- package/dist/file/index.mjs +291 -35
- package/dist/file/link.cjs +48 -22
- package/dist/file/link.d.ts +40 -5
- package/dist/file/link.mjs +37 -23
- package/dist/file/linkStat.cjs +29 -15
- package/dist/file/linkStat.d.ts +24 -4
- package/dist/file/linkStat.mjs +24 -16
- package/dist/file/makeDirectory.cjs +45 -21
- package/dist/file/makeDirectory.d.ts +35 -4
- package/dist/file/makeDirectory.mjs +35 -22
- package/dist/file/makeTemporaryDirectory.cjs +33 -15
- package/dist/file/makeTemporaryDirectory.d.ts +25 -2
- package/dist/file/makeTemporaryDirectory.mjs +26 -16
- package/dist/file/makeTemporaryFile.cjs +37 -20
- package/dist/file/makeTemporaryFile.d.ts +28 -2
- package/dist/file/makeTemporaryFile.mjs +30 -21
- package/dist/file/move.cjs +49 -23
- package/dist/file/move.d.ts +40 -5
- package/dist/file/move.mjs +38 -24
- package/dist/file/readDirectory.cjs +33 -9
- package/dist/file/readDirectory.d.ts +26 -5
- package/dist/file/readDirectory.mjs +25 -10
- package/dist/file/readFile.cjs +35 -17
- package/dist/file/readFile.d.ts +27 -4
- package/dist/file/readFile.mjs +28 -18
- package/dist/file/readJsonFile.cjs +35 -17
- package/dist/file/readJsonFile.d.ts +27 -5
- package/dist/file/readJsonFile.mjs +28 -18
- package/dist/file/readLink.cjs +31 -15
- package/dist/file/readLink.d.ts +24 -4
- package/dist/file/readLink.mjs +25 -16
- package/dist/file/readTextFile.cjs +35 -17
- package/dist/file/readTextFile.d.ts +27 -4
- package/dist/file/readTextFile.mjs +28 -18
- package/dist/file/realPath.cjs +27 -13
- package/dist/file/realPath.d.ts +21 -4
- package/dist/file/realPath.mjs +22 -14
- package/dist/file/relocate.cjs +52 -25
- package/dist/file/relocate.d.ts +40 -5
- package/dist/file/relocate.mjs +41 -26
- package/dist/file/remove.cjs +45 -23
- package/dist/file/remove.d.ts +32 -4
- package/dist/file/remove.mjs +36 -24
- package/dist/file/rename.cjs +52 -25
- package/dist/file/rename.d.ts +40 -5
- package/dist/file/rename.mjs +41 -26
- package/dist/file/setMode.cjs +29 -15
- package/dist/file/setMode.d.ts +24 -5
- package/dist/file/setMode.mjs +24 -16
- package/dist/file/setOwner.cjs +31 -15
- package/dist/file/setOwner.d.ts +25 -5
- package/dist/file/setOwner.mjs +25 -16
- package/dist/file/setTime.cjs +31 -15
- package/dist/file/setTime.d.ts +24 -5
- package/dist/file/setTime.mjs +25 -16
- package/dist/file/stat.cjs +29 -15
- package/dist/file/stat.d.ts +24 -4
- package/dist/file/stat.mjs +24 -16
- package/dist/file/symlink.cjs +42 -20
- package/dist/file/symlink.d.ts +34 -5
- package/dist/file/symlink.mjs +33 -21
- package/dist/file/truncate.cjs +43 -21
- package/dist/file/truncate.d.ts +36 -4
- package/dist/file/truncate.mjs +34 -22
- package/dist/file/unknownEntryInterface.cjs +5 -1
- package/dist/file/unknownEntryInterface.d.ts +8 -6
- package/dist/file/unknownEntryInterface.mjs +4 -2
- package/dist/file/walkDirectory.cjs +38 -15
- package/dist/file/walkDirectory.d.ts +25 -4
- package/dist/file/walkDirectory.mjs +32 -15
- package/dist/file/writeFile.cjs +45 -21
- package/dist/file/writeFile.d.ts +37 -5
- package/dist/file/writeFile.mjs +35 -22
- package/dist/file/writeJsonFile.cjs +48 -27
- package/dist/file/writeJsonFile.d.ts +37 -6
- package/dist/file/writeJsonFile.mjs +39 -28
- package/dist/file/writeTextFile.cjs +45 -21
- package/dist/file/writeTextFile.d.ts +37 -5
- package/dist/file/writeTextFile.mjs +35 -22
- package/dist/implementor.cjs +8 -5
- package/dist/implementor.d.ts +4 -4
- package/dist/implementor.mjs +8 -5
- package/dist/index.cjs +2 -0
- package/dist/index.mjs +2 -1
- package/dist/override.d.ts +8 -0
- package/package.json +4 -4
- package/dist/dataStructure/constraint/exist.d.ts +0 -10
- package/dist/dataStructure/helper/exist.cjs +0 -7
- package/dist/dataStructure/helper/exist.d.ts +0 -2
- package/dist/dataStructure/helper/exist.mjs +0 -7
- package/dist/file/types/fileSystemEither.d.ts +0 -2
- package/dist/file/types/index.d.ts +0 -1
- /package/{README → README.md} +0 -0
package/dist/command/help.cjs
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
-
const
|
|
2
|
+
const require_fileExist = require("../dataStructure/constraint/fileExist.cjs");
|
|
3
|
+
const require_folderExist = require("../dataStructure/constraint/folderExist.cjs");
|
|
3
4
|
const require_mimeType = require("../dataStructure/constraint/mimeType.cjs");
|
|
4
5
|
const require_size = require("../dataStructure/constraint/size.cjs");
|
|
5
6
|
const require_file = require("../dataStructure/type/file.cjs");
|
|
7
|
+
const require_folder = require("../dataStructure/type/folder.cjs");
|
|
6
8
|
const require_array = require("./options/defaults/array.cjs");
|
|
7
9
|
const require_boolean = require("./options/defaults/boolean.cjs");
|
|
8
10
|
const require_simple = require("./options/defaults/simple.cjs");
|
|
9
11
|
let _duplojs_lang_common = require("@duplojs/lang/common");
|
|
10
12
|
_duplojs_lang_common = require_runtime.__toESM(_duplojs_lang_common, 1);
|
|
13
|
+
let _duplojs_lang_pattern = require("@duplojs/lang/pattern");
|
|
14
|
+
_duplojs_lang_pattern = require_runtime.__toESM(_duplojs_lang_pattern, 1);
|
|
11
15
|
let _duplojs_lang_dataStructure = require("@duplojs/lang/dataStructure");
|
|
12
16
|
_duplojs_lang_dataStructure = require_runtime.__toESM(_duplojs_lang_dataStructure, 1);
|
|
13
17
|
let _duplojs_lang_array = require("@duplojs/lang/array");
|
|
14
18
|
_duplojs_lang_array = require_runtime.__toESM(_duplojs_lang_array, 1);
|
|
15
|
-
let _duplojs_lang_pattern = require("@duplojs/lang/pattern");
|
|
16
|
-
_duplojs_lang_pattern = require_runtime.__toESM(_duplojs_lang_pattern, 1);
|
|
17
19
|
let _duplojs_lang_string = require("@duplojs/lang/string");
|
|
18
20
|
_duplojs_lang_string = require_runtime.__toESM(_duplojs_lang_string, 1);
|
|
19
21
|
let _duplojs_lang_printer = require("@duplojs/lang/printer");
|
|
@@ -28,8 +30,12 @@ const literal = (input) => _duplojs_lang_printer.colorized(input, "yellow");
|
|
|
28
30
|
const marker = (input) => _duplojs_lang_printer.colorized(input, "yellow");
|
|
29
31
|
const secondary = (input) => _duplojs_lang_printer.colorized(input, "gray");
|
|
30
32
|
const constraintLabel = (input) => _duplojs_lang_printer.colorized(input, "magenta");
|
|
31
|
-
function renderInline(input) {
|
|
32
|
-
return _duplojs_lang_printer.
|
|
33
|
+
function renderInline(input, depth = 0) {
|
|
34
|
+
return _duplojs_lang_printer.renderLine(input, {
|
|
35
|
+
joinCharacter: "",
|
|
36
|
+
indent: _duplojs_lang_printer.Indent.tab,
|
|
37
|
+
indentLevel: depth
|
|
38
|
+
});
|
|
33
39
|
}
|
|
34
40
|
function formatLiteral(value) {
|
|
35
41
|
if (typeof value === "string") return JSON.stringify(value);
|
|
@@ -53,7 +59,7 @@ function formatBytes(value) {
|
|
|
53
59
|
return `${Number.isInteger(size) ? size : size.toFixed(1)} ${units[index]}`;
|
|
54
60
|
}
|
|
55
61
|
function renderType(type) {
|
|
56
|
-
return _duplojs_lang_pattern.match(type).when(_duplojs_lang_dataStructure.typeIdentifier(_duplojs_lang_dataStructure.stringLiteralTypeKind), ({ definition }) => [literal(formatLiteral(definition.value))]).when(_duplojs_lang_dataStructure.typeIdentifier(_duplojs_lang_dataStructure.numberLiteralTypeKind), ({ definition }) => [literal(formatLiteral(definition.value))]).when(_duplojs_lang_dataStructure.typeIdentifier(_duplojs_lang_dataStructure.bigintLiteralTypeKind), ({ definition }) => [literal(formatLiteral(definition.value))]).when(_duplojs_lang_dataStructure.typeIdentifier(_duplojs_lang_dataStructure.booleanLiteralTypeKind), ({ definition }) => [literal(formatLiteral(definition.value))]).when(_duplojs_lang_dataStructure.typeIdentifier(_duplojs_lang_dataStructure.nullTypeKind), _duplojs_lang_common.justReturn([literal("null")])).when(_duplojs_lang_dataStructure.typeIdentifier(_duplojs_lang_dataStructure.undefinedTypeKind), _duplojs_lang_common.justReturn([literal("undefined")])).when(_duplojs_lang_dataStructure.typeIdentifier(_duplojs_lang_dataStructure.stringTypeKind), _duplojs_lang_common.justReturn([typeLabel("string")])).when(_duplojs_lang_dataStructure.typeIdentifier(_duplojs_lang_dataStructure.numberTypeKind), _duplojs_lang_common.justReturn([typeLabel("number")])).when(_duplojs_lang_dataStructure.typeIdentifier(_duplojs_lang_dataStructure.bigintTypeKind), _duplojs_lang_common.justReturn([typeLabel("bigint")])).when(_duplojs_lang_dataStructure.typeIdentifier(_duplojs_lang_dataStructure.booleanTypeKind), _duplojs_lang_common.justReturn([typeLabel("boolean")])).when(_duplojs_lang_dataStructure.typeIdentifier(_duplojs_lang_dataStructure.dateTypeKind), _duplojs_lang_common.justReturn([typeLabel("date")])).when(_duplojs_lang_dataStructure.typeIdentifier(_duplojs_lang_dataStructure.timeTypeKind), _duplojs_lang_common.justReturn([typeLabel("time")])).when(_duplojs_lang_dataStructure.typeIdentifier(require_file.fileTypeKind), _duplojs_lang_common.justReturn([typeLabel("file")])).otherwise(_duplojs_lang_common.justReturn([typeLabel("unknown")]));
|
|
62
|
+
return _duplojs_lang_pattern.match(type).when(_duplojs_lang_dataStructure.typeIdentifier(_duplojs_lang_dataStructure.stringLiteralTypeKind), ({ definition }) => [literal(formatLiteral(definition.value))]).when(_duplojs_lang_dataStructure.typeIdentifier(_duplojs_lang_dataStructure.numberLiteralTypeKind), ({ definition }) => [literal(formatLiteral(definition.value))]).when(_duplojs_lang_dataStructure.typeIdentifier(_duplojs_lang_dataStructure.bigintLiteralTypeKind), ({ definition }) => [literal(formatLiteral(definition.value))]).when(_duplojs_lang_dataStructure.typeIdentifier(_duplojs_lang_dataStructure.booleanLiteralTypeKind), ({ definition }) => [literal(formatLiteral(definition.value))]).when(_duplojs_lang_dataStructure.typeIdentifier(_duplojs_lang_dataStructure.nullTypeKind), _duplojs_lang_common.justReturn([literal("null")])).when(_duplojs_lang_dataStructure.typeIdentifier(_duplojs_lang_dataStructure.undefinedTypeKind), _duplojs_lang_common.justReturn([literal("undefined")])).when(_duplojs_lang_dataStructure.typeIdentifier(_duplojs_lang_dataStructure.stringTypeKind), _duplojs_lang_common.justReturn([typeLabel("string")])).when(_duplojs_lang_dataStructure.typeIdentifier(_duplojs_lang_dataStructure.numberTypeKind), _duplojs_lang_common.justReturn([typeLabel("number")])).when(_duplojs_lang_dataStructure.typeIdentifier(_duplojs_lang_dataStructure.bigintTypeKind), _duplojs_lang_common.justReturn([typeLabel("bigint")])).when(_duplojs_lang_dataStructure.typeIdentifier(_duplojs_lang_dataStructure.booleanTypeKind), _duplojs_lang_common.justReturn([typeLabel("boolean")])).when(_duplojs_lang_dataStructure.typeIdentifier(_duplojs_lang_dataStructure.dateTypeKind), _duplojs_lang_common.justReturn([typeLabel("date")])).when(_duplojs_lang_dataStructure.typeIdentifier(_duplojs_lang_dataStructure.timeTypeKind), _duplojs_lang_common.justReturn([typeLabel("time")])).when(_duplojs_lang_dataStructure.typeIdentifier(require_file.fileTypeKind), _duplojs_lang_common.justReturn([typeLabel("file")])).when(_duplojs_lang_dataStructure.typeIdentifier(require_folder.folderTypeKind), _duplojs_lang_common.justReturn([typeLabel("folder")])).otherwise(_duplojs_lang_common.justReturn([typeLabel("unknown")]));
|
|
57
63
|
}
|
|
58
64
|
function renderStringLength(constraints) {
|
|
59
65
|
const equal = _duplojs_lang_array.find(constraints, _duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.stringLengthEqualConstraintKind));
|
|
@@ -83,7 +89,7 @@ function renderNumberBounds(constraints) {
|
|
|
83
89
|
return _duplojs_lang_array.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], _duplojs_lang_common.truthy);
|
|
84
90
|
}
|
|
85
91
|
function renderSimpleConstraint(constraint) {
|
|
86
|
-
return _duplojs_lang_pattern.match(constraint).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.emailConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("email")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.urlConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("url")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.uuidConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("uuid")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.integerConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("integer")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.trimmedConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("trimmed")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.notEmptyConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("not empty")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.numberInStringConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("number in string")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.evenConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("even")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.oddConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("odd")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.positiveConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("positive")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.negativeConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("negative")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.notZeroConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("not zero")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.safeConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("safe number")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.pathConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("path")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.absolutePathConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("absolute path")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.segmentPathConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("path segment")])).when(_duplojs_lang_dataStructure.constraintIdentifier(
|
|
92
|
+
return _duplojs_lang_pattern.match(constraint).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.emailConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("email")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.urlConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("url")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.uuidConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("uuid")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.integerConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("integer")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.trimmedConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("trimmed")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.notEmptyConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("not empty")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.numberInStringConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("number in string")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.evenConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("even")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.oddConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("odd")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.positiveConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("positive")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.negativeConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("negative")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.notZeroConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("not zero")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.safeConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("safe number")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.pathConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("path")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.absolutePathConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("absolute path")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.segmentPathConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("path segment")])).when(_duplojs_lang_dataStructure.constraintIdentifier(require_fileExist.fileExistConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("exists")])).when(_duplojs_lang_dataStructure.constraintIdentifier(require_folderExist.folderExistConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("exists")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.strictPositiveConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("> "), literal("0")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.strictNegativeConstraintKind), _duplojs_lang_common.justReturn([constraintLabel("< "), literal("0")])).when(_duplojs_lang_dataStructure.constraintIdentifier(_duplojs_lang_dataStructure.betweenThanConstraintKind), ({ definition }) => [
|
|
87
93
|
constraintLabel("> "),
|
|
88
94
|
literal(String(definition.greater)),
|
|
89
95
|
secondary(" and "),
|
|
@@ -157,14 +163,10 @@ function renderMetadata(help, markerValue) {
|
|
|
157
163
|
]);
|
|
158
164
|
}
|
|
159
165
|
function renderConstraintLines(constraints, depth) {
|
|
160
|
-
return _duplojs_lang_array.map(constraints, (constraint) => renderInline([
|
|
161
|
-
_duplojs_lang_printer.indent(depth),
|
|
162
|
-
secondary("↳ "),
|
|
163
|
-
constraint
|
|
164
|
-
]));
|
|
166
|
+
return _duplojs_lang_array.map(constraints, (constraint) => renderInline([secondary("↳ "), constraint], depth));
|
|
165
167
|
}
|
|
166
168
|
function renderDescriptionLine(description, depth) {
|
|
167
|
-
return description ? renderInline([
|
|
169
|
+
return description ? renderInline([secondary(description)], depth) : null;
|
|
168
170
|
}
|
|
169
171
|
function renderUsage(command) {
|
|
170
172
|
const args = command.subject?.type === "argument" ? _duplojs_lang_array.map(command.subject.args, (argument) => argument.optional ? `[${argument.name}]` : `<${argument.name}>`) : command.subject?.type === "subCommand" ? ["<command>"] : [];
|
|
@@ -191,48 +193,39 @@ function renderOptionDetails(option, depth) {
|
|
|
191
193
|
if (require_simple.simpleOptionKind.has(option) || require_array.arrayOptionKind.has(option)) {
|
|
192
194
|
const help = renderDataStructure(option.dataStructure);
|
|
193
195
|
return _duplojs_lang_array.filter([
|
|
194
|
-
renderInline([
|
|
195
|
-
|
|
196
|
-
|
|
196
|
+
renderInline([renderMetadata(help, option.required ? "required" : "optional")], depth),
|
|
197
|
+
...renderConstraintLines(help.constraints, depth),
|
|
198
|
+
renderDescriptionLine(option.description, depth)
|
|
197
199
|
], _duplojs_lang_common.truthy);
|
|
198
200
|
}
|
|
199
|
-
if (require_boolean.booleanOptionKind.has(option)) return _duplojs_lang_array.filter([renderInline([
|
|
201
|
+
if (require_boolean.booleanOptionKind.has(option)) return _duplojs_lang_array.filter([renderInline([typeLabel("boolean")], depth), renderDescriptionLine(option.description, depth)], _duplojs_lang_common.truthy);
|
|
200
202
|
return _duplojs_lang_array.filter([renderDescriptionLine(option.description, depth)], _duplojs_lang_common.truthy);
|
|
201
203
|
}
|
|
202
204
|
function renderOptionsHelp(options, depth) {
|
|
203
|
-
return _duplojs_lang_printer.renderParagraph([renderInline([
|
|
205
|
+
return _duplojs_lang_printer.renderParagraph([renderInline([section("OPTIONS", "magenta")], depth), _duplojs_lang_array.map(options, (option) => _duplojs_lang_printer.renderParagraph([renderInline([renderOptionSignature(option)], depth + 1), renderOptionDetails(option, depth + 2)]))]);
|
|
204
206
|
}
|
|
205
207
|
function renderArgumentsHelp(args, depth) {
|
|
206
|
-
return _duplojs_lang_printer.renderParagraph([renderInline([
|
|
208
|
+
return _duplojs_lang_printer.renderParagraph([renderInline([section("ARGUMENTS", "cyan")], depth), _duplojs_lang_array.map(args, (argument) => {
|
|
207
209
|
const help = renderDataStructure(argument.dataStructure);
|
|
208
210
|
return _duplojs_lang_printer.renderParagraph([
|
|
209
|
-
renderInline([
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
renderMetadata(help, argument.optional ? "optional" : "required")
|
|
213
|
-
]),
|
|
214
|
-
renderDescriptionLine(argument.description, depth + 2),
|
|
215
|
-
renderConstraintLines(help.constraints, depth + 2)
|
|
211
|
+
renderInline([name(argument.name.padEnd(12)), renderMetadata(help, argument.optional ? "optional" : "required")], depth + 1),
|
|
212
|
+
renderConstraintLines(help.constraints, depth + 2),
|
|
213
|
+
renderDescriptionLine(argument.description, depth + 2)
|
|
216
214
|
]);
|
|
217
215
|
})]);
|
|
218
216
|
}
|
|
219
217
|
function renderSubCommandsHelp(commands, depth) {
|
|
220
|
-
return _duplojs_lang_printer.renderParagraph([renderInline([
|
|
221
|
-
_duplojs_lang_printer.indent(depth + 1),
|
|
222
|
-
name(command.name.padEnd(16)),
|
|
223
|
-
command.description ? secondary(command.description) : null
|
|
224
|
-
]))]);
|
|
218
|
+
return _duplojs_lang_printer.renderParagraph([renderInline([section("COMMANDS", "green")], depth), _duplojs_lang_array.map(commands, (command) => renderInline([name(command.name.padEnd(16)), command.description ? secondary(command.description) : null], depth + 1))]);
|
|
225
219
|
}
|
|
226
220
|
function renderCommandHelp(command, depth) {
|
|
227
221
|
return [..._duplojs_lang_array.filter([
|
|
228
222
|
renderInline([
|
|
229
|
-
_duplojs_lang_printer.indent(depth),
|
|
230
223
|
section("COMMAND", "green"),
|
|
231
224
|
" ",
|
|
232
225
|
_duplojs_lang_printer.colorizedBold(command.name, "cyan")
|
|
233
|
-
]),
|
|
226
|
+
], depth),
|
|
234
227
|
renderDescriptionLine(command.description, depth + 1),
|
|
235
|
-
_duplojs_lang_printer.renderParagraph([renderInline([
|
|
228
|
+
_duplojs_lang_printer.renderParagraph([renderInline([section("USAGE", "blue")], depth), renderInline([syntax(renderUsage(command))], depth + 1)]),
|
|
236
229
|
command.subject?.type === "argument" ? renderArgumentsHelp(command.subject.args, depth) : null,
|
|
237
230
|
command.subject?.type === "subCommand" ? renderSubCommandsHelp(command.subject.subCommands, depth) : null,
|
|
238
231
|
_duplojs_lang_array.minElements(command.options, 1) ? renderOptionsHelp(command.options, depth) : null
|
|
@@ -242,7 +235,7 @@ function logCommandHelp(command) {
|
|
|
242
235
|
console.log(_duplojs_lang_printer.renderParagraph(renderCommandHelp(command, 0)));
|
|
243
236
|
}
|
|
244
237
|
function renderExecOptionHelp(options, depth) {
|
|
245
|
-
return [renderInline([
|
|
238
|
+
return [renderInline([section("EXEC OPTIONS", "green")], depth), renderOptionsHelp(options, depth)];
|
|
246
239
|
}
|
|
247
240
|
function logExecOptionHelp(options) {
|
|
248
241
|
console.log(_duplojs_lang_printer.renderParagraph(renderExecOptionHelp(options, 0)));
|
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/help.mjs
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { fileExistConstraintKind } from "../dataStructure/constraint/fileExist.mjs";
|
|
2
|
+
import { folderExistConstraintKind } from "../dataStructure/constraint/folderExist.mjs";
|
|
2
3
|
import { mimeTypeConstraintKind } from "../dataStructure/constraint/mimeType.mjs";
|
|
3
4
|
import { sizeConstraintKind } from "../dataStructure/constraint/size.mjs";
|
|
4
5
|
import { fileTypeKind } from "../dataStructure/type/file.mjs";
|
|
6
|
+
import { folderTypeKind } from "../dataStructure/type/folder.mjs";
|
|
5
7
|
import { arrayOptionKind } from "./options/defaults/array.mjs";
|
|
6
8
|
import { booleanOptionKind, createBooleanOption } from "./options/defaults/boolean.mjs";
|
|
7
9
|
import { simpleOptionKind } from "./options/defaults/simple.mjs";
|
|
8
10
|
import * as DCommon from "@duplojs/lang/common";
|
|
11
|
+
import * as DPattern from "@duplojs/lang/pattern";
|
|
9
12
|
import * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
10
13
|
import * as DArray from "@duplojs/lang/array";
|
|
11
|
-
import * as DPattern from "@duplojs/lang/pattern";
|
|
12
14
|
import * as DString from "@duplojs/lang/string";
|
|
13
15
|
import * as DPrinter from "@duplojs/lang/printer";
|
|
14
16
|
//#region scripts/command/help.ts
|
|
@@ -21,8 +23,12 @@ const literal = (input) => DPrinter.colorized(input, "yellow");
|
|
|
21
23
|
const marker = (input) => DPrinter.colorized(input, "yellow");
|
|
22
24
|
const secondary = (input) => DPrinter.colorized(input, "gray");
|
|
23
25
|
const constraintLabel = (input) => DPrinter.colorized(input, "magenta");
|
|
24
|
-
function renderInline(input) {
|
|
25
|
-
return DPrinter.
|
|
26
|
+
function renderInline(input, depth = 0) {
|
|
27
|
+
return DPrinter.renderLine(input, {
|
|
28
|
+
joinCharacter: "",
|
|
29
|
+
indent: DPrinter.Indent.tab,
|
|
30
|
+
indentLevel: depth
|
|
31
|
+
});
|
|
26
32
|
}
|
|
27
33
|
function formatLiteral(value) {
|
|
28
34
|
if (typeof value === "string") return JSON.stringify(value);
|
|
@@ -46,7 +52,7 @@ function formatBytes(value) {
|
|
|
46
52
|
return `${Number.isInteger(size) ? size : size.toFixed(1)} ${units[index]}`;
|
|
47
53
|
}
|
|
48
54
|
function renderType(type) {
|
|
49
|
-
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")])).otherwise(DCommon.justReturn([typeLabel("unknown")]));
|
|
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")]));
|
|
50
56
|
}
|
|
51
57
|
function renderStringLength(constraints) {
|
|
52
58
|
const equal = DArray.find(constraints, DDataStructure.constraintIdentifier(DDataStructure.stringLengthEqualConstraintKind));
|
|
@@ -76,7 +82,7 @@ function renderNumberBounds(constraints) {
|
|
|
76
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);
|
|
77
83
|
}
|
|
78
84
|
function renderSimpleConstraint(constraint) {
|
|
79
|
-
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(
|
|
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 }) => [
|
|
80
86
|
constraintLabel("> "),
|
|
81
87
|
literal(String(definition.greater)),
|
|
82
88
|
secondary(" and "),
|
|
@@ -150,14 +156,10 @@ function renderMetadata(help, markerValue) {
|
|
|
150
156
|
]);
|
|
151
157
|
}
|
|
152
158
|
function renderConstraintLines(constraints, depth) {
|
|
153
|
-
return DArray.map(constraints, (constraint) => renderInline([
|
|
154
|
-
DPrinter.indent(depth),
|
|
155
|
-
secondary("↳ "),
|
|
156
|
-
constraint
|
|
157
|
-
]));
|
|
159
|
+
return DArray.map(constraints, (constraint) => renderInline([secondary("↳ "), constraint], depth));
|
|
158
160
|
}
|
|
159
161
|
function renderDescriptionLine(description, depth) {
|
|
160
|
-
return description ? renderInline([
|
|
162
|
+
return description ? renderInline([secondary(description)], depth) : null;
|
|
161
163
|
}
|
|
162
164
|
function renderUsage(command) {
|
|
163
165
|
const args = command.subject?.type === "argument" ? DArray.map(command.subject.args, (argument) => argument.optional ? `[${argument.name}]` : `<${argument.name}>`) : command.subject?.type === "subCommand" ? ["<command>"] : [];
|
|
@@ -184,48 +186,39 @@ function renderOptionDetails(option, depth) {
|
|
|
184
186
|
if (simpleOptionKind.has(option) || arrayOptionKind.has(option)) {
|
|
185
187
|
const help = renderDataStructure(option.dataStructure);
|
|
186
188
|
return DArray.filter([
|
|
187
|
-
renderInline([
|
|
188
|
-
|
|
189
|
-
|
|
189
|
+
renderInline([renderMetadata(help, option.required ? "required" : "optional")], depth),
|
|
190
|
+
...renderConstraintLines(help.constraints, depth),
|
|
191
|
+
renderDescriptionLine(option.description, depth)
|
|
190
192
|
], DCommon.truthy);
|
|
191
193
|
}
|
|
192
|
-
if (booleanOptionKind.has(option)) return DArray.filter([renderInline([
|
|
194
|
+
if (booleanOptionKind.has(option)) return DArray.filter([renderInline([typeLabel("boolean")], depth), renderDescriptionLine(option.description, depth)], DCommon.truthy);
|
|
193
195
|
return DArray.filter([renderDescriptionLine(option.description, depth)], DCommon.truthy);
|
|
194
196
|
}
|
|
195
197
|
function renderOptionsHelp(options, depth) {
|
|
196
|
-
return DPrinter.renderParagraph([renderInline([
|
|
198
|
+
return DPrinter.renderParagraph([renderInline([section("OPTIONS", "magenta")], depth), DArray.map(options, (option) => DPrinter.renderParagraph([renderInline([renderOptionSignature(option)], depth + 1), renderOptionDetails(option, depth + 2)]))]);
|
|
197
199
|
}
|
|
198
200
|
function renderArgumentsHelp(args, depth) {
|
|
199
|
-
return DPrinter.renderParagraph([renderInline([
|
|
201
|
+
return DPrinter.renderParagraph([renderInline([section("ARGUMENTS", "cyan")], depth), DArray.map(args, (argument) => {
|
|
200
202
|
const help = renderDataStructure(argument.dataStructure);
|
|
201
203
|
return DPrinter.renderParagraph([
|
|
202
|
-
renderInline([
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
renderMetadata(help, argument.optional ? "optional" : "required")
|
|
206
|
-
]),
|
|
207
|
-
renderDescriptionLine(argument.description, depth + 2),
|
|
208
|
-
renderConstraintLines(help.constraints, depth + 2)
|
|
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)
|
|
209
207
|
]);
|
|
210
208
|
})]);
|
|
211
209
|
}
|
|
212
210
|
function renderSubCommandsHelp(commands, depth) {
|
|
213
|
-
return DPrinter.renderParagraph([renderInline([
|
|
214
|
-
DPrinter.indent(depth + 1),
|
|
215
|
-
name(command.name.padEnd(16)),
|
|
216
|
-
command.description ? secondary(command.description) : null
|
|
217
|
-
]))]);
|
|
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))]);
|
|
218
212
|
}
|
|
219
213
|
function renderCommandHelp(command, depth) {
|
|
220
214
|
return [...DArray.filter([
|
|
221
215
|
renderInline([
|
|
222
|
-
DPrinter.indent(depth),
|
|
223
216
|
section("COMMAND", "green"),
|
|
224
217
|
" ",
|
|
225
218
|
DPrinter.colorizedBold(command.name, "cyan")
|
|
226
|
-
]),
|
|
219
|
+
], depth),
|
|
227
220
|
renderDescriptionLine(command.description, depth + 1),
|
|
228
|
-
DPrinter.renderParagraph([renderInline([
|
|
221
|
+
DPrinter.renderParagraph([renderInline([section("USAGE", "blue")], depth), renderInline([syntax(renderUsage(command))], depth + 1)]),
|
|
229
222
|
command.subject?.type === "argument" ? renderArgumentsHelp(command.subject.args, depth) : null,
|
|
230
223
|
command.subject?.type === "subCommand" ? renderSubCommandsHelp(command.subject.subCommands, depth) : null,
|
|
231
224
|
DArray.minElements(command.options, 1) ? renderOptionsHelp(command.options, depth) : null
|
|
@@ -235,7 +228,7 @@ function logCommandHelp(command) {
|
|
|
235
228
|
console.log(DPrinter.renderParagraph(renderCommandHelp(command, 0)));
|
|
236
229
|
}
|
|
237
230
|
function renderExecOptionHelp(options, depth) {
|
|
238
|
-
return [renderInline([
|
|
231
|
+
return [renderInline([section("EXEC OPTIONS", "green")], depth), renderOptionsHelp(options, depth)];
|
|
239
232
|
}
|
|
240
233
|
function logExecOptionHelp(options) {
|
|
241
234
|
console.log(DPrinter.renderParagraph(renderExecOptionHelp(options, 0)));
|
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>;
|