OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library csslib.src.options; | 5 library csslib.src.options; |
6 | 6 |
7 import 'package:args/args.dart'; | 7 import 'package:args/args.dart'; |
8 | 8 |
9 class PreprocessorOptions { | 9 class PreprocessorOptions { |
10 /** Generate polyfill code (e.g., var, etc.) */ | 10 /** Generate polyfill code (e.g., var, etc.) */ |
(...skipping 26 matching lines...) Expand all Loading... |
37 /** Whether to use colors to print messages on the terminal. */ | 37 /** Whether to use colors to print messages on the terminal. */ |
38 final bool useColors; | 38 final bool useColors; |
39 | 39 |
40 /** File to process by the compiler. */ | 40 /** File to process by the compiler. */ |
41 String inputFile; | 41 String inputFile; |
42 | 42 |
43 // We could make this faster, if it ever matters. | 43 // We could make this faster, if it ever matters. |
44 factory PreprocessorOptions() => parse(['']); | 44 factory PreprocessorOptions() => parse(['']); |
45 | 45 |
46 PreprocessorOptions.fromArgs(ArgResults args) | 46 PreprocessorOptions.fromArgs(ArgResults args) |
47 : warningsAsErrors = args['warnings_as_errors'], | 47 : warningsAsErrors = args['warnings_as_errors'], |
48 throwOnWarnings = args['throw_on_warnings'], | 48 throwOnWarnings = args['throw_on_warnings'], |
49 throwOnErrors = args['throw_on_errors'], | 49 throwOnErrors = args['throw_on_errors'], |
50 verbose = args['verbose'], | 50 verbose = args['verbose'], |
51 checked = args['checked'], | 51 checked = args['checked'], |
52 lessSupport = args['less'], | 52 lessSupport = args['less'], |
53 useColors = args['colors'], | 53 useColors = args['colors'], |
54 polyfill = args['polyfill'], | 54 polyfill = args['polyfill'], |
55 inputFile = args.rest.length > 0 ? args.rest[0] : null; | 55 inputFile = args.rest.length > 0 ? args.rest[0] : null; |
56 | 56 |
57 // tool.dart [options...] <css file> | 57 // tool.dart [options...] <css file> |
58 static PreprocessorOptions parse(List<String> arguments) { | 58 static PreprocessorOptions parse(List<String> arguments) { |
59 var parser = new ArgParser() | 59 var parser = new ArgParser() |
60 ..addFlag('verbose', abbr: 'v', defaultsTo: false, negatable: false, | 60 ..addFlag('verbose', |
| 61 abbr: 'v', |
| 62 defaultsTo: false, |
| 63 negatable: false, |
61 help: 'Display detail info') | 64 help: 'Display detail info') |
62 ..addFlag('checked', defaultsTo: false, negatable: false, | 65 ..addFlag('checked', |
| 66 defaultsTo: false, |
| 67 negatable: false, |
63 help: 'Validate CSS values invalid value display a warning message') | 68 help: 'Validate CSS values invalid value display a warning message') |
64 ..addFlag('less', defaultsTo: true, negatable: true, | 69 ..addFlag('less', |
| 70 defaultsTo: true, |
| 71 negatable: true, |
65 help: 'Supports subset of Less syntax') | 72 help: 'Supports subset of Less syntax') |
66 ..addFlag('suppress_warnings', defaultsTo: true, | 73 ..addFlag('suppress_warnings', |
67 help: 'Warnings not displayed') | 74 defaultsTo: true, help: 'Warnings not displayed') |
68 ..addFlag('warnings_as_errors', defaultsTo: false, | 75 ..addFlag('warnings_as_errors', |
69 help: 'Warning handled as errors') | 76 defaultsTo: false, help: 'Warning handled as errors') |
70 ..addFlag('throw_on_errors', defaultsTo: false, | 77 ..addFlag('throw_on_errors', |
71 help: 'Throw on errors encountered') | 78 defaultsTo: false, help: 'Throw on errors encountered') |
72 ..addFlag('throw_on_warnings', defaultsTo: false, | 79 ..addFlag('throw_on_warnings', |
73 help: 'Throw on warnings encountered') | 80 defaultsTo: false, help: 'Throw on warnings encountered') |
74 ..addFlag('colors', defaultsTo: true, | 81 ..addFlag('colors', |
75 help: 'Display errors/warnings in colored text') | 82 defaultsTo: true, help: 'Display errors/warnings in colored text') |
76 ..addFlag('polyfill', defaultsTo: false, | 83 ..addFlag('polyfill', |
77 help: 'Generate polyfill for new CSS features') | 84 defaultsTo: false, help: 'Generate polyfill for new CSS features') |
78 ..addFlag('help', abbr: 'h', defaultsTo: false, negatable: false, | 85 ..addFlag('help', |
| 86 abbr: 'h', |
| 87 defaultsTo: false, |
| 88 negatable: false, |
79 help: 'Displays this help message'); | 89 help: 'Displays this help message'); |
80 | 90 |
81 try { | 91 try { |
82 var results = parser.parse(arguments); | 92 var results = parser.parse(arguments); |
83 if (results['help'] || results.rest.length == 0) { | 93 if (results['help'] || results.rest.length == 0) { |
84 showUsage(parser); | 94 showUsage(parser); |
85 return null; | 95 return null; |
86 } | 96 } |
87 return new PreprocessorOptions.fromArgs(results); | 97 return new PreprocessorOptions.fromArgs(results); |
88 } on FormatException catch (e) { | 98 } on FormatException catch (e) { |
89 print(e.message); | 99 print(e.message); |
90 showUsage(parser); | 100 showUsage(parser); |
91 return null; | 101 return null; |
92 } | 102 } |
93 } | 103 } |
94 | 104 |
95 static showUsage(parser) { | 105 static showUsage(parser) { |
96 print('Usage: css [options...] input.css'); | 106 print('Usage: css [options...] input.css'); |
97 print(parser.getUsage()); | 107 print(parser.getUsage()); |
98 } | 108 } |
99 | |
100 } | 109 } |
OLD | NEW |