MCPcopy Index your code
hub / github.com/ampproject/amphtml / main

Function main

validator/js/nodejs/index.js:376–493  ·  view source on GitHub ↗

* Main entry point into the command line tool.

()

Source from the content-addressed store, hash-verified

374 * Main entry point into the command line tool.
375 */
376function main() {
377 program
378 .usage(
379 '[options] <fileOrUrlOrMinus...>\n\n' +
380 ' Validates the files or urls provided as arguments. If "-" is\n' +
381 ' specified, reads from stdin instead.')
382 .option(
383 '--validator_js <fileOrUrl>',
384 'The Validator Javascript.\n' +
385 ' Latest published version by default, or\n' +
386 ' dist/validator_minified.js (built with build.py)\n' +
387 ' for development.',
388 'https://cdn.ampproject.org/v0/validator_wasm.js')
389 .option(
390 '--user-agent <userAgent>', 'User agent string to use in requests.',
391 DEFAULT_USER_AGENT)
392 .option(
393 '--html_format <AMP|AMP4ADS|AMP4EMAIL>',
394 'The input format to be validated.\n' +
395 ' AMP by default.',
396 'AMP')
397 .option(
398 '--format <color|text|json>',
399 'How to format the output.\n' +
400 ' "color" displays errors/warnings/success in\n' +
401 ' red/orange/green.\n' +
402 ' "text" avoids color (e.g., useful in terminals not\n' +
403 ' supporting color).\n' +
404 ' "json" emits json corresponding to the ValidationResult\n' +
405 ' message in validator.proto.',
406 'color')
407 .parse(process.argv);
408 const opts = program.opts();
409 if (opts.length === 0) {
410 program.outputHelp();
411 process.exit(1);
412 }
413 if (opts.html_format !== 'AMP' && opts.html_format !== 'AMP4ADS' &&
414 opts.html_format !== 'AMP4EMAIL') {
415 process.stderr.write(
416 '--html_format must be set to "AMP", "AMP4ADS", or "AMP4EMAIL".\n',
417 function() {
418 process.exit(1);
419 });
420 }
421 if (opts.format !== 'color' && opts.format !== 'text' &&
422 opts.format !== 'json') {
423 process.stderr.write(
424 '--format must be set to "color", "text", or "json".\n', function() {
425 process.exit(1);
426 });
427 }
428 const inputs = [];
429 for (let ii = 0; ii < program.args.length; ii++) {
430 const item = program.args[ii];
431 if (item === '-') {
432 inputs.push(readFromStdin());
433 } else if (isHttpOrHttpsUrl(item)) {

Callers 1

cli.jsFile · 0.70

Calls 13

readFromStdinFunction · 0.85
isHttpOrHttpsUrlFunction · 0.85
readFromUrlFunction · 0.85
readFromFileFunction · 0.85
getInstanceFunction · 0.85
exitMethod · 0.80
catchMethod · 0.80
stringifyMethod · 0.80
logValidationResultFunction · 0.70
parseMethod · 0.45
writeMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected