Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(562)

Side by Side Diff: observatory_pub_packages/csslib/src/options.dart

Issue 816693004: Add observatory_pub_packages snapshot to third_party (Closed) Base URL: http://dart.googlecode.com/svn/third_party/
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 String inputFile;
42
43 // We could make this faster, if it ever matters.
44 factory PreprocessorOptions() => parse(['']);
45
46 PreprocessorOptions.fromArgs(ArgResults args)
47 : warningsAsErrors = args['warnings_as_errors'],
48 throwOnWarnings = args['throw_on_warnings'],
49 throwOnErrors = args['throw_on_errors'],
50 verbose = args['verbose'],
51 checked = args['checked'],
52 lessSupport = args['less'],
53 useColors = args['colors'],
54 polyfill = args['polyfill'],
55 inputFile = args.rest.length > 0 ? args.rest[0] : null;
56
57 // tool.dart [options...] <css file>
58 static PreprocessorOptions parse(List<String> arguments) {
59 var parser = new ArgParser()
60 ..addFlag('verbose', abbr: 'v', defaultsTo: false, negatable: false,
61 help: 'Display detail info')
62 ..addFlag('checked', defaultsTo: false, negatable: false,
63 help: 'Validate CSS values invalid value display a warning message')
64 ..addFlag('less', defaultsTo: true, negatable: true,
65 help: 'Supports subset of Less syntax')
66 ..addFlag('suppress_warnings', defaultsTo: true,
67 help: 'Warnings not displayed')
68 ..addFlag('warnings_as_errors', defaultsTo: false,
69 help: 'Warning handled as errors')
70 ..addFlag('throw_on_errors', defaultsTo: false,
71 help: 'Throw on errors encountered')
72 ..addFlag('throw_on_warnings', defaultsTo: false,
73 help: 'Throw on warnings encountered')
74 ..addFlag('colors', defaultsTo: true,
75 help: 'Display errors/warnings in colored text')
76 ..addFlag('polyfill', defaultsTo: false,
77 help: 'Generate polyfill for new CSS features')
78 ..addFlag('help', abbr: 'h', defaultsTo: false, negatable: false,
79 help: 'Displays this help message');
80
81 try {
82 var results = parser.parse(arguments);
83 if (results['help'] || results.rest.length == 0) {
84 showUsage(parser);
85 return null;
86 }
87 return new PreprocessorOptions.fromArgs(results);
88 } on FormatException catch (e) {
89 print(e.message);
90 showUsage(parser);
91 return null;
92 }
93 }
94
95 static showUsage(parser) {
96 print('Usage: css [options...] input.css');
97 print(parser.getUsage());
98 }
99
100 }
OLDNEW
« no previous file with comments | « observatory_pub_packages/csslib/src/messages.dart ('k') | observatory_pub_packages/csslib/src/polyfill.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698