@gearbox-protocol/deploy-tools 1.1.5 → 1.3.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 (2) hide show
  1. package/dist/index.js +217 -172
  2. package/package.json +11 -11
package/dist/index.js CHANGED
@@ -167,7 +167,7 @@ var require_argument = __commonJS({
167
167
  /**
168
168
  * Set the default value, and optionally supply the description to be displayed in the help.
169
169
  *
170
- * @param {any} value
170
+ * @param {*} value
171
171
  * @param {string} [description]
172
172
  * @return {Argument}
173
173
  */
@@ -312,8 +312,8 @@ var require_help = __commonJS({
312
312
  if (!this.showGlobalOptions)
313
313
  return [];
314
314
  const globalOptions = [];
315
- for (let parentCmd = cmd.parent; parentCmd; parentCmd = parentCmd.parent) {
316
- const visibleOptions = parentCmd.options.filter((option) => !option.hidden);
315
+ for (let ancestorCmd = cmd.parent; ancestorCmd; ancestorCmd = ancestorCmd.parent) {
316
+ const visibleOptions = ancestorCmd.options.filter((option) => !option.hidden);
317
317
  globalOptions.push(...visibleOptions);
318
318
  }
319
319
  if (this.sortOptions) {
@@ -329,12 +329,12 @@ var require_help = __commonJS({
329
329
  */
330
330
  visibleArguments(cmd) {
331
331
  if (cmd._argsDescription) {
332
- cmd._args.forEach((argument) => {
332
+ cmd.registeredArguments.forEach((argument) => {
333
333
  argument.description = argument.description || cmd._argsDescription[argument.name()] || "";
334
334
  });
335
335
  }
336
- if (cmd._args.find((argument) => argument.description)) {
337
- return cmd._args;
336
+ if (cmd.registeredArguments.find((argument) => argument.description)) {
337
+ return cmd.registeredArguments;
338
338
  }
339
339
  return [];
340
340
  }
@@ -345,7 +345,7 @@ var require_help = __commonJS({
345
345
  * @returns {string}
346
346
  */
347
347
  subcommandTerm(cmd) {
348
- const args = cmd._args.map((arg) => humanReadableArgName(arg)).join(" ");
348
+ const args = cmd.registeredArguments.map((arg) => humanReadableArgName(arg)).join(" ");
349
349
  return cmd._name + (cmd._aliases[0] ? "|" + cmd._aliases[0] : "") + (cmd.options.length ? " [options]" : "") + // simplistic check for non-help option
350
350
  (args ? " " + args : "");
351
351
  }
@@ -426,11 +426,11 @@ var require_help = __commonJS({
426
426
  if (cmd._aliases[0]) {
427
427
  cmdName = cmdName + "|" + cmd._aliases[0];
428
428
  }
429
- let parentCmdNames = "";
430
- for (let parentCmd = cmd.parent; parentCmd; parentCmd = parentCmd.parent) {
431
- parentCmdNames = parentCmd.name() + " " + parentCmdNames;
429
+ let ancestorCmdNames = "";
430
+ for (let ancestorCmd = cmd.parent; ancestorCmd; ancestorCmd = ancestorCmd.parent) {
431
+ ancestorCmdNames = ancestorCmd.name() + " " + ancestorCmdNames;
432
432
  }
433
- return parentCmdNames + cmdName + " " + cmd.usage();
433
+ return ancestorCmdNames + cmdName + " " + cmd.usage();
434
434
  }
435
435
  /**
436
436
  * Get the description for the command.
@@ -654,7 +654,7 @@ var require_option = __commonJS({
654
654
  /**
655
655
  * Set the default value, and optionally supply the description to be displayed in the help.
656
656
  *
657
- * @param {any} value
657
+ * @param {*} value
658
658
  * @param {string} [description]
659
659
  * @return {Option}
660
660
  */
@@ -671,7 +671,7 @@ var require_option = __commonJS({
671
671
  * new Option('--color').default('GREYSCALE').preset('RGB');
672
672
  * new Option('--donate [amount]').preset('20').argParser(parseFloat);
673
673
  *
674
- * @param {any} arg
674
+ * @param {*} arg
675
675
  * @return {Option}
676
676
  */
677
677
  preset(arg) {
@@ -852,7 +852,7 @@ var require_option = __commonJS({
852
852
  /**
853
853
  * Did the value come from the option, and not from possible matching dual option?
854
854
  *
855
- * @param {any} value
855
+ * @param {*} value
856
856
  * @param {Option} option
857
857
  * @returns {boolean}
858
858
  */
@@ -997,7 +997,8 @@ var require_command = __commonJS({
997
997
  this.parent = null;
998
998
  this._allowUnknownOption = false;
999
999
  this._allowExcessArguments = true;
1000
- this._args = [];
1000
+ this.registeredArguments = [];
1001
+ this._args = this.registeredArguments;
1001
1002
  this.args = [];
1002
1003
  this.rawArgs = [];
1003
1004
  this.processedArgs = [];
@@ -1069,6 +1070,17 @@ var require_command = __commonJS({
1069
1070
  this._showSuggestionAfterError = sourceCommand._showSuggestionAfterError;
1070
1071
  return this;
1071
1072
  }
1073
+ /**
1074
+ * @returns {Command[]}
1075
+ * @api private
1076
+ */
1077
+ _getCommandAndAncestors() {
1078
+ const result = [];
1079
+ for (let command = this; command; command = command.parent) {
1080
+ result.push(command);
1081
+ }
1082
+ return result;
1083
+ }
1072
1084
  /**
1073
1085
  * Define a command.
1074
1086
  *
@@ -1286,14 +1298,14 @@ var require_command = __commonJS({
1286
1298
  * @return {Command} `this` command for chaining
1287
1299
  */
1288
1300
  addArgument(argument) {
1289
- const previousArgument = this._args.slice(-1)[0];
1301
+ const previousArgument = this.registeredArguments.slice(-1)[0];
1290
1302
  if (previousArgument && previousArgument.variadic) {
1291
1303
  throw new Error(`only the last argument can be variadic '${previousArgument.name()}'`);
1292
1304
  }
1293
1305
  if (argument.required && argument.defaultValue !== void 0 && argument.parseArg === void 0) {
1294
1306
  throw new Error(`a default value for a required argument is never used: '${argument.name()}'`);
1295
1307
  }
1296
- this._args.push(argument);
1308
+ this.registeredArguments.push(argument);
1297
1309
  return this;
1298
1310
  }
1299
1311
  /**
@@ -1398,7 +1410,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
1398
1410
  */
1399
1411
  action(fn) {
1400
1412
  const listener = (args) => {
1401
- const expectedArgsCount = this._args.length;
1413
+ const expectedArgsCount = this.registeredArguments.length;
1402
1414
  const actionArgs = args.slice(0, expectedArgsCount);
1403
1415
  if (this._storeOptionsAsProperties) {
1404
1416
  actionArgs[expectedArgsCount] = this;
@@ -1424,6 +1436,26 @@ Expecting one of '${allowedValues.join("', '")}'`);
1424
1436
  createOption(flags, description) {
1425
1437
  return new Option2(flags, description);
1426
1438
  }
1439
+ /**
1440
+ * Wrap parseArgs to catch 'commander.invalidArgument'.
1441
+ *
1442
+ * @param {Option | Argument} target
1443
+ * @param {string} value
1444
+ * @param {*} previous
1445
+ * @param {string} invalidArgumentMessage
1446
+ * @api private
1447
+ */
1448
+ _callParseArg(target, value, previous, invalidArgumentMessage) {
1449
+ try {
1450
+ return target.parseArg(value, previous);
1451
+ } catch (err) {
1452
+ if (err.code === "commander.invalidArgument") {
1453
+ const message = `${invalidArgumentMessage} ${err.message}`;
1454
+ this.error(message, { exitCode: err.exitCode, code: err.code });
1455
+ }
1456
+ throw err;
1457
+ }
1458
+ }
1427
1459
  /**
1428
1460
  * Add an option.
1429
1461
  *
@@ -1448,15 +1480,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
1448
1480
  }
1449
1481
  const oldValue = this.getOptionValue(name);
1450
1482
  if (val !== null && option.parseArg) {
1451
- try {
1452
- val = option.parseArg(val, oldValue);
1453
- } catch (err) {
1454
- if (err.code === "commander.invalidArgument") {
1455
- const message = `${invalidValueMessage} ${err.message}`;
1456
- this.error(message, { exitCode: err.exitCode, code: err.code });
1457
- }
1458
- throw err;
1459
- }
1483
+ val = this._callParseArg(option, val, oldValue, invalidValueMessage);
1460
1484
  } else if (val !== null && option.variadic) {
1461
1485
  val = option._concatValue(val, oldValue);
1462
1486
  }
@@ -1509,56 +1533,28 @@ Expecting one of '${allowedValues.join("', '")}'`);
1509
1533
  return this.addOption(option);
1510
1534
  }
1511
1535
  /**
1512
- * Define option with `flags`, `description` and optional
1513
- * coercion `fn`.
1536
+ * Define option with `flags`, `description`, and optional argument parsing function or `defaultValue` or both.
1514
1537
  *
1515
- * The `flags` string contains the short and/or long flags,
1516
- * separated by comma, a pipe or space. The following are all valid
1517
- * all will output this way when `--help` is used.
1538
+ * The `flags` string contains the short and/or long flags, separated by comma, a pipe or space. A required
1539
+ * option-argument is indicated by `<>` and an optional option-argument by `[]`.
1518
1540
  *
1519
- * "-p, --pepper"
1520
- * "-p|--pepper"
1521
- * "-p --pepper"
1541
+ * See the README for more details, and see also addOption() and requiredOption().
1522
1542
  *
1523
1543
  * @example
1524
- * // simple boolean defaulting to undefined
1525
- * program.option('-p, --pepper', 'add pepper');
1526
- *
1527
- * program.pepper
1528
- * // => undefined
1529
- *
1530
- * --pepper
1531
- * program.pepper
1532
- * // => true
1533
- *
1534
- * // simple boolean defaulting to true (unless non-negated option is also defined)
1535
- * program.option('-C, --no-cheese', 'remove cheese');
1536
- *
1537
- * program.cheese
1538
- * // => true
1539
- *
1540
- * --no-cheese
1541
- * program.cheese
1542
- * // => false
1543
- *
1544
- * // required argument
1545
- * program.option('-C, --chdir <path>', 'change the working directory');
1546
- *
1547
- * --chdir /tmp
1548
- * program.chdir
1549
- * // => "/tmp"
1550
- *
1551
- * // optional argument
1552
- * program.option('-c, --cheese [type]', 'add cheese [marble]');
1544
+ * program
1545
+ * .option('-p, --pepper', 'add pepper')
1546
+ * .option('-p, --pizza-type <TYPE>', 'type of pizza') // required option-argument
1547
+ * .option('-c, --cheese [CHEESE]', 'add extra cheese', 'mozzarella') // optional option-argument with default
1548
+ * .option('-t, --tip <VALUE>', 'add tip to purchase cost', parseFloat) // custom parse function
1553
1549
  *
1554
1550
  * @param {string} flags
1555
1551
  * @param {string} [description]
1556
- * @param {Function|*} [fn] - custom option processing function or default value
1552
+ * @param {Function|*} [parseArg] - custom option processing function or default value
1557
1553
  * @param {*} [defaultValue]
1558
1554
  * @return {Command} `this` command for chaining
1559
1555
  */
1560
- option(flags, description, fn, defaultValue) {
1561
- return this._optionEx({}, flags, description, fn, defaultValue);
1556
+ option(flags, description, parseArg, defaultValue) {
1557
+ return this._optionEx({}, flags, description, parseArg, defaultValue);
1562
1558
  }
1563
1559
  /**
1564
1560
  * Add a required option which must have a value after parsing. This usually means
@@ -1568,12 +1564,12 @@ Expecting one of '${allowedValues.join("', '")}'`);
1568
1564
  *
1569
1565
  * @param {string} flags
1570
1566
  * @param {string} [description]
1571
- * @param {Function|*} [fn] - custom option processing function or default value
1567
+ * @param {Function|*} [parseArg] - custom option processing function or default value
1572
1568
  * @param {*} [defaultValue]
1573
1569
  * @return {Command} `this` command for chaining
1574
1570
  */
1575
- requiredOption(flags, description, fn, defaultValue) {
1576
- return this._optionEx({ mandatory: true }, flags, description, fn, defaultValue);
1571
+ requiredOption(flags, description, parseArg, defaultValue) {
1572
+ return this._optionEx({ mandatory: true }, flags, description, parseArg, defaultValue);
1577
1573
  }
1578
1574
  /**
1579
1575
  * Alter parsing of short flags with optional values.
@@ -1644,10 +1640,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
1644
1640
  * @return {Command} `this` command for chaining
1645
1641
  */
1646
1642
  storeOptionsAsProperties(storeAsProperties = true) {
1647
- this._storeOptionsAsProperties = !!storeAsProperties;
1648
1643
  if (this.options.length) {
1649
1644
  throw new Error("call .storeOptionsAsProperties() before adding options");
1650
1645
  }
1646
+ this._storeOptionsAsProperties = !!storeAsProperties;
1651
1647
  return this;
1652
1648
  }
1653
1649
  /**
@@ -1708,7 +1704,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
1708
1704
  */
1709
1705
  getOptionValueSourceWithGlobals(key) {
1710
1706
  let source;
1711
- getCommandAndParents(this).forEach((cmd) => {
1707
+ this._getCommandAndAncestors().forEach((cmd) => {
1712
1708
  if (cmd.getOptionValueSource(key) !== void 0) {
1713
1709
  source = cmd.getOptionValueSource(key);
1714
1710
  }
@@ -1907,16 +1903,16 @@ Expecting one of '${allowedValues.join("', '")}'`);
1907
1903
  const subCommand = this._findCommand(commandName);
1908
1904
  if (!subCommand)
1909
1905
  this.help({ error: true });
1910
- let hookResult;
1911
- hookResult = this._chainOrCallSubCommandHook(hookResult, subCommand, "preSubcommand");
1912
- hookResult = this._chainOrCall(hookResult, () => {
1906
+ let promiseChain;
1907
+ promiseChain = this._chainOrCallSubCommandHook(promiseChain, subCommand, "preSubcommand");
1908
+ promiseChain = this._chainOrCall(promiseChain, () => {
1913
1909
  if (subCommand._executableHandler) {
1914
1910
  this._executeSubCommand(subCommand, operands.concat(unknown));
1915
1911
  } else {
1916
1912
  return subCommand._parseCommand(operands, unknown);
1917
1913
  }
1918
1914
  });
1919
- return hookResult;
1915
+ return promiseChain;
1920
1916
  }
1921
1917
  /**
1922
1918
  * Invoke help directly if possible, or dispatch if necessary.
@@ -1932,28 +1928,30 @@ Expecting one of '${allowedValues.join("', '")}'`);
1932
1928
  if (subCommand && !subCommand._executableHandler) {
1933
1929
  subCommand.help();
1934
1930
  }
1935
- return this._dispatchSubcommand(subcommandName, [], [this._helpLongFlag]);
1931
+ return this._dispatchSubcommand(subcommandName, [], [
1932
+ this._helpLongFlag || this._helpShortFlag
1933
+ ]);
1936
1934
  }
1937
1935
  /**
1938
- * Check this.args against expected this._args.
1936
+ * Check this.args against expected this.registeredArguments.
1939
1937
  *
1940
1938
  * @api private
1941
1939
  */
1942
1940
  _checkNumberOfArguments() {
1943
- this._args.forEach((arg, i) => {
1941
+ this.registeredArguments.forEach((arg, i) => {
1944
1942
  if (arg.required && this.args[i] == null) {
1945
1943
  this.missingArgument(arg.name());
1946
1944
  }
1947
1945
  });
1948
- if (this._args.length > 0 && this._args[this._args.length - 1].variadic) {
1946
+ if (this.registeredArguments.length > 0 && this.registeredArguments[this.registeredArguments.length - 1].variadic) {
1949
1947
  return;
1950
1948
  }
1951
- if (this.args.length > this._args.length) {
1949
+ if (this.args.length > this.registeredArguments.length) {
1952
1950
  this._excessArguments(this.args);
1953
1951
  }
1954
1952
  }
1955
1953
  /**
1956
- * Process this.args using this._args and save as this.processedArgs!
1954
+ * Process this.args using this.registeredArguments and save as this.processedArgs!
1957
1955
  *
1958
1956
  * @api private
1959
1957
  */
@@ -1961,21 +1959,14 @@ Expecting one of '${allowedValues.join("', '")}'`);
1961
1959
  const myParseArg = (argument, value, previous) => {
1962
1960
  let parsedValue = value;
1963
1961
  if (value !== null && argument.parseArg) {
1964
- try {
1965
- parsedValue = argument.parseArg(value, previous);
1966
- } catch (err) {
1967
- if (err.code === "commander.invalidArgument") {
1968
- const message = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'. ${err.message}`;
1969
- this.error(message, { exitCode: err.exitCode, code: err.code });
1970
- }
1971
- throw err;
1972
- }
1962
+ const invalidValueMessage = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'.`;
1963
+ parsedValue = this._callParseArg(argument, value, previous, invalidValueMessage);
1973
1964
  }
1974
1965
  return parsedValue;
1975
1966
  };
1976
1967
  this._checkNumberOfArguments();
1977
1968
  const processedArgs = [];
1978
- this._args.forEach((declaredArg, index) => {
1969
+ this.registeredArguments.forEach((declaredArg, index) => {
1979
1970
  let value = declaredArg.defaultValue;
1980
1971
  if (declaredArg.variadic) {
1981
1972
  if (index < this.args.length) {
@@ -2022,7 +2013,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2022
2013
  _chainOrCallHooks(promise, event) {
2023
2014
  let result = promise;
2024
2015
  const hooks = [];
2025
- getCommandAndParents(this).reverse().filter((cmd) => cmd._lifeCycleHooks[event] !== void 0).forEach((hookedCommand) => {
2016
+ this._getCommandAndAncestors().reverse().filter((cmd) => cmd._lifeCycleHooks[event] !== void 0).forEach((hookedCommand) => {
2026
2017
  hookedCommand._lifeCycleHooks[event].forEach((callback) => {
2027
2018
  hooks.push({ hookedCommand, callback });
2028
2019
  });
@@ -2094,16 +2085,16 @@ Expecting one of '${allowedValues.join("', '")}'`);
2094
2085
  if (this._actionHandler) {
2095
2086
  checkForUnknownOptions();
2096
2087
  this._processArguments();
2097
- let actionResult;
2098
- actionResult = this._chainOrCallHooks(actionResult, "preAction");
2099
- actionResult = this._chainOrCall(actionResult, () => this._actionHandler(this.processedArgs));
2088
+ let promiseChain;
2089
+ promiseChain = this._chainOrCallHooks(promiseChain, "preAction");
2090
+ promiseChain = this._chainOrCall(promiseChain, () => this._actionHandler(this.processedArgs));
2100
2091
  if (this.parent) {
2101
- actionResult = this._chainOrCall(actionResult, () => {
2092
+ promiseChain = this._chainOrCall(promiseChain, () => {
2102
2093
  this.parent.emit(commandEvent, operands, unknown);
2103
2094
  });
2104
2095
  }
2105
- actionResult = this._chainOrCallHooks(actionResult, "postAction");
2106
- return actionResult;
2096
+ promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
2097
+ return promiseChain;
2107
2098
  }
2108
2099
  if (this.parent && this.parent.listenerCount(commandEvent)) {
2109
2100
  checkForUnknownOptions();
@@ -2156,13 +2147,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
2156
2147
  * @api private
2157
2148
  */
2158
2149
  _checkForMissingMandatoryOptions() {
2159
- for (let cmd = this; cmd; cmd = cmd.parent) {
2150
+ this._getCommandAndAncestors().forEach((cmd) => {
2160
2151
  cmd.options.forEach((anOption) => {
2161
2152
  if (anOption.mandatory && cmd.getOptionValue(anOption.attributeName()) === void 0) {
2162
2153
  cmd.missingMandatoryOptionValue(anOption);
2163
2154
  }
2164
2155
  });
2165
- }
2156
+ });
2166
2157
  }
2167
2158
  /**
2168
2159
  * Display an error message if conflicting options are used together in this.
@@ -2198,9 +2189,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
2198
2189
  * @api private
2199
2190
  */
2200
2191
  _checkForConflictingOptions() {
2201
- for (let cmd = this; cmd; cmd = cmd.parent) {
2192
+ this._getCommandAndAncestors().forEach((cmd) => {
2202
2193
  cmd._checkForConflictingLocalOptions();
2203
- }
2194
+ });
2204
2195
  }
2205
2196
  /**
2206
2197
  * Parse options from `argv` removing known options,
@@ -2334,7 +2325,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2334
2325
  * @return {Object}
2335
2326
  */
2336
2327
  optsWithGlobals() {
2337
- return getCommandAndParents(this).reduce(
2328
+ return this._getCommandAndAncestors().reduce(
2338
2329
  (combinedOptions, cmd) => Object.assign(combinedOptions, cmd.opts()),
2339
2330
  {}
2340
2331
  );
@@ -2490,7 +2481,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2490
2481
  _excessArguments(receivedArgs) {
2491
2482
  if (this._allowExcessArguments)
2492
2483
  return;
2493
- const expected = this._args.length;
2484
+ const expected = this.registeredArguments.length;
2494
2485
  const s = expected === 1 ? "" : "s";
2495
2486
  const forSubcommand = this.parent ? ` for '${this.name()}'` : "";
2496
2487
  const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
@@ -2517,17 +2508,16 @@ Expecting one of '${allowedValues.join("', '")}'`);
2517
2508
  this.error(message, { code: "commander.unknownCommand" });
2518
2509
  }
2519
2510
  /**
2520
- * Set the program version to `str`.
2511
+ * Get or set the program version.
2521
2512
  *
2522
- * This method auto-registers the "-V, --version" flag
2523
- * which will print the version number when passed.
2513
+ * This method auto-registers the "-V, --version" option which will print the version number.
2524
2514
  *
2525
- * You can optionally supply the flags and description to override the defaults.
2515
+ * You can optionally supply the flags and description to override the defaults.
2526
2516
  *
2527
- * @param {string} str
2517
+ * @param {string} [str]
2528
2518
  * @param {string} [flags]
2529
2519
  * @param {string} [description]
2530
- * @return {this | string} `this` command for chaining, or version string if no arguments
2520
+ * @return {this | string | undefined} `this` command for chaining, or version string if no arguments
2531
2521
  */
2532
2522
  version(str, flags, description) {
2533
2523
  if (str === void 0)
@@ -2617,13 +2607,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
2617
2607
  if (str === void 0) {
2618
2608
  if (this._usage)
2619
2609
  return this._usage;
2620
- const args = this._args.map((arg) => {
2610
+ const args = this.registeredArguments.map((arg) => {
2621
2611
  return humanReadableArgName(arg);
2622
2612
  });
2623
2613
  return [].concat(
2624
2614
  this.options.length || this._hasHelpOption ? "[options]" : [],
2625
2615
  this.commands.length ? "[command]" : [],
2626
- this._args.length ? args : []
2616
+ this.registeredArguments.length ? args : []
2627
2617
  ).join(" ");
2628
2618
  }
2629
2619
  this._usage = str;
@@ -2666,7 +2656,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2666
2656
  * program.executableDir('subcommands');
2667
2657
  *
2668
2658
  * @param {string} [path]
2669
- * @return {string|Command}
2659
+ * @return {string|null|Command}
2670
2660
  */
2671
2661
  executableDir(path5) {
2672
2662
  if (path5 === void 0)
@@ -2717,7 +2707,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2717
2707
  contextOptions = void 0;
2718
2708
  }
2719
2709
  const context = this._getHelpContext(contextOptions);
2720
- getCommandAndParents(this).reverse().forEach((command) => command.emit("beforeAllHelp", context));
2710
+ this._getCommandAndAncestors().reverse().forEach((command) => command.emit("beforeAllHelp", context));
2721
2711
  this.emit("beforeHelp", context);
2722
2712
  let helpInformation = this.helpInformation(context);
2723
2713
  if (deprecatedCallback) {
@@ -2727,9 +2717,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
2727
2717
  }
2728
2718
  }
2729
2719
  context.write(helpInformation);
2730
- this.emit(this._helpLongFlag);
2720
+ if (this._helpLongFlag) {
2721
+ this.emit(this._helpLongFlag);
2722
+ }
2731
2723
  this.emit("afterHelp", context);
2732
- getCommandAndParents(this).forEach((command) => command.emit("afterAllHelp", context));
2724
+ this._getCommandAndAncestors().forEach((command) => command.emit("afterAllHelp", context));
2733
2725
  }
2734
2726
  /**
2735
2727
  * You can pass in flags and a description to override the help
@@ -2835,13 +2827,6 @@ Expecting one of '${allowedValues.join("', '")}'`);
2835
2827
  return arg;
2836
2828
  });
2837
2829
  }
2838
- function getCommandAndParents(startCommand) {
2839
- const result = [];
2840
- for (let command = startCommand; command; command = command.parent) {
2841
- result.push(command);
2842
- }
2843
- return result;
2844
- }
2845
2830
  exports2.Command = Command2;
2846
2831
  }
2847
2832
  });
@@ -2856,13 +2841,13 @@ var require_commander = __commonJS({
2856
2841
  var { Option: Option2 } = require_option();
2857
2842
  exports2 = module2.exports = new Command2();
2858
2843
  exports2.program = exports2;
2859
- exports2.Argument = Argument2;
2860
2844
  exports2.Command = Command2;
2861
- exports2.CommanderError = CommanderError2;
2845
+ exports2.Option = Option2;
2846
+ exports2.Argument = Argument2;
2862
2847
  exports2.Help = Help2;
2848
+ exports2.CommanderError = CommanderError2;
2863
2849
  exports2.InvalidArgumentError = InvalidArgumentError2;
2864
2850
  exports2.InvalidOptionArgumentError = InvalidArgumentError2;
2865
- exports2.Option = Option2;
2866
2851
  }
2867
2852
  });
2868
2853
 
@@ -150489,7 +150474,7 @@ var require_package2 = __commonJS({
150489
150474
  license: "BUSL-1.1",
150490
150475
  scripts: {
150491
150476
  build: "node esbuild.config.mjs",
150492
- start: "ts-node -r dotenv/config ./src/index.ts",
150477
+ start: "tsx -r dotenv/config ./src/index.ts",
150493
150478
  prepare: "husky install",
150494
150479
  prettier: "prettier --write .",
150495
150480
  "prettier:ci": "npx prettier --check .",
@@ -150500,32 +150485,32 @@ var require_package2 = __commonJS({
150500
150485
  dependencies: {},
150501
150486
  devDependencies: {
150502
150487
  "@actions/core": "^1.10.1",
150503
- "@commitlint/cli": "^17.7.2",
150504
- "@commitlint/config-conventional": "^17.7.0",
150488
+ "@commitlint/cli": "^17.8.0",
150489
+ "@commitlint/config-conventional": "^17.8.0",
150505
150490
  "@ethereum-sourcify/bytecode-utils": "^1.2.0",
150506
150491
  "@ethereum-sourcify/lib-sourcify": "^1.3.2",
150507
150492
  "@gearbox-protocol/eslint-config": "2.0.0-next.0",
150508
150493
  "@gearbox-protocol/prettier-config": "2.0.0-next.0",
150509
- "@gearbox-protocol/sdk": "^3.0.0-next.14",
150494
+ "@gearbox-protocol/sdk": "^3.0.0-next.36",
150510
150495
  "@safe-global/api-kit": "^1.3.1",
150511
150496
  "@safe-global/protocol-kit": "^1.3.0",
150512
150497
  "@safe-global/safe-core-sdk-types": "^2.3.0",
150513
150498
  "@types/lodash": "^4.14.199",
150514
- "@types/node": "^20.8.2",
150515
- abitype: "^0.9.9",
150499
+ "@types/node": "^20.8.6",
150500
+ abitype: "^0.10.1",
150516
150501
  chalk: "^4.1.2",
150517
- commander: "^11.0.0",
150502
+ commander: "^11.1.0",
150518
150503
  "date-fns": "^2.30.0",
150519
150504
  dotenv: "^16.3.1",
150520
150505
  esbuild: "^0.19.4",
150521
- eslint: "^8.50.0",
150506
+ eslint: "^8.51.0",
150522
150507
  ethers: "5.7.2",
150523
150508
  husky: "^8.0.3",
150524
- "lint-staged": "^14.0.1",
150509
+ "lint-staged": "^15.0.1",
150525
150510
  lodash: "^4.17.21",
150526
150511
  "p-retry": "^4.6.2",
150527
150512
  prettier: "^3.0.3",
150528
- "ts-node": "^10.9.1",
150513
+ tsx: "^3.13.0",
150529
150514
  tslog: "^4.9.2",
150530
150515
  typescript: "^5.2.2"
150531
150516
  },
@@ -151139,8 +151124,10 @@ var levels = {
151139
151124
  fatal: 6
151140
151125
  };
151141
151126
  var _a;
151127
+ var minLevel = levels[((_a = process.env.LOG_LEVEL) == null ? void 0 : _a.toLowerCase()) ?? "info"] ?? 3;
151142
151128
  var logger = new Logger({
151143
- minLevel: levels[((_a = process.env.LOG_LEVEL) == null ? void 0 : _a.toLowerCase()) ?? "info"] ?? 3
151129
+ prettyLogTemplate: minLevel < 3 ? "{{logLevelName}} {{filePathWithLine}} {{name}} " : "{{logLevelName}} {{name}} ",
151130
+ minLevel
151144
151131
  });
151145
151132
  var log_default = logger;
151146
151133
 
@@ -151466,7 +151453,7 @@ var AuditChecker = class {
151466
151453
  async setup() {
151467
151454
  (0, import_node_fs.mkdirSync)(__privateGet(this, _sandboxDir), { recursive: true });
151468
151455
  await clearDir(__privateGet(this, _sandboxDir));
151469
- __privateGet(this, _logger).debug(`Cleared sandbox dir ${__privateGet(this, _sandboxDir)}`);
151456
+ __privateGet(this, _logger).info("Setting up audit repositories");
151470
151457
  for (const [repo, repoAudits] of Object.entries(audits)) {
151471
151458
  for (const audit of repoAudits) {
151472
151459
  await __privateMethod(this, _checkoutAudit, checkoutAudit_fn).call(this, repo, audit);
@@ -151504,15 +151491,7 @@ auditFile_fn = async function(file) {
151504
151491
  return file;
151505
151492
  }
151506
151493
  __privateGet(this, _logger).debug(`Checking audits for ${path4} in ${repo}`);
151507
- const matches = await __privateMethod(this, _findMatches, findMatches_fn).call(this, file);
151508
- if (!matches) {
151509
- __privateGet(this, _logger).warn(`no matches for ${path4} in ${repo}`);
151510
- } else {
151511
- __privateGet(this, _logger).debug(
151512
- `Found ${matches.length} matches for ${path4} in ${repo}`
151513
- );
151514
- file.audits = matches;
151515
- }
151494
+ file.audits = await __privateMethod(this, _findMatches, findMatches_fn).call(this, file);
151516
151495
  return file;
151517
151496
  };
151518
151497
  _findMatches = new WeakSet();
@@ -151596,7 +151575,7 @@ var SafeBase = class {
151596
151575
  _safe = new WeakMap();
151597
151576
 
151598
151577
  // src/Create2Verifier.ts
151599
- var _sandboxDir2, _auditor, _setupMetaRepos, setupMetaRepos_fn, _verifyBatchAndMeta, verifyBatchAndMeta_fn, _verifySafeTx, verifySafeTx_fn, _verify, verify_fn, _verifyCreate2Tx, verifyCreate2Tx_fn;
151578
+ var _logger2, _sandboxDir2, _auditor, _output, _ignoreInterfaces, _setupMetaRepos, setupMetaRepos_fn, _verifyBatchAndMeta, verifyBatchAndMeta_fn, _verifySafeTx, verifySafeTx_fn, _verify, verify_fn, _verifyCreate2Tx, verifyCreate2Tx_fn;
151600
151579
  var _Create2Verifier = class _Create2Verifier extends SafeBase {
151601
151580
  constructor(options) {
151602
151581
  const provider = new import_ethers3.ethers.providers.StaticJsonRpcProvider(
@@ -151617,10 +151596,17 @@ var _Create2Verifier = class _Create2Verifier extends SafeBase {
151617
151596
  __privateAdd(this, _verifySafeTx);
151618
151597
  __privateAdd(this, _verify);
151619
151598
  __privateAdd(this, _verifyCreate2Tx);
151599
+ __privateAdd(this, _logger2, log_default.getSubLogger({ name: "verifier" }));
151620
151600
  __privateAdd(this, _sandboxDir2, void 0);
151621
151601
  __privateAdd(this, _auditor, void 0);
151602
+ __privateAdd(this, _output, []);
151603
+ __privateAdd(this, _ignoreInterfaces, false);
151622
151604
  if (options.sandboxDir) {
151623
151605
  __privateSet(this, _sandboxDir2, import_node_path3.default.resolve(options.sandboxDir));
151606
+ try {
151607
+ (0, import_node_fs2.mkdirSync)(__privateGet(this, _sandboxDir2));
151608
+ } catch {
151609
+ }
151624
151610
  } else {
151625
151611
  __privateSet(this, _sandboxDir2, (0, import_node_fs2.mkdtempSync)("cr2ver", { encoding: "utf8" }));
151626
151612
  }
@@ -151636,6 +151622,8 @@ if no options are provided, will verify all pending transactions from safe multi
151636
151622
  "--sandbox-dir [dir]",
151637
151623
  "directory for temporary files, defaults to tmp dir"
151638
151624
  )
151625
+ ).addOption(
151626
+ new Option("--out-file [json]", "save output result into json file")
151639
151627
  ).addOption(
151640
151628
  new Option(
151641
151629
  "--mainnet-rpc <url>",
@@ -151658,6 +151646,11 @@ if no options are provided, will verify all pending transactions from safe multi
151658
151646
  "--skip-cleanup",
151659
151647
  "Do not clean up sandbox dir on verification start"
151660
151648
  )
151649
+ ).addOption(
151650
+ new Option(
151651
+ "--ignore-interfaces",
151652
+ "Do not warn about audits of gearbox contracts/interfaces"
151653
+ )
151661
151654
  ).action(async (opts) => {
151662
151655
  const verifier = new _Create2Verifier(opts);
151663
151656
  await verifier.verify(opts);
@@ -151665,35 +151658,53 @@ if no options are provided, will verify all pending transactions from safe multi
151665
151658
  }
151666
151659
  async verify(opts) {
151667
151660
  const { batchFile, metaFile, safeTxHashes, skipCleanup } = opts;
151668
- if (!skipCleanup) {
151669
- await __privateMethod(this, _setupMetaRepos, setupMetaRepos_fn).call(this);
151670
- await __privateGet(this, _auditor).setup();
151671
- }
151672
- if (batchFile && metaFile) {
151673
- await __privateMethod(this, _verifyBatchAndMeta, verifyBatchAndMeta_fn).call(this, batchFile, metaFile);
151674
- } else if (safeTxHashes == null ? void 0 : safeTxHashes.length) {
151675
- for (const safeTxHash of safeTxHashes) {
151676
- const tx = await this.service.getTransaction(safeTxHash);
151677
- if (!tx) {
151678
- throw new Error(`safe tx ${safeTxHash} not found`);
151661
+ __privateSet(this, _ignoreInterfaces, !!opts.ignoreInterfaces);
151662
+ try {
151663
+ if (!skipCleanup) {
151664
+ await __privateMethod(this, _setupMetaRepos, setupMetaRepos_fn).call(this);
151665
+ await __privateGet(this, _auditor).setup();
151666
+ }
151667
+ if (batchFile && metaFile) {
151668
+ await __privateMethod(this, _verifyBatchAndMeta, verifyBatchAndMeta_fn).call(this, batchFile, metaFile);
151669
+ } else if (safeTxHashes == null ? void 0 : safeTxHashes.length) {
151670
+ for (const safeTxHash of safeTxHashes) {
151671
+ const tx = await this.service.getTransaction(safeTxHash);
151672
+ if (!tx) {
151673
+ throw new Error(`safe tx ${safeTxHash} not found`);
151674
+ }
151675
+ await __privateMethod(this, _verifySafeTx, verifySafeTx_fn).call(this, tx);
151676
+ }
151677
+ } else {
151678
+ const pendingTransactions = await this.service.getPendingTransactions(
151679
+ this.safeAddress
151680
+ );
151681
+ const pending = getTransactionsToExecute(pendingTransactions);
151682
+ for (const tx of pending) {
151683
+ await __privateMethod(this, _verifySafeTx, verifySafeTx_fn).call(this, tx);
151679
151684
  }
151680
- await __privateMethod(this, _verifySafeTx, verifySafeTx_fn).call(this, tx);
151681
151685
  }
151682
- } else {
151683
- const pendingTransactions = await this.service.getPendingTransactions(
151684
- this.safeAddress
151685
- );
151686
- const pending = getTransactionsToExecute(pendingTransactions);
151687
- for (const tx of pending) {
151688
- await __privateMethod(this, _verifySafeTx, verifySafeTx_fn).call(this, tx);
151686
+ if (opts.outFile) {
151687
+ await import_promises3.default.writeFile(
151688
+ opts.outFile,
151689
+ JSON.stringify(__privateGet(this, _output), null, 2),
151690
+ "utf-8"
151691
+ );
151692
+ }
151693
+ } finally {
151694
+ if (!skipCleanup) {
151695
+ await import_promises3.default.rm(__privateGet(this, _sandboxDir2), { force: true, recursive: true });
151689
151696
  }
151690
151697
  }
151691
151698
  }
151692
151699
  };
151700
+ _logger2 = new WeakMap();
151693
151701
  _sandboxDir2 = new WeakMap();
151694
151702
  _auditor = new WeakMap();
151703
+ _output = new WeakMap();
151704
+ _ignoreInterfaces = new WeakMap();
151695
151705
  _setupMetaRepos = new WeakSet();
151696
151706
  setupMetaRepos_fn = async function() {
151707
+ __privateGet(this, _logger2).info("setting up meta repositories");
151697
151708
  await clearDir(__privateGet(this, _sandboxDir2));
151698
151709
  await Promise.all(
151699
151710
  DEPLOY_REPOS.map(
@@ -151703,6 +151714,7 @@ setupMetaRepos_fn = async function() {
151703
151714
  })
151704
151715
  )
151705
151716
  );
151717
+ __privateGet(this, _logger2).debug("meta repositories setup complete");
151706
151718
  };
151707
151719
  _verifyBatchAndMeta = new WeakSet();
151708
151720
  verifyBatchAndMeta_fn = async function(batchFile, metaFile) {
@@ -151711,24 +151723,28 @@ verifyBatchAndMeta_fn = async function(batchFile, metaFile) {
151711
151723
  const batch = JSON.parse(batchContent);
151712
151724
  const meta2 = JSON.parse(metaContent);
151713
151725
  const create2txs = getCreate2transactions(batch);
151714
- await __privateMethod(this, _verify, verify_fn).call(this, create2txs, meta2);
151726
+ const results = await __privateMethod(this, _verify, verify_fn).call(this, create2txs, meta2);
151727
+ __privateGet(this, _output).push({ results });
151715
151728
  };
151716
151729
  _verifySafeTx = new WeakSet();
151717
151730
  verifySafeTx_fn = async function(tx) {
151718
- console.info(`Verifying tx ${import_chalk.default.green(tx.safeTxHash)}...`);
151731
+ __privateGet(this, _logger2).info(`Verifying tx ${import_chalk.default.green(tx.safeTxHash)}...`);
151719
151732
  await import_promises3.default.writeFile(
151720
151733
  import_node_path3.default.resolve(__privateGet(this, _sandboxDir2), `${tx.safeTxHash}.tx.json`),
151721
151734
  JSON.stringify(tx, null, 2)
151722
151735
  );
151723
151736
  const meta2 = await getDeployMeta(tx.safeTxHash, __privateGet(this, _sandboxDir2));
151724
151737
  const create2txs = getCreate2transactions(tx);
151725
- await __privateMethod(this, _verify, verify_fn).call(this, create2txs, meta2);
151738
+ const results = await __privateMethod(this, _verify, verify_fn).call(this, create2txs, meta2);
151739
+ __privateGet(this, _output).push({ results, safeTxHash: tx.safeTxHash });
151726
151740
  };
151727
151741
  _verify = new WeakSet();
151728
151742
  verify_fn = async function(create2txs, meta2) {
151743
+ var _a2;
151729
151744
  const addressToMeta = new Map(
151730
151745
  Object.values(meta2).map((c) => [c.contractAddress, c])
151731
151746
  );
151747
+ const results = [];
151732
151748
  for (const tx2 of create2txs) {
151733
151749
  const address = create2Address(tx2);
151734
151750
  const metaContract = addressToMeta.get(address);
@@ -151738,8 +151754,37 @@ verify_fn = async function(create2txs, meta2) {
151738
151754
  );
151739
151755
  }
151740
151756
  const match = await __privateMethod(this, _verifyCreate2Tx, verifyCreate2Tx_fn).call(this, tx2, metaContract);
151741
- console.log(JSON.stringify(match, null, 2));
151757
+ results.push(match);
151758
+ if ("error" in match) {
151759
+ __privateGet(this, _logger2).error(
151760
+ `${import_chalk.default.red(match.contract)} is not verified: ${match.error}`
151761
+ );
151762
+ process.exitCode = 1;
151763
+ } else {
151764
+ if (match.match === "partial") {
151765
+ __privateGet(this, _logger2).warn(
151766
+ `${import_chalk.default.yellow(match.contract)} is a partial match`
151767
+ );
151768
+ } else {
151769
+ __privateGet(this, _logger2).debug(
151770
+ `${import_chalk.default.green(match.contract)} is a perfect match`
151771
+ );
151772
+ }
151773
+ for (const file of match.files) {
151774
+ if (file.gearbox && !((_a2 = file.audits) == null ? void 0 : _a2.length)) {
151775
+ if (__privateGet(this, _ignoreInterfaces) && file.path.startsWith("contracts/interfaces")) {
151776
+ continue;
151777
+ }
151778
+ __privateGet(this, _logger2).warn(
151779
+ `No audits for file ${import_chalk.default.yellow(file.path)} in ${import_chalk.default.yellow(
151780
+ file.repo
151781
+ )} for contract ${import_chalk.default.yellow(match.contract)}`
151782
+ );
151783
+ }
151784
+ }
151785
+ }
151742
151786
  }
151787
+ return results;
151743
151788
  };
151744
151789
  _verifyCreate2Tx = new WeakSet();
151745
151790
  verifyCreate2Tx_fn = async function(tx, meta2) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/deploy-tools",
3
3
  "description": "Gearbox deploy tools",
4
- "version": "1.1.5",
4
+ "version": "1.3.0",
5
5
  "homepage": "https://gearbox.fi",
6
6
  "keywords": [
7
7
  "gearbox"
@@ -20,7 +20,7 @@
20
20
  "license": "BUSL-1.1",
21
21
  "scripts": {
22
22
  "build": "node esbuild.config.mjs",
23
- "start": "ts-node -r dotenv/config ./src/index.ts",
23
+ "start": "tsx -r dotenv/config ./src/index.ts",
24
24
  "prepare": "husky install",
25
25
  "prettier": "prettier --write .",
26
26
  "prettier:ci": "npx prettier --check .",
@@ -31,32 +31,32 @@
31
31
  "dependencies": {},
32
32
  "devDependencies": {
33
33
  "@actions/core": "^1.10.1",
34
- "@commitlint/cli": "^17.7.2",
35
- "@commitlint/config-conventional": "^17.7.0",
34
+ "@commitlint/cli": "^17.8.0",
35
+ "@commitlint/config-conventional": "^17.8.0",
36
36
  "@ethereum-sourcify/bytecode-utils": "^1.2.0",
37
37
  "@ethereum-sourcify/lib-sourcify": "^1.3.2",
38
38
  "@gearbox-protocol/eslint-config": "2.0.0-next.0",
39
39
  "@gearbox-protocol/prettier-config": "2.0.0-next.0",
40
- "@gearbox-protocol/sdk": "^3.0.0-next.14",
40
+ "@gearbox-protocol/sdk": "^3.0.0-next.36",
41
41
  "@safe-global/api-kit": "^1.3.1",
42
42
  "@safe-global/protocol-kit": "^1.3.0",
43
43
  "@safe-global/safe-core-sdk-types": "^2.3.0",
44
44
  "@types/lodash": "^4.14.199",
45
- "@types/node": "^20.8.2",
46
- "abitype": "^0.9.9",
45
+ "@types/node": "^20.8.6",
46
+ "abitype": "^0.10.1",
47
47
  "chalk": "^4.1.2",
48
- "commander": "^11.0.0",
48
+ "commander": "^11.1.0",
49
49
  "date-fns": "^2.30.0",
50
50
  "dotenv": "^16.3.1",
51
51
  "esbuild": "^0.19.4",
52
- "eslint": "^8.50.0",
52
+ "eslint": "^8.51.0",
53
53
  "ethers": "5.7.2",
54
54
  "husky": "^8.0.3",
55
- "lint-staged": "^14.0.1",
55
+ "lint-staged": "^15.0.1",
56
56
  "lodash": "^4.17.21",
57
57
  "p-retry": "^4.6.2",
58
58
  "prettier": "^3.0.3",
59
- "ts-node": "^10.9.1",
59
+ "tsx": "^3.13.0",
60
60
  "tslog": "^4.9.2",
61
61
  "typescript": "^5.2.2"
62
62
  },