<commit_before>#!/usr/bin/env node

require('es6-promise').polyfill();
var fetch = require('isomorphic-fetch');
var meow = require('meow');
var getStdin = require('get-stdin');
var graphqlviz = require('./');

var cli = meow([
  'Options:',
  '  -a, --noargs     render without field arguments',
  '  -v, --verbose    print introspection result',
  '',
  'Usage',
  '  $ graphqlviz [url]',
  '      Renders dot schema from [url] endpoint',
  '',
  'Examples',
  '  $ graphqlviz https://localhost:3000 | dot -Tpng -o graph.png',
  '  $ graphqlviz http://graphql-swapi.parseapp.com | dot -Tpng | open -f -a Preview',
  '  $ cat result.json | graphqlviz | dot -Tpng | open -f -a Preview',
  ' '
], {
  alias: {
    v: 'verbose',
    a: 'noargs'
  }
});

// build render options
var opts = {
  noargs: cli.flags.noargs
};

function terminate() {
  cli.showHelp()
  // console.error(cli.help);
  // process.exit(1);
}

if (cli.input[0] === 'query') {
  process.stdout.write(JSON.stringify({query: graphqlviz.query}) + '\n');
} else if (cli.input.length === 0) {
  getStdin().then(function (stdin) {
    if (stdin.trim() === '') {
      return terminate();
    }

    try {
      console.log(graphqlviz.render(stdin, opts));
    } catch (e) {
      console.error('Invalid introspection result on stdin. Use --verbose flag to see it.');
      console.error('Error: ' + e.message);

      if (cli.flags.verbose) {
        console.error(stdin);<commit_msg>fixed missing semicolon that xo complains about<commit_after>#!/usr/bin/env node

require('es6-promise').polyfill();
var fetch = require('isomorphic-fetch');
var meow = require('meow');
var getStdin = require('get-stdin');
var graphqlviz = require('./');

var cli = meow([
  'Options:',
  '  -a, --noargs     render without field arguments',
  '  -v, --verbose    print introspection result',
  '',
  'Usage',
  '  $ graphqlviz [url]',
  '      Renders dot schema from [url] endpoint',
  '',
  'Examples',
  '  $ graphqlviz https://localhost:3000 | dot -Tpng -o graph.png',
  '  $ graphqlviz http://graphql-swapi.parseapp.com | dot -Tpng | open -f -a Preview',
  '  $ cat result.json | graphqlviz | dot -Tpng | open -f -a Preview',
  ' '
], {
  alias: {
    v: 'verbose',
    a: 'noargs'
  }
});

// build render options
var opts = {
  noargs: cli.flags.noargs
};

function terminate() {
  // cli.showHelp();
  console.error(cli.help);
  process.exit(1);
}

if (cli.input[0] === 'query') {
  process.stdout.write(JSON.stringify({query: graphqlviz.query}) + '\n');
} else if (cli.input.length === 0) {
  getStdin().then(function (stdin) {
    if (stdin.trim() === '') {
      return terminate();
    }

    try {
      console.log(graphqlviz.render(stdin, opts));
    } catch (e) {
      console.error('Invalid introspection result on stdin. Use --verbose flag to see it.');
      console.error('Error: ' + e.message);

      if (cli.flags.verbose) {
        console.error(stdin);
{'fraction_non_alphanumeric': 0.1862611073137389, 'fraction_numerical': 0.005468215994531784, 'mean_word_length': 2.9661246612466123, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5050243', 'n_tokens_mistral': 1068, 'n_tokens_neox': 1051, 'n_words': 239}