(args: string[])
| 95 | } |
| 96 | |
| 97 | export const parseCleanDbOptions = (args: string[]): CleanDbOptions => { |
| 98 | const options: CleanDbOptions = { |
| 99 | all: false, |
| 100 | dryRun: false, |
| 101 | force: false, |
| 102 | help: false, |
| 103 | kinds: [], |
| 104 | } |
| 105 | |
| 106 | for (let index = 0; index < args.length; index++) { |
| 107 | const arg = args[index] |
| 108 | |
| 109 | if (arg === '--all') { |
| 110 | options.all = true |
| 111 | continue |
| 112 | } |
| 113 | |
| 114 | if (arg === '--dry-run') { |
| 115 | options.dryRun = true |
| 116 | continue |
| 117 | } |
| 118 | |
| 119 | if (arg === '--force') { |
| 120 | options.force = true |
| 121 | continue |
| 122 | } |
| 123 | |
| 124 | if (arg === '--help' || arg === '-h') { |
| 125 | options.help = true |
| 126 | continue |
| 127 | } |
| 128 | |
| 129 | if (matchesOption(arg, '--older-than')) { |
| 130 | const [value, nextIndex] = getOptionValue(arg, args, index) |
| 131 | options.olderThanDays = parseOlderThanDays(value) |
| 132 | index = nextIndex |
| 133 | continue |
| 134 | } |
| 135 | |
| 136 | if (matchesOption(arg, '--kinds')) { |
| 137 | const [value, nextIndex] = getOptionValue(arg, args, index) |
| 138 | options.kinds = parseKinds(value) |
| 139 | index = nextIndex |
| 140 | continue |
| 141 | } |
| 142 | |
| 143 | throw new Error(`Unknown option: ${arg}`) |
| 144 | } |
| 145 | |
| 146 | if (options.help) { |
| 147 | return options |
| 148 | } |
| 149 | |
| 150 | if (!options.all && options.olderThanDays === undefined && !options.kinds.length) { |
| 151 | throw new Error('Select a target with --all, --older-than, or --kinds') |
| 152 | } |
| 153 | |
| 154 | if (options.all && (options.olderThanDays !== undefined || options.kinds.length)) { |
no test coverage detected