@nmakarov/cli-toolkit 0.14.2 → 0.18.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.
Files changed (57) hide show
  1. package/dist/args.cjs +49 -9
  2. package/dist/args.cjs.map +1 -1
  3. package/dist/args.js +49 -9
  4. package/dist/args.js.map +1 -1
  5. package/dist/cli-runner.cjs +5006 -0
  6. package/dist/cli-runner.cjs.map +1 -0
  7. package/dist/cli-runner.js +4989 -0
  8. package/dist/cli-runner.js.map +1 -0
  9. package/dist/db.cjs +9 -2
  10. package/dist/db.cjs.map +1 -1
  11. package/dist/db.js +9 -2
  12. package/dist/db.js.map +1 -1
  13. package/dist/errors.cjs +17 -0
  14. package/dist/errors.cjs.map +1 -1
  15. package/dist/errors.js +15 -0
  16. package/dist/errors.js.map +1 -1
  17. package/dist/filedatabase.cjs +110 -37
  18. package/dist/filedatabase.cjs.map +1 -1
  19. package/dist/filedatabase.js +110 -36
  20. package/dist/filedatabase.js.map +1 -1
  21. package/dist/http-client.cjs +44 -34
  22. package/dist/http-client.cjs.map +1 -1
  23. package/dist/http-client.js +44 -34
  24. package/dist/http-client.js.map +1 -1
  25. package/dist/http-client2.cjs +1728 -0
  26. package/dist/http-client2.cjs.map +1 -0
  27. package/dist/http-client2.js +1690 -0
  28. package/dist/http-client2.js.map +1 -0
  29. package/dist/index.cjs +1456 -112
  30. package/dist/index.cjs.map +1 -1
  31. package/dist/index.js +1436 -110
  32. package/dist/index.js.map +1 -1
  33. package/dist/init.cjs +199 -82
  34. package/dist/init.cjs.map +1 -1
  35. package/dist/init.js +199 -82
  36. package/dist/init.js.map +1 -1
  37. package/dist/logger.cjs +28 -42
  38. package/dist/logger.cjs.map +1 -1
  39. package/dist/logger.js +28 -42
  40. package/dist/logger.js.map +1 -1
  41. package/dist/mock-server.cjs +205 -359
  42. package/dist/mock-server.cjs.map +1 -1
  43. package/dist/mock-server.js +203 -359
  44. package/dist/mock-server.js.map +1 -1
  45. package/dist/params.cjs +114 -15
  46. package/dist/params.cjs.map +1 -1
  47. package/dist/params.js +114 -15
  48. package/dist/params.js.map +1 -1
  49. package/dist/tasks.cjs +2295 -0
  50. package/dist/tasks.cjs.map +1 -0
  51. package/dist/tasks.js +2240 -0
  52. package/dist/tasks.js.map +1 -0
  53. package/dist/utils.cjs +15 -2
  54. package/dist/utils.cjs.map +1 -1
  55. package/dist/utils.js +12 -1
  56. package/dist/utils.js.map +1 -1
  57. package/package.json +18 -3
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(config2 = {}) {
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(config2).length > 0) {
1126
- this.configure(config2);
1128
+ if (Object.keys(configToUse).length > 0) {
1129
+ this.configure(configToUse);
1127
1130
  }
1128
- const args = config2.args || process.argv.slice(2);
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
- * Note: Args is special - it's initialized first, so it can't take context
1157
- * This static method is for consistency with other components
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
- return new _Args(config2);
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 feature
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
- source = "cli";
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 parameters left-to-right to support cross-parameter references
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
- const res = {};
1903
- for (const [k, def] of Object.entries(defs)) {
1904
- const value = this.get(k, def);
1905
- res[k] = value;
1906
- if (value !== void 0) {
1907
- this.params[k] = value;
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
- return res;
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
@@ -1987,6 +2126,7 @@ var ALL_LEVELS = [
1987
2126
  "response",
1988
2127
  "progress"
1989
2128
  ];
2129
+ var DEFAULT_LEVELS = ALL_LEVELS.filter((l) => l !== "silly");
1990
2130
  var MAX_LEVEL_LENGTH = Math.max(...ALL_LEVELS.map((level) => level.toUpperCase().length));
1991
2131
  var LEVEL_COLORS = {
1992
2132
  error: chalk.red.bold,
@@ -2017,8 +2157,7 @@ var Logger = class _Logger {
2017
2157
  this.updateTransport();
2018
2158
  }
2019
2159
  /**
2020
- * Configure logger options
2021
- * Only parameters present in options are updated
2160
+ * Configure logger options. Accepts both LoggerOptions shape and flat param names (levels string, progressWithTimes, progressThrottleMs).
2022
2161
  */
2023
2162
  configure(options) {
2024
2163
  if (options.mode !== void 0) {
@@ -2028,32 +2167,24 @@ var Logger = class _Logger {
2028
2167
  this.options.route = options.route;
2029
2168
  this.updateTransport();
2030
2169
  }
2031
- if (options.prefix !== void 0) {
2032
- this.options.prefix = options.prefix;
2033
- }
2034
- if (options.silent !== void 0) {
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
- }
2170
+ if (options.prefix !== void 0) this.options.prefix = options.prefix;
2171
+ if (options.silent !== void 0) this.options.silent = options.silent;
2172
+ if (options.showLevel !== void 0) this.options.showLevel = options.showLevel;
2173
+ if (options.timestamp !== void 0) this.options.timestamp = options.timestamp;
2043
2174
  if (options.levels !== void 0) {
2044
- this.options.levels = this.normalizeLevels(options.levels);
2175
+ const levels = typeof options.levels === "string" ? options.levels.split(",") : options.levels;
2176
+ this.options.levels = this.normalizeLevels(levels);
2045
2177
  }
2046
2178
  if (options.progress !== void 0) {
2047
- if (options.progress.withTimes !== void 0) {
2048
- this.options.progressTimes = options.progress.withTimes;
2049
- }
2050
- if (options.progress.throttleMs !== void 0) {
2051
- this.options.progressThrottle = options.progress.throttleMs;
2052
- }
2179
+ if (options.progress.withTimes !== void 0) this.options.progressTimes = options.progress.withTimes;
2180
+ if (options.progress.throttleMs !== void 0) this.options.progressThrottle = options.progress.throttleMs;
2053
2181
  }
2182
+ const flat = options;
2183
+ if (flat.progressWithTimes !== void 0) this.options.progressTimes = flat.progressWithTimes;
2184
+ if (flat.progressThrottleMs !== void 0) this.options.progressThrottle = flat.progressThrottleMs;
2054
2185
  }
2055
2186
  /**
2056
- * Initialize logger from context and CLI parameters
2187
+ * Initialize logger from context and CLI parameters. Whatever is in options goes (after discovered params).
2057
2188
  */
2058
2189
  static init(context, options) {
2059
2190
  const paramDefs = {
@@ -2067,20 +2198,8 @@ var Logger = class _Logger {
2067
2198
  progressWithTimes: "boolean default false",
2068
2199
  progressThrottleMs: "number"
2069
2200
  };
2070
- const cliParams = context.params.getAll(paramDefs);
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
- };
2201
+ const discovered = context.params.getAllForModule(paramDefs);
2202
+ const config2 = { ...discovered, ...options };
2084
2203
  const logger = new _Logger(context, config2);
2085
2204
  context.logger = logger;
2086
2205
  return logger;
@@ -2093,7 +2212,7 @@ var Logger = class _Logger {
2093
2212
  silent: false,
2094
2213
  showLevel: false,
2095
2214
  timestamp: false,
2096
- levels: ALL_LEVELS,
2215
+ levels: DEFAULT_LEVELS,
2097
2216
  progressTimes: false,
2098
2217
  progressThrottle: void 0
2099
2218
  };
@@ -2107,6 +2226,10 @@ var Logger = class _Logger {
2107
2226
  }
2108
2227
  this.options.mode = mode;
2109
2228
  }
2229
+ /** Returns a styled string (bright white) for highlighting; keeps chalk inside logger. */
2230
+ highlight(text) {
2231
+ return chalk.whiteBright(text);
2232
+ }
2110
2233
  debug(message, ...chunks) {
2111
2234
  this.out({ level: "debug", message, chunks });
2112
2235
  }
@@ -2249,15 +2372,17 @@ var Logger = class _Logger {
2249
2372
  }
2250
2373
  normalizeLevels(levels) {
2251
2374
  if (!levels || !levels.length) {
2252
- return ALL_LEVELS;
2375
+ return DEFAULT_LEVELS;
2253
2376
  }
2254
- const includes = levels.filter((level) => !level.startsWith("-"));
2255
- const excludes = levels.filter((level) => level.startsWith("-")).map((level) => level.slice(1));
2256
- const unknown = [...includes, ...excludes].filter((level) => !ALL_LEVELS.includes(level));
2377
+ const tokens = levels.map((t) => String(t).trim()).filter(Boolean);
2378
+ const explicitIncludes = tokens.filter((t) => !t.startsWith("+") && !t.startsWith("-")).map((t) => t);
2379
+ const addIncludes = tokens.filter((t) => t.startsWith("+")).map((t) => t.slice(1));
2380
+ const excludes = tokens.filter((t) => t.startsWith("-")).map((t) => t.slice(1));
2381
+ const unknown = [...explicitIncludes, ...addIncludes, ...excludes].filter((level) => !ALL_LEVELS.includes(level));
2257
2382
  if (unknown.length) {
2258
2383
  console.warn(`[Logger] Unknown level(s): ${unknown.join(", ")}`);
2259
2384
  }
2260
- const base = includes.length ? includes : ALL_LEVELS;
2385
+ const base = explicitIncludes.length ? explicitIncludes : Array.from(/* @__PURE__ */ new Set([...DEFAULT_LEVELS, ...addIncludes]));
2261
2386
  return base.filter((level) => !excludes.includes(level));
2262
2387
  }
2263
2388
  isValidMode(mode) {
@@ -2282,12 +2407,7 @@ function extractComponentOptions(opts, componentName) {
2282
2407
  return componentOptions;
2283
2408
  }
2284
2409
  function setup(opts = {}) {
2285
- const args = Args.init({
2286
- overrides: opts.overrides || {},
2287
- defaults: opts.defaults || {}
2288
- });
2289
2410
  const partialContext = {
2290
- args,
2291
2411
  emitter: new EventEmitter(),
2292
2412
  isStop: () => false,
2293
2413
  cleanupFunctions: [],
@@ -2295,6 +2415,11 @@ function setup(opts = {}) {
2295
2415
  partialContext.cleanupFunctions.push(fn);
2296
2416
  }
2297
2417
  };
2418
+ const args = Args.init(partialContext, {
2419
+ overrides: opts.overrides || {},
2420
+ defaults: opts.defaults || {}
2421
+ });
2422
+ partialContext.args = args;
2298
2423
  const params = Params.init(partialContext, opts.overrides || {});
2299
2424
  partialContext.params = params;
2300
2425
  const loggerOptions = extractComponentOptions(opts, "logger");
@@ -2355,6 +2480,7 @@ async function init(flow, opts = {}) {
2355
2480
  context.isStop = () => stop;
2356
2481
  context = await setupModules(context, opts);
2357
2482
  const stopAfter = context.args.get("stopAfter");
2483
+ const stopAllowance = context.params.get("stopAllowance", "number default 5");
2358
2484
  if (stopAfter === "init") {
2359
2485
  printAllParameters(context);
2360
2486
  process.exit(0);
@@ -2365,13 +2491,8 @@ async function init(flow, opts = {}) {
2365
2491
  process.exit(2);
2366
2492
  }
2367
2493
  stop = true;
2368
- let allowance = 5;
2369
- try {
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);
2494
+ context.logger.info(`>> emitting stop with allowance ${stopAllowance}`);
2495
+ context.emitter.emit("stop", stopAllowance);
2375
2496
  });
2376
2497
  await flow(context);
2377
2498
  } catch (error) {
@@ -2402,10 +2523,6 @@ async function init(flow, opts = {}) {
2402
2523
  context.logger.warn("[cleanup] error in cleanup function:", error);
2403
2524
  }
2404
2525
  }
2405
- const unusedArgs = context.args.getUnused();
2406
- if (unusedArgs.length > 0) {
2407
- context.logger.warn("Unused CLI args:", unusedArgs.join(", "));
2408
- }
2409
2526
  }
2410
2527
  }
2411
2528
  }