|
28 | 28 |
|
29 | 29 | import { table, getBorderCharacters } from 'table' |
30 | 30 | import wrapAnsi from 'wrap-ansi' |
| 31 | +import yargsParse from 'yargs-parser' |
31 | 32 |
|
32 | 33 | export enum OutputFormat { |
33 | 34 | Table = 'table', |
@@ -64,6 +65,27 @@ export const fixParameters = ( |
64 | 65 | } |
65 | 66 | } |
66 | 67 |
|
| 68 | +/** |
| 69 | + * Re-parses process.argv with number parsing disabled to recover positional |
| 70 | + * arguments as strings. gluegun uses yargs-parser internally and converts hex |
| 71 | + * strings (e.g. 0x0, 0x...0010) to numbers before our commands see them, |
| 72 | + * making the conversion irreversible. Re-parsing with 'parse-numbers: false' |
| 73 | + * and taking the last N positionals (N = parametersArray.length) restores |
| 74 | + * the original strings, since gluegun strips the subcommand prefix from |
| 75 | + * parameters.array but our re-parse includes it. |
| 76 | + */ |
| 77 | +export function getRawPositionalArgs(parametersArray: unknown[]): string[] { |
| 78 | + const raw = yargsParse(process.argv.slice(2), { |
| 79 | + configuration: { 'parse-numbers': false }, |
| 80 | + }) |
| 81 | + // raw._ includes the full subcommand path (e.g. ['indexer', 'allocations', 'close', ...]) |
| 82 | + // while parameters.array has already had the command path stripped by gluegun. |
| 83 | + // Taking the last N elements (N = parameters.array.length) removes the command path |
| 84 | + // and gives us only the user-provided positional arguments. |
| 85 | + const positionals = raw._ as string[] |
| 86 | + return positionals.slice(positionals.length - parametersArray.length) |
| 87 | +} |
| 88 | + |
67 | 89 | export const formatData = ( |
68 | 90 | // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types |
69 | 91 | data: any, |
|
0 commit comments