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'; | |
8 | |
9 class PreprocessorOptions { | 7 class PreprocessorOptions { |
10 /** Generate polyfill code (e.g., var, etc.) */ | 8 /** Generate polyfill code (e.g., var, etc.) */ |
11 final bool polyfill; | 9 final bool polyfill; |
12 | 10 |
13 /** Report warnings as errors. */ | 11 /** Report warnings as errors. */ |
14 final bool warningsAsErrors; | 12 final bool warningsAsErrors; |
15 | 13 |
16 /** Throw an exception on warnings (not used by command line tool). */ | 14 /** Throw an exception on warnings (not used by command line tool). */ |
17 final bool throwOnWarnings; | 15 final bool throwOnWarnings; |
18 | 16 |
(...skipping 24 matching lines...) Expand all Loading... |
43 const PreprocessorOptions( | 41 const PreprocessorOptions( |
44 {this.verbose: false, | 42 {this.verbose: false, |
45 this.checked: false, | 43 this.checked: false, |
46 this.lessSupport: true, | 44 this.lessSupport: true, |
47 this.warningsAsErrors: false, | 45 this.warningsAsErrors: false, |
48 this.throwOnErrors: false, | 46 this.throwOnErrors: false, |
49 this.throwOnWarnings: false, | 47 this.throwOnWarnings: false, |
50 this.useColors: true, | 48 this.useColors: true, |
51 this.polyfill: false, | 49 this.polyfill: false, |
52 this.inputFile}); | 50 this.inputFile}); |
53 | |
54 PreprocessorOptions.fromArgs(ArgResults args) | |
55 : warningsAsErrors = args['warnings_as_errors'], | |
56 throwOnWarnings = args['throw_on_warnings'], | |
57 throwOnErrors = args['throw_on_errors'], | |
58 verbose = args['verbose'], | |
59 checked = args['checked'], | |
60 lessSupport = args['less'], | |
61 useColors = args['colors'], | |
62 polyfill = args['polyfill'], | |
63 inputFile = args.rest.length > 0 ? args.rest[0] : null; | |
64 | |
65 // tool.dart [options...] <css file> | |
66 static PreprocessorOptions parse(List<String> arguments) { | |
67 var parser = new ArgParser() | |
68 ..addFlag('verbose', | |
69 abbr: 'v', | |
70 defaultsTo: false, | |
71 negatable: false, | |
72 help: 'Display detail info') | |
73 ..addFlag('checked', | |
74 defaultsTo: false, | |
75 negatable: false, | |
76 help: 'Validate CSS values invalid value display a warning message') | |
77 ..addFlag('less', | |
78 defaultsTo: true, | |
79 negatable: true, | |
80 help: 'Supports subset of Less syntax') | |
81 ..addFlag('suppress_warnings', | |
82 defaultsTo: true, help: 'Warnings not displayed') | |
83 ..addFlag('warnings_as_errors', | |
84 defaultsTo: false, help: 'Warning handled as errors') | |
85 ..addFlag('throw_on_errors', | |
86 defaultsTo: false, help: 'Throw on errors encountered') | |
87 ..addFlag('throw_on_warnings', | |
88 defaultsTo: false, help: 'Throw on warnings encountered') | |
89 ..addFlag('colors', | |
90 defaultsTo: true, help: 'Display errors/warnings in colored text') | |
91 ..addFlag('polyfill', | |
92 defaultsTo: false, help: 'Generate polyfill for new CSS features') | |
93 ..addFlag('help', | |
94 abbr: 'h', | |
95 defaultsTo: false, | |
96 negatable: false, | |
97 help: 'Displays this help message'); | |
98 | |
99 try { | |
100 var results = parser.parse(arguments); | |
101 if (results['help'] || results.rest.length == 0) { | |
102 showUsage(parser); | |
103 return null; | |
104 } | |
105 return new PreprocessorOptions.fromArgs(results); | |
106 } on FormatException catch (e) { | |
107 print(e.message); | |
108 showUsage(parser); | |
109 return null; | |
110 } | |
111 } | |
112 | |
113 static showUsage(parser) { | |
114 print('Usage: css [options...] input.css'); | |
115 print(parser.getUsage()); | |
116 } | |
117 } | 51 } |
OLD | NEW |