OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library csslib.src.options; |
| 6 |
| 7 import 'package:args/args.dart'; |
| 8 |
| 9 class PreprocessorOptions { |
| 10 /** Report warnings as errors. */ |
| 11 final bool warningsAsErrors; |
| 12 |
| 13 /** Throw an exception on warnings (not used by command line tool). */ |
| 14 final bool throwOnWarnings; |
| 15 |
| 16 /** Throw an exception on errors (not used by command line tool). */ |
| 17 final bool throwOnErrors; |
| 18 |
| 19 /** True to show informational messages. The `--verbose` flag. */ |
| 20 final bool verbose; |
| 21 |
| 22 /** True to show warning messages for bad CSS. The '--checked' flag. */ |
| 23 final bool checked; |
| 24 |
| 25 // TODO(terry): Add mixin support and nested rules. |
| 26 /** |
| 27 * Subset of Less commands enabled; disable with '--no-less'. |
| 28 * Less syntax supported: |
| 29 * - @name at root level statically defines variables resolved at compilation |
| 30 * time. Essentially a directive e.g., @var-name. |
| 31 */ |
| 32 final bool lessSupport; |
| 33 |
| 34 /** Whether to use colors to print messages on the terminal. */ |
| 35 final bool useColors; |
| 36 |
| 37 /** File to process by the compiler. */ |
| 38 String inputFile; |
| 39 |
| 40 // We could make this faster, if it ever matters. |
| 41 factory PreprocessorOptions() => parse(['']); |
| 42 |
| 43 PreprocessorOptions.fromArgs(ArgResults args) |
| 44 : warningsAsErrors = args['warnings_as_errors'], |
| 45 throwOnWarnings = args['throw_on_warnings'], |
| 46 throwOnErrors = args['throw_on_errors'], |
| 47 verbose = args['verbose'], |
| 48 checked = args['checked'], |
| 49 lessSupport = args['less'], |
| 50 useColors = args['colors'], |
| 51 inputFile = args.rest.length > 0 ? args.rest[0] : null; |
| 52 |
| 53 // tool.dart [options...] <css file> |
| 54 static PreprocessorOptions parse(List<String> arguments) { |
| 55 var parser = new ArgParser() |
| 56 ..addFlag('verbose', abbr: 'v', defaultsTo: false, negatable: false, |
| 57 help: 'Display detail info') |
| 58 ..addFlag('checked', defaultsTo: false, negatable: false, |
| 59 help: 'Validate CSS values invalid value display a warning message') |
| 60 ..addFlag('less', defaultsTo: true, negatable: true, |
| 61 help: 'Supports subset of Less syntax') |
| 62 ..addFlag('suppress_warnings', defaultsTo: true, |
| 63 help: 'Warnings not displayed') |
| 64 ..addFlag('warnings_as_errors', defaultsTo: false, |
| 65 help: 'Warning handled as errors') |
| 66 ..addFlag('throw_on_errors', defaultsTo: false, |
| 67 help: 'Throw on errors encountered') |
| 68 ..addFlag('throw_on_warnings', defaultsTo: false, |
| 69 help: 'Throw on warnings encountered') |
| 70 ..addFlag('colors', defaultsTo: true, |
| 71 help: 'Display errors/warnings in colored text') |
| 72 ..addFlag('help', abbr: 'h', defaultsTo: false, negatable: false, |
| 73 help: 'Displays this help message'); |
| 74 |
| 75 try { |
| 76 var results = parser.parse(arguments); |
| 77 if (results['help'] || results.rest.length == 0) { |
| 78 showUsage(parser); |
| 79 return null; |
| 80 } |
| 81 return new PreprocessorOptions.fromArgs(results); |
| 82 } on FormatException catch (e) { |
| 83 print(e.message); |
| 84 showUsage(parser); |
| 85 return null; |
| 86 } |
| 87 } |
| 88 |
| 89 static showUsage(parser) { |
| 90 print('Usage: css [options...] input.css'); |
| 91 print(parser.getUsage()); |
| 92 } |
| 93 |
| 94 } |
OLD | NEW |