| 7 | } |
| 8 | |
| 9 | function parseArgs(args: string[]): CacheOptions { |
| 10 | const options: CacheOptions = { |
| 11 | force: false, |
| 12 | headed: false, |
| 13 | directory: "./wallets-cache/", |
| 14 | }; |
| 15 | |
| 16 | for (const arg of args) { |
| 17 | if (arg === "-f" || arg === "--force") { |
| 18 | options.force = true; |
| 19 | } else if (arg === "--headed") { |
| 20 | options.headed = true; |
| 21 | } else if (arg === "-h" || arg === "--help") { |
| 22 | console.log(` |
| 23 | w3wallets cache - Build wallet caches from setup files |
| 24 | |
| 25 | USAGE: |
| 26 | npx w3wallets cache [OPTIONS] [directory] |
| 27 | |
| 28 | ARGUMENTS: |
| 29 | directory Directory containing *.cache.{ts,js} files (default: ./wallets-cache/) |
| 30 | |
| 31 | OPTIONS: |
| 32 | -f, --force Force rebuild even if cache exists |
| 33 | --headed Run browser in headed mode |
| 34 | -h, --help Show this help message |
| 35 | |
| 36 | EXAMPLES: |
| 37 | npx w3wallets cache # Build caches from ./wallets-cache/ |
| 38 | npx w3wallets cache ./tests/setups/ # Custom directory |
| 39 | npx w3wallets cache --force # Force rebuild |
| 40 | `); |
| 41 | process.exit(0); |
| 42 | } else if (!arg.startsWith("-")) { |
| 43 | options.directory = arg; |
| 44 | } else { |
| 45 | console.error(`Error: Unknown option "${arg}"`); |
| 46 | process.exit(1); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | return options; |
| 51 | } |
| 52 | |
| 53 | const options = parseArgs(process.argv.slice(2)); |
| 54 | |