| 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 /** Generate polyfill code (e.g., var, etc.) */ | |
| 11 final bool polyfill; | |
| 12 | |
| 13 /** Report warnings as errors. */ | |
| 14 final bool warningsAsErrors; | |
| 15 | |
| 16 /** Throw an exception on warnings (not used by command line tool). */ | |
| 17 final bool throwOnWarnings; | |
| 18 | |
| 19 /** Throw an exception on errors (not used by command line tool). */ | |
| 20 final bool throwOnErrors; | |
| 21 | |
| 22 /** True to show informational messages. The `--verbose` flag. */ | |
| 23 final bool verbose; | |
| 24 | |
| 25 /** True to show warning messages for bad CSS. The '--checked' flag. */ | |
| 26 final bool checked; | |
| 27 | |
| 28 // TODO(terry): Add mixin support and nested rules. | |
| 29 /** | |
| 30 * Subset of Less commands enabled; disable with '--no-less'. | |
| 31 * Less syntax supported: | |
| 32 * - @name at root level statically defines variables resolved at compilation | |
| 33 * time. Essentially a directive e.g., @var-name. | |
| 34 */ | |
| 35 final bool lessSupport; | |
| 36 | |
| 37 /** Whether to use colors to print messages on the terminal. */ | |
| 38 final bool useColors; | |
| 39 | |
| 40 /** File to process by the compiler. */ | |
| 41 final String inputFile; | |
| 42 | |
| 43 const PreprocessorOptions({this.verbose: false, this.checked: false, | |
| 44 this.lessSupport: true, this.warningsAsErrors: false, | |
| 45 this.throwOnErrors: false, this.throwOnWarnings: false, | |
| 46 this.useColors: true, this.polyfill: false, this.inputFile}); | |
| 47 | |
| 48 PreprocessorOptions.fromArgs(ArgResults args) | |
| 49 : warningsAsErrors = args['warnings_as_errors'], | |
| 50 throwOnWarnings = args['throw_on_warnings'], | |
| 51 throwOnErrors = args['throw_on_errors'], | |
| 52 verbose = args['verbose'], | |
| 53 checked = args['checked'], | |
| 54 lessSupport = args['less'], | |
| 55 useColors = args['colors'], | |
| 56 polyfill = args['polyfill'], | |
| 57 inputFile = args.rest.length > 0 ? args.rest[0] : null; | |
| 58 | |
| 59 // tool.dart [options...] <css file> | |
| 60 static PreprocessorOptions parse(List<String> arguments) { | |
| 61 var parser = new ArgParser() | |
| 62 ..addFlag('verbose', | |
| 63 abbr: 'v', | |
| 64 defaultsTo: false, | |
| 65 negatable: false, | |
| 66 help: 'Display detail info') | |
| 67 ..addFlag('checked', | |
| 68 defaultsTo: false, | |
| 69 negatable: false, | |
| 70 help: 'Validate CSS values invalid value display a warning message') | |
| 71 ..addFlag('less', | |
| 72 defaultsTo: true, | |
| 73 negatable: true, | |
| 74 help: 'Supports subset of Less syntax') | |
| 75 ..addFlag('suppress_warnings', | |
| 76 defaultsTo: true, help: 'Warnings not displayed') | |
| 77 ..addFlag('warnings_as_errors', | |
| 78 defaultsTo: false, help: 'Warning handled as errors') | |
| 79 ..addFlag('throw_on_errors', | |
| 80 defaultsTo: false, help: 'Throw on errors encountered') | |
| 81 ..addFlag('throw_on_warnings', | |
| 82 defaultsTo: false, help: 'Throw on warnings encountered') | |
| 83 ..addFlag('colors', | |
| 84 defaultsTo: true, help: 'Display errors/warnings in colored text') | |
| 85 ..addFlag('polyfill', | |
| 86 defaultsTo: false, help: 'Generate polyfill for new CSS features') | |
| 87 ..addFlag('help', | |
| 88 abbr: 'h', | |
| 89 defaultsTo: false, | |
| 90 negatable: false, | |
| 91 help: 'Displays this help message'); | |
| 92 | |
| 93 try { | |
| 94 var results = parser.parse(arguments); | |
| 95 if (results['help'] || results.rest.length == 0) { | |
| 96 showUsage(parser); | |
| 97 return null; | |
| 98 } | |
| 99 return new PreprocessorOptions.fromArgs(results); | |
| 100 } on FormatException catch (e) { | |
| 101 print(e.message); | |
| 102 showUsage(parser); | |
| 103 return null; | |
| 104 } | |
| 105 } | |
| 106 | |
| 107 static showUsage(parser) { | |
| 108 print('Usage: css [options...] input.css'); | |
| 109 print(parser.getUsage()); | |
| 110 } | |
| 111 } | |
| OLD | NEW |