@reliverse/rempts 1.7.65 → 2.2.7

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.
Files changed (131) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +1534 -1431
  3. package/cleanup.mjs +33 -0
  4. package/dist/cancel.d.ts +31 -0
  5. package/dist/cancel.js +28 -0
  6. package/dist/ffi.d.ts +1 -0
  7. package/dist/ffi.js +165 -0
  8. package/dist/group.d.ts +16 -0
  9. package/dist/group.js +22 -0
  10. package/dist/launcher/command.d.ts +8 -0
  11. package/dist/launcher/command.js +10 -0
  12. package/dist/launcher/discovery.d.ts +3 -0
  13. package/dist/launcher/discovery.js +207 -0
  14. package/dist/launcher/errors.d.ts +15 -0
  15. package/dist/launcher/errors.js +31 -0
  16. package/dist/launcher/help.d.ts +3 -0
  17. package/dist/launcher/help.js +145 -0
  18. package/dist/launcher/mod.d.ts +12 -0
  19. package/dist/launcher/mod.js +222 -0
  20. package/dist/launcher/parser.d.ts +14 -0
  21. package/dist/launcher/parser.js +255 -0
  22. package/dist/launcher/registry.d.ts +10 -0
  23. package/dist/launcher/registry.js +42 -0
  24. package/dist/launcher/types.d.ts +78 -0
  25. package/dist/launcher/validator.d.ts +3 -0
  26. package/dist/launcher/validator.js +39 -0
  27. package/dist/mod.d.ts +6 -0
  28. package/dist/mod.js +6 -0
  29. package/dist/prompt.d.ts +13 -0
  30. package/dist/prompt.js +53 -0
  31. package/dist/selection.d.ts +92 -0
  32. package/dist/selection.js +191 -0
  33. package/dist/spinner.d.ts +26 -0
  34. package/dist/spinner.js +141 -0
  35. package/dist/utils.d.ts +3 -0
  36. package/dist/utils.js +11 -0
  37. package/package.json +41 -47
  38. package/bin/libs/animate/animate-mod.ts.txt +0 -78
  39. package/bin/libs/anykey/anykey-mod.d.ts +0 -12
  40. package/bin/libs/anykey/anykey-mod.js +0 -125
  41. package/bin/libs/cancel/cancel.d.ts +0 -45
  42. package/bin/libs/cancel/cancel.js +0 -72
  43. package/bin/libs/confirm/confirm-alias.d.ts +0 -2
  44. package/bin/libs/confirm/confirm-alias.js +0 -2
  45. package/bin/libs/confirm/confirm-mod.d.ts +0 -5
  46. package/bin/libs/confirm/confirm-mod.js +0 -179
  47. package/bin/libs/date/date.d.ts +0 -2
  48. package/bin/libs/date/date.js +0 -254
  49. package/bin/libs/editor/editor-mod.d.ts +0 -25
  50. package/bin/libs/editor/editor-mod.js +0 -1133
  51. package/bin/libs/figures/figures-mod.d.ts +0 -461
  52. package/bin/libs/figures/figures-mod.js +0 -285
  53. package/bin/libs/group/group-mod.d.ts +0 -33
  54. package/bin/libs/group/group-mod.js +0 -89
  55. package/bin/libs/input/input-alias.d.ts +0 -5
  56. package/bin/libs/input/input-alias.js +0 -4
  57. package/bin/libs/input/input-mod.d.ts +0 -16
  58. package/bin/libs/input/input-mod.js +0 -370
  59. package/bin/libs/intro/intro-alias.d.ts +0 -3
  60. package/bin/libs/intro/intro-alias.js +0 -3
  61. package/bin/libs/intro/intro-mod.d.ts +0 -19
  62. package/bin/libs/intro/intro-mod.js +0 -71
  63. package/bin/libs/launcher/command-runner.d.ts +0 -31
  64. package/bin/libs/launcher/command-runner.js +0 -229
  65. package/bin/libs/launcher/launcher-alias.d.ts +0 -2
  66. package/bin/libs/launcher/launcher-alias.js +0 -2
  67. package/bin/libs/launcher/launcher-mod.d.ts +0 -66
  68. package/bin/libs/launcher/launcher-mod.js +0 -1037
  69. package/bin/libs/launcher/launcher-types.d.ts +0 -176
  70. package/bin/libs/launcher/launcher-types.js +0 -0
  71. package/bin/libs/log/log-alias.d.ts +0 -1
  72. package/bin/libs/log/log-alias.js +0 -2
  73. package/bin/libs/msg-fmt/colors.d.ts +0 -30
  74. package/bin/libs/msg-fmt/colors.js +0 -42
  75. package/bin/libs/msg-fmt/mapping.d.ts +0 -3
  76. package/bin/libs/msg-fmt/mapping.js +0 -41
  77. package/bin/libs/msg-fmt/messages.d.ts +0 -35
  78. package/bin/libs/msg-fmt/messages.js +0 -305
  79. package/bin/libs/msg-fmt/terminal.d.ts +0 -15
  80. package/bin/libs/msg-fmt/terminal.js +0 -60
  81. package/bin/libs/msg-fmt/variants.d.ts +0 -11
  82. package/bin/libs/msg-fmt/variants.js +0 -52
  83. package/bin/libs/multiselect/multiselect-alias.d.ts +0 -2
  84. package/bin/libs/multiselect/multiselect-alias.js +0 -2
  85. package/bin/libs/multiselect/multiselect-prompt.d.ts +0 -2
  86. package/bin/libs/multiselect/multiselect-prompt.js +0 -340
  87. package/bin/libs/next-steps/next-steps.d.ts +0 -13
  88. package/bin/libs/next-steps/next-steps.js +0 -24
  89. package/bin/libs/number/number-mod.d.ts +0 -28
  90. package/bin/libs/number/number-mod.js +0 -234
  91. package/bin/libs/outro/outro-alias.d.ts +0 -3
  92. package/bin/libs/outro/outro-alias.js +0 -3
  93. package/bin/libs/outro/outro-mod.d.ts +0 -7
  94. package/bin/libs/outro/outro-mod.js +0 -49
  95. package/bin/libs/reliarg/reliarg-mod.d.ts +0 -76
  96. package/bin/libs/reliarg/reliarg-mod.js +0 -276
  97. package/bin/libs/results/results.d.ts +0 -7
  98. package/bin/libs/results/results.js +0 -27
  99. package/bin/libs/select/nummultiselect-prompt.d.ts +0 -6
  100. package/bin/libs/select/nummultiselect-prompt.js +0 -141
  101. package/bin/libs/select/numselect-prompt.d.ts +0 -7
  102. package/bin/libs/select/numselect-prompt.js +0 -111
  103. package/bin/libs/select/select-alias.d.ts +0 -9
  104. package/bin/libs/select/select-alias.js +0 -9
  105. package/bin/libs/select/select-prompt.d.ts +0 -5
  106. package/bin/libs/select/select-prompt.js +0 -311
  107. package/bin/libs/select/toggle-prompt.d.ts +0 -5
  108. package/bin/libs/select/toggle-prompt.js +0 -207
  109. package/bin/libs/spinner/spinner-impl.d.ts +0 -70
  110. package/bin/libs/spinner/spinner-impl.js +0 -336
  111. package/bin/libs/spinner/spinner-mod.d.ts +0 -167
  112. package/bin/libs/spinner/spinner-mod.js +0 -447
  113. package/bin/libs/utils/colorize.d.ts +0 -2
  114. package/bin/libs/utils/colorize.js +0 -122
  115. package/bin/libs/utils/errors.d.ts +0 -1
  116. package/bin/libs/utils/errors.js +0 -17
  117. package/bin/libs/utils/prevent.d.ts +0 -8
  118. package/bin/libs/utils/prevent.js +0 -62
  119. package/bin/libs/utils/prompt-end.d.ts +0 -8
  120. package/bin/libs/utils/prompt-end.js +0 -36
  121. package/bin/libs/utils/stream-text.d.ts +0 -18
  122. package/bin/libs/utils/stream-text.js +0 -138
  123. package/bin/libs/utils/system.d.ts +0 -6
  124. package/bin/libs/utils/system.js +0 -7
  125. package/bin/libs/utils/validate.d.ts +0 -21
  126. package/bin/libs/utils/validate.js +0 -17
  127. package/bin/libs/visual/visual-mod.ts.txt +0 -19
  128. package/bin/mod.d.ts +0 -50
  129. package/bin/mod.js +0 -127
  130. package/bin/types.d.ts +0 -372
  131. /package/{bin → dist/launcher}/types.js +0 -0
