<commit_before>#! /usr/bin/env node
var serveit2 = require('./index');
var options = {};

if (process.argv[2]) options.port = process.argv[2];
serveit2(options, function (port) {
  console.log('Server listening at: https://localhost:%s', port);
});<commit_msg>feat(cli): Add advanced CLI options<commit_after>#! /usr/bin/env node
var serveit2 = require('./index');
var meow = require('meow');
var fs = require('fs');

var options = {};
var rootDir;
var config;

// check if we have a config file
try {
  config = JSON.parse(fs.readFileSync(process.cwd() + '/.serveit2'));
} catch (e) {
  if (e.toString() === 'SyntaxError: Unexpected end of input') {
    config = 'Invalid json';
  }
  if (e.code === 'ENOENT') {
    config = 'Not found';
  }
}

if (typeof config === 'object' && config.root) {
  rootDir = config.root;
  if (rootDir[0] !== '/') rootDir = process.cwd + '/' + rootDir;
}

var cli = meow(
  '     Usage\n' +
  '     -----\n' +
  '     $ serveit2 [port]\n' +
  '\n' +
  '     Options\n' +
  '     -------\n' +
  '     -g, --gzip Turn on gzipping\n' +
  '     -q, --quiet Turn off logger output\n' +
  '     -x, --no-conf Do not parse config file (ignore .serveit2 config file in the root public dir)\n' +
  '     -r, --root Server root directory (defaults to `cwd`)\n' +
  '\n' +
  '     Examples\n' +
  '     --------\n' +
  '     $ serveit2\n' +
  '     $ serveit2 7000 -g -r=/User/something/somewhere\n' +
  '\n' +
  '     Info\n' +
  '     ----\n' +
  (typeof config === 'string' ? '     Config error: ' + config + '\n' : '') +
  (typeof config === 'object' && config.root ? '     Root directory with config applied: ' + rootDir + '\n' : '') +
  '     Root directory without config applied would be: `' + process.cwd() + '/`',
  {
    alias: {
      g: 'gzip',
      q: 'quiet',
      x: 'no-conf',
      r: 'root',
    },
  }
);

if (cli.flags.x) {
  config = {};
}

options.port = cli.input[0] || config.port;
options.gzip = cli.flags.g || config.gzip || false;
options.push = config.push || {};
options.quiet = cli.flags.q || config.quiet || false;
options.root = cli.flags.r || config.root;

//console.log(cli.input[0], cli.flags);
serveit2(options, function (port) {
  console.log('Server listening at: https://localhost:%s', port);
});
{'fraction_non_alphanumeric': 0.21204072598494908, 'fraction_numerical': 0.00796812749003984, 'mean_word_length': 2.5646687697160884, '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': '6654324', 'n_tokens_mistral': 839, 'n_tokens_neox': 828, 'n_words': 203}