import indentString from 'indent-string';
import _ from 'lodash';
import qrcodeTerminal from 'qrcode-terminal';

import { Android, ProjectSettings, Simulator } from 'xdl';

import CommandError from './CommandError';

function addOptions(program) {
  program
    .option('-a, --android', 'Opens your app in Expo on a connected Android device')
    .option(
      '-i, --ios',
      'Opens your app in Expo in a currently running iOS simulator on your computer'
    )
    .option(
      '-m, --host [mode]',
      'tunnel (default), lan, localhost. Type of host to use. "tunnel" allows you to view your link on other networks'
    )
    .option('--tunnel', 'Same as --host tunnel')
    .option('--lan', 'Same as --host lan')
    .option('--localhost', 'Same as --host localhost')
    .option('--dev', 'Turns dev flag on')
    .option('--no-dev', 'Turns dev flag off')
    .option('--strict', 'Turns strict flag on')
    .option('--no-strict', 'Turns strict flag off')
    .option('--minify', 'Turns minify flag on')
    .option('--no-minify', 'Turns minify flag off');
}

function hasBooleanArg(rawArgs, argName) {
  return _.includes(rawArgs, '--' + argName) || _.includes(rawArgs, '--no-' + argName);
}

function getBooleanArg(rawArgs, argName) {
  if (_.includes(rawArgs, '--' + argName)) {
    return true;
  } else {
    return false;
  }
}

async function optsAsync(projectDir, options) {
  var opts = await ProjectSettings.readAsync(projectDir);

  if (!!options.host + !!options.lan + !!options.localhost + !!options.tunnel > 1) {
    throw CommandError(
      'BAD_ARGS',
      'Specify at most one of --host, --tunnel, --lan, and --localhost'
    );
  }

  if (options.host) {
    opts.hostType = options.host;
  }
  if (options.tunnel) {
    opts.hostType = 'tunnel';
  }
  if (options.lan) {
    opts.hostType = 'lan';
  }
  if (options.localhost) {
    opts.hostType = 'localhost';
  }

  let rawArgs = options.parent.rawArgs;
  if (hasBooleanArg(rawArgs, 'dev')) {
    opts.dev = getBooleanArg(rawArgs, 'dev');
  }
  if (hasBooleanArg(rawArgs, 'strict')) {
    opts.strict = getBooleanArg(rawArgs, 'strict');
  }
  if (hasBooleanArg(rawArgs, 'minify')) {
    opts.minify = getBooleanArg(rawArgs, 'minify');
  }

  await ProjectSettings.setAsync(projectDir, opts);

  return opts;
}

function printQRCode(url) {
  qrcodeTerminal.generate(url, code => console.log(`${indentString(code, 2)}\n`));
}

async function handleMobileOptsAsync(projectDir, options) {
  if (options.android) {
    await Android.openProjectAsync(projectDir);
  }

  if (options.ios) {
    await Simulator.openProjectAsync(projectDir);
  }

  return !!options.android || !!options.ios;
}

export default {
  addOptions,
  handleMobileOptsAsync,
  printQRCode,
  optsAsync,
};

@@ -863,108 +863,8 @@
 f')%0A
-    .option('--strict', 'Turns strict flag on')%0A    .option('--no-strict', 'Turns strict flag off')%0A
     
@@ -1924,106 +1924,8 @@
   %7D%0A
-  if (hasBooleanArg(rawArgs, 'strict')) %7B%0A    opts.strict = getBooleanArg(rawArgs, 'strict');%0A  %7D%0A
   if

Remove `strict` project setting (#1647)