* Parse CLI args and throw errors if any are invalid. * the validated URL, parsed minimum scores, and optional file path to write the report to
(args)
| 175 | * the validated URL, parsed minimum scores, and optional file path to write the report to |
| 176 | */ |
| 177 | function parseInput(args) { |
| 178 | const [url, minScoresRaw] = args; |
| 179 | |
| 180 | if (!url) { |
| 181 | onError('Invalid arguments: <url> not specified.'); |
| 182 | } else if (!minScoresRaw) { |
| 183 | onError('Invalid arguments: <min-scores> not specified.'); |
| 184 | } |
| 185 | |
| 186 | const minScores = parseMinScores(minScoresRaw || ''); |
| 187 | const unknownCategories = Object.keys(minScores).filter(cat => !AUDIT_CATEGORIES.includes(cat)); |
| 188 | const allValuesValid = Object.values(minScores).every(x => 0 <= x && x <= 1); |
| 189 | |
| 190 | if (unknownCategories.length > 0) { |
| 191 | onError( |
| 192 | `Invalid arguments: <min-scores> contains unknown category(-ies): ${unknownCategories.join( |
| 193 | ', ', |
| 194 | )}`, |
| 195 | ); |
| 196 | } else if (!allValuesValid) { |
| 197 | onError( |
| 198 | `Invalid arguments: <min-scores> has non-numeric or out-of-range values: ${minScoresRaw}`, |
| 199 | ); |
| 200 | } |
| 201 | |
| 202 | return {url, minScores}; |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * @param {string} raw is either a number (in which case it is interpreted as `all:<min-score>`) |
no test coverage detected