@nmakarov/cli-toolkit 0.14.2 → 0.16.0
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/args.cjs +49 -9
- package/dist/args.cjs.map +1 -1
- package/dist/args.js +49 -9
- package/dist/args.js.map +1 -1
- package/dist/db.cjs +9 -2
- package/dist/db.cjs.map +1 -1
- package/dist/db.js +9 -2
- package/dist/db.js.map +1 -1
- package/dist/errors.cjs +17 -0
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.js +15 -0
- package/dist/errors.js.map +1 -1
- package/dist/filedatabase.cjs +16 -24
- package/dist/filedatabase.cjs.map +1 -1
- package/dist/filedatabase.js +16 -23
- package/dist/filedatabase.js.map +1 -1
- package/dist/http-client.cjs +44 -34
- package/dist/http-client.cjs.map +1 -1
- package/dist/http-client.js +44 -34
- package/dist/http-client.js.map +1 -1
- package/dist/http-client2.cjs +368 -0
- package/dist/http-client2.cjs.map +1 -0
- package/dist/http-client2.js +340 -0
- package/dist/http-client2.js.map +1 -0
- package/dist/index.cjs +212 -91
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +212 -90
- package/dist/index.js.map +1 -1
- package/dist/init.cjs +190 -76
- package/dist/init.cjs.map +1 -1
- package/dist/init.js +190 -76
- package/dist/init.js.map +1 -1
- package/dist/logger.cjs +19 -36
- package/dist/logger.cjs.map +1 -1
- package/dist/logger.js +19 -36
- package/dist/logger.js.map +1 -1
- package/dist/mock-server.cjs +13 -16
- package/dist/mock-server.cjs.map +1 -1
- package/dist/mock-server.js +13 -16
- package/dist/mock-server.js.map +1 -1
- package/dist/params.cjs +114 -15
- package/dist/params.cjs.map +1 -1
- package/dist/params.js +114 -15
- package/dist/params.js.map +1 -1
- package/package.json +9 -2
package/dist/init.js
CHANGED
|
@@ -1117,20 +1117,31 @@ var Args = class _Args {
|
|
|
1117
1117
|
configValues = {};
|
|
1118
1118
|
configsLoaded = [];
|
|
1119
1119
|
env = "local";
|
|
1120
|
-
constructor(
|
|
1120
|
+
constructor(contextOrConfig = {}, config2) {
|
|
1121
|
+
const hasContext = config2 !== void 0;
|
|
1122
|
+
const configToUse = hasContext ? config2 ?? {} : contextOrConfig ?? {};
|
|
1123
|
+
const context = hasContext ? contextOrConfig : void 0;
|
|
1121
1124
|
this.aliases = {};
|
|
1122
1125
|
this.overrides = {};
|
|
1123
1126
|
this.defaults = {};
|
|
1124
1127
|
this.prefixes = ["not", "no"];
|
|
1125
|
-
if (Object.keys(
|
|
1126
|
-
this.configure(
|
|
1128
|
+
if (Object.keys(configToUse).length > 0) {
|
|
1129
|
+
this.configure(configToUse);
|
|
1127
1130
|
}
|
|
1128
|
-
const args =
|
|
1131
|
+
const args = configToUse.args || process.argv.slice(2);
|
|
1129
1132
|
this.parseArgs(args);
|
|
1130
1133
|
this.env = this.get("env")?.toLowerCase() || "local";
|
|
1131
1134
|
this.loadDotEnv();
|
|
1132
1135
|
this.loadConfigFiles();
|
|
1133
1136
|
this.checkConflicts();
|
|
1137
|
+
if (context && typeof context.registerCleanup === "function") {
|
|
1138
|
+
context.registerCleanup((ctx) => {
|
|
1139
|
+
const unusedArgs = ctx.args.getUnused();
|
|
1140
|
+
if (unusedArgs.length > 0) {
|
|
1141
|
+
ctx.logger.warn("Unused CLI args:", unusedArgs.join(", "));
|
|
1142
|
+
}
|
|
1143
|
+
});
|
|
1144
|
+
}
|
|
1134
1145
|
}
|
|
1135
1146
|
/**
|
|
1136
1147
|
* Configure Args options
|
|
@@ -1152,12 +1163,15 @@ var Args = class _Args {
|
|
|
1152
1163
|
}
|
|
1153
1164
|
}
|
|
1154
1165
|
/**
|
|
1155
|
-
* Initialize Args instance
|
|
1156
|
-
*
|
|
1157
|
-
*
|
|
1166
|
+
* Initialize Args instance.
|
|
1167
|
+
* Args.init(context, config) when used from init/setup: context has registerCleanup, Args registers unused-args cleanup.
|
|
1168
|
+
* Args.init(config) for standalone use (no cleanup).
|
|
1158
1169
|
*/
|
|
1159
|
-
static init(config2
|
|
1160
|
-
|
|
1170
|
+
static init(contextOrConfig, config2) {
|
|
1171
|
+
if (config2 !== void 0) {
|
|
1172
|
+
return new _Args(contextOrConfig, config2);
|
|
1173
|
+
}
|
|
1174
|
+
return new _Args(contextOrConfig ?? {});
|
|
1161
1175
|
}
|
|
1162
1176
|
/**
|
|
1163
1177
|
* Parse command line arguments
|
|
@@ -1337,6 +1351,32 @@ var Args = class _Args {
|
|
|
1337
1351
|
}
|
|
1338
1352
|
return void 0;
|
|
1339
1353
|
}
|
|
1354
|
+
/**
|
|
1355
|
+
* Return which layer provided the value for get(key): overrides, cli, config, env, or default.
|
|
1356
|
+
* Does not add key to usedKeys. Use after get(key) when you need the origin.
|
|
1357
|
+
*/
|
|
1358
|
+
getSource(key) {
|
|
1359
|
+
const resolvedKey = this.aliases[key] || key;
|
|
1360
|
+
const lcKey = resolvedKey.toLowerCase();
|
|
1361
|
+
const overrideKey = Object.keys(this.overrides).find((k) => k.toLowerCase() === lcKey);
|
|
1362
|
+
if (overrideKey !== void 0) return "overrides";
|
|
1363
|
+
const lcKeyWithEnv = `${lcKey}${this.env ? `_${this.env.toLowerCase()}` : ""}`;
|
|
1364
|
+
if (this.env && this.args[lcKeyWithEnv] !== void 0) return "cli";
|
|
1365
|
+
if (this.args[lcKey] !== void 0) return "cli";
|
|
1366
|
+
const configKey = Object.keys(this.configValues).find((k) => k.toLowerCase() === lcKey);
|
|
1367
|
+
if (configKey !== void 0) return "config";
|
|
1368
|
+
const envKey = this.toEnvKey(resolvedKey);
|
|
1369
|
+
const envKeyWithEnv = `${envKey}${this.env ? `_${this.env.toUpperCase()}` : ""}`;
|
|
1370
|
+
const envSpecificKey = Object.keys(process.env).find((k) => this.env && k.toUpperCase() === envKeyWithEnv);
|
|
1371
|
+
const envKeyFound = Object.keys(process.env).find((k) => k.toUpperCase() === envKey);
|
|
1372
|
+
const envKeyAlt = envKey.replace(/_([0-9])/g, "$1");
|
|
1373
|
+
const envKeyAltFound = !envKeyFound ? Object.keys(process.env).find((k) => k.toUpperCase() === envKeyAlt) : null;
|
|
1374
|
+
if (envSpecificKey || envKeyFound || envKeyAltFound) return "env";
|
|
1375
|
+
const defaultKey = Object.keys(this.defaults).find((k) => k.toLowerCase() === lcKey);
|
|
1376
|
+
if (defaultKey !== void 0) return "default";
|
|
1377
|
+
if (lcKey === "env" && process.env.NODE_ENV !== void 0) return "env";
|
|
1378
|
+
return void 0;
|
|
1379
|
+
}
|
|
1340
1380
|
/**
|
|
1341
1381
|
* Set a value (for testing/internal use)
|
|
1342
1382
|
*/
|
|
@@ -1689,17 +1729,53 @@ var Params = class _Params {
|
|
|
1689
1729
|
context;
|
|
1690
1730
|
// Partial context during initialization
|
|
1691
1731
|
params = {};
|
|
1732
|
+
paramSources = {};
|
|
1692
1733
|
definitions = {};
|
|
1693
1734
|
args;
|
|
1694
1735
|
paramSetters = [];
|
|
1695
1736
|
paramGetters = [];
|
|
1696
1737
|
trackedParams = [];
|
|
1738
|
+
_currentModule = "script";
|
|
1739
|
+
/** Resolved early in constructor so cleanup does not read params lazily */
|
|
1740
|
+
_showUsedParams = false;
|
|
1697
1741
|
constructor(context, options = {}) {
|
|
1698
1742
|
this.context = context;
|
|
1699
1743
|
this.args = context.args;
|
|
1700
1744
|
if (Object.keys(options).length > 0) {
|
|
1701
1745
|
this.configure(options);
|
|
1702
1746
|
}
|
|
1747
|
+
this._showUsedParams = this.get("showUsedParams", "boolean default false");
|
|
1748
|
+
if (context && typeof context.registerCleanup === "function") {
|
|
1749
|
+
context.registerCleanup((ctx) => {
|
|
1750
|
+
if (!ctx.params.getShowUsedParams()) return;
|
|
1751
|
+
const byModule = ctx.params.getFiguredByModule();
|
|
1752
|
+
const modules = Object.keys(byModule).sort();
|
|
1753
|
+
if (modules.length === 0) return;
|
|
1754
|
+
const logger = ctx.logger;
|
|
1755
|
+
logger.debug("[Params]: list of used params:");
|
|
1756
|
+
if (typeof logger.highlight !== "function") {
|
|
1757
|
+
for (const mod of modules) {
|
|
1758
|
+
logger.debug(` [${mod}]`);
|
|
1759
|
+
for (const [key, entry] of Object.entries(byModule[mod])) {
|
|
1760
|
+
logger.debug(` ${key}: ${JSON.stringify(entry.value)} (${entry.source})`);
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
return;
|
|
1764
|
+
}
|
|
1765
|
+
for (const mod of modules) {
|
|
1766
|
+
logger.debug(` [${mod}]`);
|
|
1767
|
+
for (const [key, entry] of Object.entries(byModule[mod])) {
|
|
1768
|
+
const valueStr = JSON.stringify(entry.value);
|
|
1769
|
+
const display = entry.source === "default" ? valueStr : logger.highlight(valueStr);
|
|
1770
|
+
logger.debug(` ${key}: ${display} (${entry.source})`);
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
});
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
/** Whether --showUsedParams was requested (resolved in constructor). */
|
|
1777
|
+
getShowUsedParams() {
|
|
1778
|
+
return this._showUsedParams;
|
|
1703
1779
|
}
|
|
1704
1780
|
/**
|
|
1705
1781
|
* Configure parameters
|
|
@@ -1718,14 +1794,15 @@ var Params = class _Params {
|
|
|
1718
1794
|
return new _Params(context, options || {});
|
|
1719
1795
|
}
|
|
1720
1796
|
/**
|
|
1721
|
-
* Track a parameter request for --stopAfter=init
|
|
1797
|
+
* Track a parameter request for --stopAfter=init and --showUsedParams
|
|
1722
1798
|
*/
|
|
1723
|
-
trackParam(key, definition, value, source) {
|
|
1799
|
+
trackParam(key, definition, value, source, moduleName) {
|
|
1724
1800
|
this.trackedParams.push({
|
|
1725
1801
|
key,
|
|
1726
1802
|
definition,
|
|
1727
1803
|
value,
|
|
1728
|
-
source
|
|
1804
|
+
source,
|
|
1805
|
+
module: moduleName ?? this._currentModule
|
|
1729
1806
|
});
|
|
1730
1807
|
}
|
|
1731
1808
|
/**
|
|
@@ -1735,7 +1812,7 @@ var Params = class _Params {
|
|
|
1735
1812
|
return [...this.trackedParams];
|
|
1736
1813
|
}
|
|
1737
1814
|
/**
|
|
1738
|
-
* Get all figured parameters as a record
|
|
1815
|
+
* Get all figured parameters as a record (flat, last occurrence per key)
|
|
1739
1816
|
* Returns all parameters that were collected during initialization,
|
|
1740
1817
|
* whether from CLI args, options, or defaults
|
|
1741
1818
|
*/
|
|
@@ -1749,6 +1826,19 @@ var Params = class _Params {
|
|
|
1749
1826
|
}
|
|
1750
1827
|
return result;
|
|
1751
1828
|
}
|
|
1829
|
+
/**
|
|
1830
|
+
* Get figured parameters grouped by module name.
|
|
1831
|
+
* Same param can appear in multiple modules (e.g. source, resource).
|
|
1832
|
+
*/
|
|
1833
|
+
getFiguredByModule() {
|
|
1834
|
+
const byModule = {};
|
|
1835
|
+
for (const param of this.trackedParams) {
|
|
1836
|
+
const mod = param.module;
|
|
1837
|
+
if (!byModule[mod]) byModule[mod] = {};
|
|
1838
|
+
byModule[mod][param.key] = { value: param.value, source: param.source };
|
|
1839
|
+
}
|
|
1840
|
+
return byModule;
|
|
1841
|
+
}
|
|
1752
1842
|
/**
|
|
1753
1843
|
* Clear tracked parameters
|
|
1754
1844
|
*/
|
|
@@ -1867,14 +1957,19 @@ var Params = class _Params {
|
|
|
1867
1957
|
source = "options";
|
|
1868
1958
|
} else if (valFromArgs !== void 0 && valFromArgs !== null) {
|
|
1869
1959
|
value = this.validate(key, valFromArgs, def);
|
|
1870
|
-
|
|
1960
|
+
const argsSource = this.args.getSource?.(key);
|
|
1961
|
+
if (argsSource === "overrides") source = "options";
|
|
1962
|
+
else if (argsSource === "cli" || argsSource === "env" || argsSource === "config") source = argsSource;
|
|
1963
|
+
else if (argsSource === "default") source = "default";
|
|
1964
|
+
else source = "cli";
|
|
1871
1965
|
} else if (valFromParams !== void 0 && valFromParams !== null) {
|
|
1872
1966
|
value = this.validate(key, valFromParams, def);
|
|
1873
|
-
source = "options";
|
|
1967
|
+
source = this.paramSources[key] ?? "options";
|
|
1874
1968
|
} else {
|
|
1875
1969
|
value = this.validate(key, void 0, def);
|
|
1876
1970
|
source = "default";
|
|
1877
1971
|
}
|
|
1972
|
+
this.paramSources[key] = source;
|
|
1878
1973
|
this.trackParam(key, definition || "string", value, source);
|
|
1879
1974
|
if (value !== void 0 && def.values && !def.values.includes(value)) {
|
|
1880
1975
|
throw new ParamError(`key ${key} should be one of ${def.values}`);
|
|
@@ -1895,19 +1990,63 @@ var Params = class _Params {
|
|
|
1895
1990
|
}
|
|
1896
1991
|
}
|
|
1897
1992
|
/**
|
|
1898
|
-
* Get all parameters from definitions
|
|
1899
|
-
* Processes
|
|
1993
|
+
* Get all parameters from definitions (main script).
|
|
1994
|
+
* Same as getAllForModule("script", defs). Processes left-to-right for cross-parameter references.
|
|
1900
1995
|
*/
|
|
1901
1996
|
getAll(defs) {
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1997
|
+
return this.getAllForModule("script", defs);
|
|
1998
|
+
}
|
|
1999
|
+
/**
|
|
2000
|
+
* Get all parameters from definitions for a given module name.
|
|
2001
|
+
* Figured params are grouped by module when using --showUsedParams.
|
|
2002
|
+
* Processes parameters left-to-right to support cross-parameter references.
|
|
2003
|
+
* If moduleName is omitted, it is inferred from the caller's file path (directory name under src/).
|
|
2004
|
+
*/
|
|
2005
|
+
getAllForModule(moduleNameOrDefs, defs) {
|
|
2006
|
+
let moduleName;
|
|
2007
|
+
let definitions;
|
|
2008
|
+
if (defs !== void 0) {
|
|
2009
|
+
moduleName = moduleNameOrDefs;
|
|
2010
|
+
definitions = defs;
|
|
2011
|
+
} else {
|
|
2012
|
+
definitions = moduleNameOrDefs;
|
|
2013
|
+
moduleName = this._inferModuleNameFromStack();
|
|
2014
|
+
}
|
|
2015
|
+
const prev = this._currentModule;
|
|
2016
|
+
this._currentModule = moduleName;
|
|
2017
|
+
try {
|
|
2018
|
+
const res = {};
|
|
2019
|
+
for (const [k, def] of Object.entries(definitions)) {
|
|
2020
|
+
const value = this.get(k, def);
|
|
2021
|
+
res[k] = value;
|
|
2022
|
+
if (value !== void 0) {
|
|
2023
|
+
this.params[k] = value;
|
|
2024
|
+
}
|
|
1908
2025
|
}
|
|
2026
|
+
return res;
|
|
2027
|
+
} finally {
|
|
2028
|
+
this._currentModule = prev;
|
|
1909
2029
|
}
|
|
1910
|
-
|
|
2030
|
+
}
|
|
2031
|
+
/**
|
|
2032
|
+
* Infer module name from call stack: first caller outside params/index gives path like .../src/<moduleName>/...
|
|
2033
|
+
*/
|
|
2034
|
+
_inferModuleNameFromStack() {
|
|
2035
|
+
const stack = new Error().stack;
|
|
2036
|
+
if (!stack) return "script";
|
|
2037
|
+
const lines = stack.split("\n");
|
|
2038
|
+
const paramsIndexPath = "params" + (typeof process !== "undefined" && process.platform === "win32" ? "\\" : "/") + "index.";
|
|
2039
|
+
for (const line of lines) {
|
|
2040
|
+
const parenMatch = line.match(/\(([^)]+)\)/);
|
|
2041
|
+
if (!parenMatch) continue;
|
|
2042
|
+
const parts = parenMatch[1].split(":");
|
|
2043
|
+
if (parts.length < 3) continue;
|
|
2044
|
+
const path = parts.slice(0, -2).join(":").replace(/^file:\/\//, "");
|
|
2045
|
+
if (!path || path.includes(paramsIndexPath)) continue;
|
|
2046
|
+
const srcMatch = path.match(/[/\\]src[/\\]([^/\\]+)(?:[/\\]|$)/);
|
|
2047
|
+
if (srcMatch) return srcMatch[1];
|
|
2048
|
+
}
|
|
2049
|
+
return "script";
|
|
1911
2050
|
}
|
|
1912
2051
|
/**
|
|
1913
2052
|
* Run all registered getters for a key
|
|
@@ -2017,8 +2156,7 @@ var Logger = class _Logger {
|
|
|
2017
2156
|
this.updateTransport();
|
|
2018
2157
|
}
|
|
2019
2158
|
/**
|
|
2020
|
-
* Configure logger options
|
|
2021
|
-
* Only parameters present in options are updated
|
|
2159
|
+
* Configure logger options. Accepts both LoggerOptions shape and flat param names (levels string, progressWithTimes, progressThrottleMs).
|
|
2022
2160
|
*/
|
|
2023
2161
|
configure(options) {
|
|
2024
2162
|
if (options.mode !== void 0) {
|
|
@@ -2028,32 +2166,24 @@ var Logger = class _Logger {
|
|
|
2028
2166
|
this.options.route = options.route;
|
|
2029
2167
|
this.updateTransport();
|
|
2030
2168
|
}
|
|
2031
|
-
if (options.prefix !== void 0)
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
if (options.
|
|
2035
|
-
this.options.silent = options.silent;
|
|
2036
|
-
}
|
|
2037
|
-
if (options.showLevel !== void 0) {
|
|
2038
|
-
this.options.showLevel = options.showLevel;
|
|
2039
|
-
}
|
|
2040
|
-
if (options.timestamp !== void 0) {
|
|
2041
|
-
this.options.timestamp = options.timestamp;
|
|
2042
|
-
}
|
|
2169
|
+
if (options.prefix !== void 0) this.options.prefix = options.prefix;
|
|
2170
|
+
if (options.silent !== void 0) this.options.silent = options.silent;
|
|
2171
|
+
if (options.showLevel !== void 0) this.options.showLevel = options.showLevel;
|
|
2172
|
+
if (options.timestamp !== void 0) this.options.timestamp = options.timestamp;
|
|
2043
2173
|
if (options.levels !== void 0) {
|
|
2044
|
-
|
|
2174
|
+
const levels = typeof options.levels === "string" ? options.levels.split(",") : options.levels;
|
|
2175
|
+
this.options.levels = this.normalizeLevels(levels);
|
|
2045
2176
|
}
|
|
2046
2177
|
if (options.progress !== void 0) {
|
|
2047
|
-
if (options.progress.withTimes !== void 0)
|
|
2048
|
-
|
|
2049
|
-
}
|
|
2050
|
-
if (options.progress.throttleMs !== void 0) {
|
|
2051
|
-
this.options.progressThrottle = options.progress.throttleMs;
|
|
2052
|
-
}
|
|
2178
|
+
if (options.progress.withTimes !== void 0) this.options.progressTimes = options.progress.withTimes;
|
|
2179
|
+
if (options.progress.throttleMs !== void 0) this.options.progressThrottle = options.progress.throttleMs;
|
|
2053
2180
|
}
|
|
2181
|
+
const flat = options;
|
|
2182
|
+
if (flat.progressWithTimes !== void 0) this.options.progressTimes = flat.progressWithTimes;
|
|
2183
|
+
if (flat.progressThrottleMs !== void 0) this.options.progressThrottle = flat.progressThrottleMs;
|
|
2054
2184
|
}
|
|
2055
2185
|
/**
|
|
2056
|
-
* Initialize logger from context and CLI parameters
|
|
2186
|
+
* Initialize logger from context and CLI parameters. Whatever is in options goes (after discovered params).
|
|
2057
2187
|
*/
|
|
2058
2188
|
static init(context, options) {
|
|
2059
2189
|
const paramDefs = {
|
|
@@ -2067,20 +2197,8 @@ var Logger = class _Logger {
|
|
|
2067
2197
|
progressWithTimes: "boolean default false",
|
|
2068
2198
|
progressThrottleMs: "number"
|
|
2069
2199
|
};
|
|
2070
|
-
const
|
|
2071
|
-
const config2 = {
|
|
2072
|
-
mode: options?.mode ?? cliParams.mode,
|
|
2073
|
-
route: options?.route ?? cliParams.route,
|
|
2074
|
-
prefix: options?.prefix ?? cliParams.prefix,
|
|
2075
|
-
silent: options?.silent ?? cliParams.silent,
|
|
2076
|
-
showLevel: options?.showLevel ?? cliParams.showLevel,
|
|
2077
|
-
timestamp: options?.timestamp ?? cliParams.timestamp,
|
|
2078
|
-
levels: options?.levels ?? (cliParams.levels ? cliParams.levels.split(",") : void 0),
|
|
2079
|
-
progress: options?.progress ?? {
|
|
2080
|
-
withTimes: cliParams.progressWithTimes,
|
|
2081
|
-
throttleMs: cliParams.progressThrottleMs
|
|
2082
|
-
}
|
|
2083
|
-
};
|
|
2200
|
+
const discovered = context.params.getAllForModule(paramDefs);
|
|
2201
|
+
const config2 = { ...discovered, ...options };
|
|
2084
2202
|
const logger = new _Logger(context, config2);
|
|
2085
2203
|
context.logger = logger;
|
|
2086
2204
|
return logger;
|
|
@@ -2107,6 +2225,10 @@ var Logger = class _Logger {
|
|
|
2107
2225
|
}
|
|
2108
2226
|
this.options.mode = mode;
|
|
2109
2227
|
}
|
|
2228
|
+
/** Returns a styled string (bright white) for highlighting; keeps chalk inside logger. */
|
|
2229
|
+
highlight(text) {
|
|
2230
|
+
return chalk.whiteBright(text);
|
|
2231
|
+
}
|
|
2110
2232
|
debug(message, ...chunks) {
|
|
2111
2233
|
this.out({ level: "debug", message, chunks });
|
|
2112
2234
|
}
|
|
@@ -2282,12 +2404,7 @@ function extractComponentOptions(opts, componentName) {
|
|
|
2282
2404
|
return componentOptions;
|
|
2283
2405
|
}
|
|
2284
2406
|
function setup(opts = {}) {
|
|
2285
|
-
const args = Args.init({
|
|
2286
|
-
overrides: opts.overrides || {},
|
|
2287
|
-
defaults: opts.defaults || {}
|
|
2288
|
-
});
|
|
2289
2407
|
const partialContext = {
|
|
2290
|
-
args,
|
|
2291
2408
|
emitter: new EventEmitter(),
|
|
2292
2409
|
isStop: () => false,
|
|
2293
2410
|
cleanupFunctions: [],
|
|
@@ -2295,6 +2412,11 @@ function setup(opts = {}) {
|
|
|
2295
2412
|
partialContext.cleanupFunctions.push(fn);
|
|
2296
2413
|
}
|
|
2297
2414
|
};
|
|
2415
|
+
const args = Args.init(partialContext, {
|
|
2416
|
+
overrides: opts.overrides || {},
|
|
2417
|
+
defaults: opts.defaults || {}
|
|
2418
|
+
});
|
|
2419
|
+
partialContext.args = args;
|
|
2298
2420
|
const params = Params.init(partialContext, opts.overrides || {});
|
|
2299
2421
|
partialContext.params = params;
|
|
2300
2422
|
const loggerOptions = extractComponentOptions(opts, "logger");
|
|
@@ -2355,6 +2477,7 @@ async function init(flow, opts = {}) {
|
|
|
2355
2477
|
context.isStop = () => stop;
|
|
2356
2478
|
context = await setupModules(context, opts);
|
|
2357
2479
|
const stopAfter = context.args.get("stopAfter");
|
|
2480
|
+
const stopAllowance = context.params.get("stopAllowance", "number default 5");
|
|
2358
2481
|
if (stopAfter === "init") {
|
|
2359
2482
|
printAllParameters(context);
|
|
2360
2483
|
process.exit(0);
|
|
@@ -2365,13 +2488,8 @@ async function init(flow, opts = {}) {
|
|
|
2365
2488
|
process.exit(2);
|
|
2366
2489
|
}
|
|
2367
2490
|
stop = true;
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
allowance = context.params.get("stopAllowance", "number default 5");
|
|
2371
|
-
} catch {
|
|
2372
|
-
}
|
|
2373
|
-
context.logger.info(`>> emitting stop with allowance ${allowance}`);
|
|
2374
|
-
context.emitter.emit("stop", allowance);
|
|
2491
|
+
context.logger.info(`>> emitting stop with allowance ${stopAllowance}`);
|
|
2492
|
+
context.emitter.emit("stop", stopAllowance);
|
|
2375
2493
|
});
|
|
2376
2494
|
await flow(context);
|
|
2377
2495
|
} catch (error) {
|
|
@@ -2402,10 +2520,6 @@ async function init(flow, opts = {}) {
|
|
|
2402
2520
|
context.logger.warn("[cleanup] error in cleanup function:", error);
|
|
2403
2521
|
}
|
|
2404
2522
|
}
|
|
2405
|
-
const unusedArgs = context.args.getUnused();
|
|
2406
|
-
if (unusedArgs.length > 0) {
|
|
2407
|
-
context.logger.warn("Unused CLI args:", unusedArgs.join(", "));
|
|
2408
|
-
}
|
|
2409
2523
|
}
|
|
2410
2524
|
}
|
|
2411
2525
|
}
|