@@ -1,229 +0,0 @@
1
- import process from "node:process";
2
- import { relinka, relinkaConfig } from "@reliverse/relinka";
3
- import { reliArgParser } from "../reliarg/reliarg-mod.js";
4
- export async function callCmd(command, input, options = {}) {
5
- const { autoExit = false, debug = false, useLifecycleHooks = true, parserOptions = {} } = options;
6
- const debugLog = (...args) => {
7
- if (debug) {
8
- void relinkaConfig().then(() => relinka("log", "[callCmd DEBUG]", ...args));
9
- }
10
- };
11
- debugLog("Calling command with input:", input);
12
- debugLog("Command meta:", command.meta);
13
- try {
14
- let ctx;
15
- if (Array.isArray(input)) {
16
- debugLog("Processing argv input:", input);
17
- ctx = await parseArgsFromArgv(command, input, parserOptions);
18
- } else {
19
- debugLog("Processing object input:", input);
20
- ctx = await createContextFromArgs(command, input);
21
- }
22
- debugLog("Created context:", ctx);
23
- if (useLifecycleHooks && command.onCmdInit) {
24
- debugLog("Calling onCmdInit hook");
25
- await command.onCmdInit(ctx);
26
- }
27
- if (command.run) {
28
- debugLog("Executing command run function");
29
- await command.run(ctx);
30
- } else {
31
- const error = "Command has no run function defined";
32
- debugLog(error);
33
- if (autoExit) {
34
- relinka("error", error);
35
- process.exit(1);
36
- }
37
- throw new Error(error);
38
- }
39
- if (useLifecycleHooks && command.onCmdExit) {
40
- debugLog("Calling onCmdExit hook");
41
- await command.onCmdExit(ctx);
42
- }
43
- debugLog("Command execution completed successfully");
44
- return ctx;
45
- } catch (error) {
46
- debugLog("Error during command execution:", error);
47
- if (autoExit) {
48
- relinka("error", `Error while executing command: ${String(error)}`);
49
- process.exit(1);
50
- }
51
- throw error;
52
- }
53
- }
54
- async function parseArgsFromArgv(command, argv, parserOptions) {
55
- const booleanKeys = Object.keys(command.args || {}).filter(
56
- (k) => command.args?.[k]?.type === "boolean"
57
- );
58
- const defaultMap = {};
59
- for (const [argKey, def] of Object.entries(command.args || {})) {
60
- if (def.type === "boolean") {
61
- defaultMap[argKey] = def.default !== void 0 ? def.default : false;
62
- } else if (def.default !== void 0) {
63
- defaultMap[argKey] = def.type === "array" && typeof def.default === "string" ? [def.default] : def.default;
64
- }
65
- }
66
- const mergedParserOptions = {
67
- ...parserOptions,
68
- boolean: [...parserOptions.boolean || [], ...booleanKeys],
69
- defaults: { ...defaultMap, ...parserOptions.defaults || {} }
70
- };
71
- const parsed = reliArgParser(argv, mergedParserOptions);
72
- const finalArgs = {};
73
- const positionalKeys = Object.keys(command.args || {}).filter(
74
- (k) => command.args?.[k]?.type === "positional"
75
- );
76
- const leftoverPositionals = [...parsed._ || []];
77
- for (let i = 0; i < positionalKeys.length; i++) {
78
- const key = positionalKeys[i];
79
- if (!key || !command.args) continue;
80
- const def = command.args[key];
81
- const val = leftoverPositionals[i];
82
- finalArgs[key] = val != null && def ? castArgValue(def, val, key) : def?.default;
83
- }
84
- const otherKeys = Object.keys(command.args || {}).filter(
85
- (k) => command.args?.[k]?.type !== "positional"
86
- );
87
- for (const key of otherKeys) {
88
- const def = command.args?.[key];
89
- if (!def) continue;
90
- let rawVal = parsed[key];
91
- if (def.type === "array" && rawVal !== void 0 && !Array.isArray(rawVal)) {
92
- rawVal = [rawVal];
93
- }
94
- const casted = rawVal !== void 0 ? castArgValue(def, rawVal, key) : def.default;
95
- const argUsed = rawVal !== void 0 && (def.type === "boolean" ? casted === true : true);
96
- if (casted == null && def.required) {
97
- throw new Error(`Missing required argument: --${key}`);
98
- }
99
- if (argUsed && def.dependencies?.length) {
100
- const missingDeps = def.dependencies.filter((d) => {
101
- const depVal = parsed[d] ?? defaultMap[d];
102
- return !depVal;
103
- });
104
- if (missingDeps.length > 0) {
105
- const depsList = missingDeps.map((d) => `--${d}`).join(", ");
106
- throw new Error(
107
- `Argument --${key} can only be used when ${depsList} ${missingDeps.length === 1 ? "is" : "are"} set`
108
- );
109
- }
110
- }
111
- finalArgs[key] = def.type === "boolean" ? Boolean(casted) : casted;
112
- }
113
- return {
114
- args: finalArgs,
115
- raw: argv
116
- };
117
- }
118
- async function createContextFromArgs(command, inputArgs) {
119
- const finalArgs = {};
120
- for (const [key, def] of Object.entries(command.args || {})) {
121
- const inputValue = inputArgs[key];
122
- let value;
123
- if (inputValue !== void 0) {
124
- value = castArgValue(def, inputValue, key);
125
- } else if (def.default !== void 0) {
126
- value = def.type === "array" && typeof def.default === "string" ? [def.default] : def.default;
127
- } else if (def.type === "boolean") {
128
- value = false;
129
- } else {
130
- value = void 0;
131
- }
132
- if (value == null && def.required) {
133
- throw new Error(`Missing required argument: ${key}`);
134
- }
135
- if (value != null && def.dependencies?.length) {
136
- const missingDeps = def.dependencies.filter((d) => {
137
- const depVal = inputArgs[d];
138
- return !depVal;
139
- });
140
- if (missingDeps.length > 0) {
141
- const depsList = missingDeps.join(", ");
142
- throw new Error(
143
- `Argument '${key}' can only be used when ${depsList} ${missingDeps.length === 1 ? "is" : "are"} provided`
144
- );
145
- }
146
- }
147
- finalArgs[key] = value;
148
- }
149
- return {
150
- args: finalArgs,
151
- raw: []
152
- // No raw argv for object input
153
- };
154
- }
155
- function castArgValue(def, rawVal, argName) {
156
- if (rawVal == null) {
157
- if (def.type === "array" && typeof def.default === "string") {
158
- return [def.default];
159
- }
160
- return def.default ?? void 0;
161
- }
162
- let castedValue;
163
- switch (def.type) {
164
- case "boolean":
165
- if (typeof rawVal === "string") {
166
- const lower = rawVal.toLowerCase();
167
- if (lower === "true") castedValue = true;
168
- else if (lower === "false") castedValue = false;
169
- else castedValue = Boolean(rawVal);
170
- } else {
171
- castedValue = Boolean(rawVal);
172
- }
173
- if (def.allowed && !def.allowed.includes(castedValue)) {
174
- throw new Error(
175
- `Invalid value for ${argName}: ${rawVal}. Allowed values are: ${def.allowed.join(", ")}`
176
- );
177
- }
178
- return castedValue;
179
- case "string":
180
- castedValue = typeof rawVal === "string" ? rawVal : String(rawVal);
181
- if (def.allowed && !def.allowed.includes(castedValue)) {
182
- throw new Error(
183
- `Invalid value for ${argName}: ${rawVal}. Allowed values are: ${def.allowed.join(", ")}`
184
- );
185
- }
186
- return castedValue;
187
- case "number": {
188
- const n = Number(rawVal);
189
- if (Number.isNaN(n)) {
190
- throw new Error(`Invalid number provided for ${argName}: ${rawVal}`);
191
- }
192
- if (def.allowed && !def.allowed.includes(n)) {
193
- throw new Error(
194
- `Invalid value for ${argName}: ${rawVal}. Allowed values are: ${def.allowed.join(", ")}`
195
- );
196
- }
197
- return n;
198
- }
199
- case "positional":
200
- castedValue = String(rawVal);
201
- if (def.allowed && !def.allowed.includes(castedValue)) {
202
- throw new Error(
203
- `Invalid value for ${argName}: ${rawVal}. Allowed values are: ${def.allowed.join(", ")}`
204
- );
205
- }
206
- return castedValue;
207
- case "array": {
208
- const arrVal = Array.isArray(rawVal) ? rawVal : [String(rawVal)];
209
- const result = [];
210
- for (let v of arrVal.map(String)) {
211
- if (v.startsWith("[") && v.endsWith("]")) {
212
- v = v.slice(1, -1);
213
- }
214
- const parts = v.split(/\s*,\s*/).filter(Boolean);
215
- for (const p of parts) {
216
- if (def.allowed && !def.allowed.includes(p)) {
217
- throw new Error(
218
- `Invalid value in array ${argName}: ${p}. Allowed values are: ${def.allowed.join(", ")}`
219
- );
220
- }
221
- }
222
- result.push(...parts);
223
- }
224
- return result;
225
- }
226
- default:
227
- return rawVal;
228
- }
229
- }
@@ -1,2 +0,0 @@
1
- import { createCli } from "./launcher-mod";
2
- export declare const runMain: typeof createCli;
@@ -1,2 +0,0 @@
1
- import { createCli } from "./launcher-mod.js";
2
- export const runMain = createCli;
@@ -1,66 +0,0 @@
1
- import type { ReliArgParserOptions } from "../reliarg/reliarg-mod";
2
- import type { ArgDefinitions, Command, DefineCommandOptions, EmptyArgs, FileBasedOptions } from "./launcher-types";
3
- /**
4
- * Defines a command with metadata, argument definitions,
5
- * an execution function, and (optional) subCommands.
6
- */
7
- export declare function defineCommand<A extends ArgDefinitions = EmptyArgs>(options: DefineCommandOptions<A>): Command<A>;
8
- /**
9
- * Show usage for a given command.
10
- */
11
- export declare function showUsage<A extends ArgDefinitions>(command: Command<A>, parserOptions?: ReliArgParserOptions & {
12
- fileBased?: FileBasedOptions;
13
- autoExit?: boolean;
14
- metaSettings?: {
15
- showDescriptionOnMain?: boolean;
16
- };
17
- _fileBasedCurrentDir?: string;
18
- _fileBasedPathSegments?: string[];
19
- _isSubcommand?: boolean;
20
- }, globalCliMeta?: {
21
- name?: string;
22
- version?: string;
23
- description?: string;
24
- }): Promise<void>;
25
- /**
26
- * Primary entry point to run a command. This function supports:
27
- *
28
- * - File-based Commands: scanning for commands within a given commands root.
29
- * - Commands defined within the command object.
30
- * - Standard flags like --help, --version, and --debug.
31
- *
32
- * This function passes along remaining arguments to command runners to ensure
33
- * consistent parsing.
34
- */
35
- export declare function createCli<A extends ArgDefinitions = EmptyArgs>(options: Command<A> | {
36
- name?: string;
37
- version?: string;
38
- description?: string;
39
- mainCommand?: Command<A>;
40
- fileBased?: FileBasedOptions;
41
- autoExit?: boolean;
42
- metaSettings?: {
43
- showDescriptionOnMain?: boolean;
44
- };
45
- meta?: Command<A>["meta"];
46
- args?: Command<A>["args"];
47
- run?: Command<A>["run"];
48
- commands?: Command<A>["commands"];
49
- onCmdInit?: Command<A>["onCmdInit"];
50
- onCmdExit?: Command<A>["onCmdExit"];
51
- onLauncherInit?: Command<A>["onLauncherInit"];
52
- onLauncherExit?: Command<A>["onLauncherExit"];
53
- }, legacyParserOptions?: ReliArgParserOptions & {
54
- fileBased?: FileBasedOptions;
55
- autoExit?: boolean;
56
- metaSettings?: {
57
- showDescriptionOnMain?: boolean;
58
- };
59
- }): Promise<void> & {
60
- run(_ctx?: any): Promise<void>;
61
- };
62
- /**
63
- * Helper to define argument definitions with improved type inference
64
- * for IntelliSense and validation for array defaults against options.
65
- */
66
- export declare function defineArgs<A extends ArgDefinitions>(args: A): A;