parse method

bool parse(
  1. Match arg
)

Update less options from arg

Example: '--include-path=lib/lessIncludes;lib/otherIncludes'

Implementation

bool parse(Match arg) {
  if (arg == null) return setParseError('empty');
  final command = arg[1];

  switch (command) {
    case 'v':
    case 'version':
      logger
          .log('lessc ${LessIndex.version.join('.')} (Less Compiler) [Dart]');
      return false;
    case 'verbose':
      verbose = true;
      logger.verbose();
      break;
    case 's':
    case 'silent':
      silent = true;
      logger.silence();
      break;
    case 'l':
    case 'lint':
      lint = true;
      break;
    case 'strict-imports':
      strictImports = true;
      break;
    case 'h':
    case 'help':
      printUsage();
      return false;
    case 'x':
    case 'compress':
      compress = true;
      break;
    case 'insecure':
      insecure = true;
      break;
    case 'js':
      // js is not supported
      javascriptEnabled = true;
      break;
    case 'M':
    case 'depends':
      depends = true;
      break;
    case 'max-line-len':
      if (checkArgFunc(command, arg[2])) {
        try {
          maxLineLen = int.parse(arg[2]);
        } catch (e) {
          return setParseError('$command bad argument');
        }
      } else {
        return setParseError(command);
      }
      break;
    case 'no-color':
      color = false;
      break;
    case 'ie-compat':
      ieCompat = true;
      break;
    case 'no-js':
      return setParseError(
          'The "--no-js" argument is deprecated, as inline JavaScript is disabled by default and not supported.');
      break;
    case 'include-path':
      if (checkArgFunc(command, arg[2])) {
        // ; supported on windows and linux, with priority
        // : supported on windows and linux, excluding a drive letter like C:\ so C:\file:D:\file parses to 2
//          if (arg[2].startsWith('package')) {
//            paths = <String>[arg[2]];
        if (arg[2].startsWith('package') || arg[2].contains(';')) {
          paths = arg[2].split(';');
        } else {
          paths =
              arg[2].split(Platform.isWindows ? RegExp(r':(?!\\)|;') : ':');
        }

//            options.paths = match[2]
//                .split(os.type().match(/Windows/) ? /:(?!\\)|;/ : ':')
//                .map(function(p) {
//                    if (p) {
//                        return path.resolve(process.cwd(), p);  //ABSOLUTE PATH -TODO ?
//                    }
//                });
      } else {
        return setParseError(command);
      }
      break;
    case 'line-numbers':
      if (checkArgFunc(command, arg[2])) {
        dumpLineNumbers = arg[2];
      } else {
        return setParseError(command);
      }
      break;
    case 'source-map':
      sourceMap = true;
      if (arg[2] != null) sourceMapOptions.sourceMapFullFilename = arg[2];
      break;
    case 'source-map-rootpath':
      if (checkArgFunc(command, arg[2])) {
        sourceMapOptions.sourceMapRootpath = arg[2];
      } else {
        return setParseError(command);
      }
      break;
    case 'source-map-basepath':
      if (checkArgFunc(command, arg[2])) {
        sourceMapOptions.sourceMapBasepath = arg[2];
      } else {
        return setParseError(command);
      }
      break;
    case 'source-map-inline':
    case 'source-map-map-inline':
      sourceMapOptions.sourceMapFileInline = true;
      sourceMap = true;
      break;
    case 'source-map-include-source':
    case 'source-map-less-inline':
      sourceMapOptions.outputSourceFiles = true;
      break;
    case 'source-map-url':
      if (checkArgFunc(command, arg[2])) {
        sourceMapOptions.sourceMapURL = arg[2];
      } else {
        return setParseError(command);
      }
      break;
    case 'rp':
    case 'rootpath':
      if (checkArgFunc(command, arg[2])) {
        rootpath =
            arg[2].replaceAll(r'\', '/'); //arg[2] must be raw (r'something')
      } else {
        return setParseError(command);
      }
      break;
    case 'relative-urls':
      logger.warn(
          'The --relative-urls option has been deprecated. Use --rewrite-urls=all.');
      rewriteUrls = RewriteUrlsConstants.all;
      break;
    case 'ru':
    case 'rewrite-urls':
      if (arg[2] != null) {
        switch (arg[2].toLowerCase()) {
          case 'local':
            rewriteUrls = RewriteUrlsConstants.local;
            break;
          case 'off':
            rewriteUrls = RewriteUrlsConstants.off;
            break;
          case 'all':
            rewriteUrls = RewriteUrlsConstants.all;
            break;
          default:
            return exitError('Unknown rewrite-urls argument ${arg[2]}');
        }
      } else {
        rewriteUrls = RewriteUrlsConstants.all;
      }
      break;
    case 'sm':
    case 'strict-math':
      logger.warn(
          'The --strict-math option has been deprecated. Use --math=strict');
      if (checkArgFunc(command, arg[2])) {
        if (checkBooleanArg(arg[2])) math = MathConstants.strictLegacy;
      }
      break;
    case 'm':
    case 'math':
      if (checkArgFunc(command, arg[2])) {
        switch (arg[2].toLowerCase()) {
          case 'always':
            math = MathConstants.always;
            break;
          case 'parens-division':
            math = MathConstants.parensDivision;
            break;
          case 'strict':
          case 'parens':
            math = MathConstants.parens;
            break;
          case 'strict-legacy':
            math = MathConstants.strictLegacy;
            break;
          default:
            return setParseError();
        }
      } else {
        return setParseError();
      }
      break;
    case 'su':
    case 'strict-units':
      if (checkArgFunc(command, arg[2])) {
        if ((strictUnits = checkBooleanArg(arg[2])) == null) {
          return setParseError();
        }
      } else {
        return setParseError(command);
      }
      break;
    case 'global-var':
      if (checkArgFunc(command, arg[2])) {
        parseVariableOption(arg[2], globalVariables);
      } else {
        return setParseError(command);
      }
      break;
    case 'modify-var':
      if (checkArgFunc(command, arg[2])) {
        parseVariableOption(arg[2], modifyVariables);
      } else {
        return setParseError(command);
      }
      break;
    case 'url-args':
      if (checkArgFunc(command, arg[2])) {
        urlArgs = arg[2];
      } else {
        return setParseError(command);
      }
      break;
    case 'show-tree-level':
      if (checkArgFunc(command, arg[2])) {
        try {
          showTreeLevel = int.parse(arg[2]);
        } catch (e) {
          return setParseError('$command bad argument');
        }
      } else {
        return setParseError(command);
      }
      break;
    case 'log-level':
      if (checkArgFunc(command, arg[2])) {
        try {
          logLevel = int.parse(arg[2]);
          logger.setLogLevel(logLevel);
        } catch (e) {
          return setParseError('$command bad argument');
        }
      } else {
        return setParseError(command);
      }
      break;
    case 'banner':
      if (checkArgFunc(command, arg[2])) {
        banner = arg[2];
      } else {
        return setParseError(command);
      }
      break;
    case 'plugin':
      final Match splitupArg = pluginRe.firstMatch(arg[2]);
      final name = splitupArg[1];
      final pluginOptions = splitupArg[3];
      final plugin = pluginLoader.tryLoadPlugin(name, pluginOptions);

      if (plugin != null) {
        plugins.add(plugin);
      } else {
        return exitError(
            'Unable to load plugin $name please make sure that it is installed\n');
      }
      break;
    default:
      final plugin =
          pluginLoader.tryLoadPlugin('less-plugin-$command', arg[2]);
      if (plugin != null) {
        plugins.add(plugin);
      } else {
        return exitError(
            'Unable to interpret argument $command\nif it is a plugin (less-plugin-$command), make sure that it is installed\n');
      }
  }
  return true;
}