Index: packages/csslib/lib/css.dart |
diff --git a/packages/csslib/lib/css.dart b/packages/csslib/lib/css.dart |
index e7ef5344346dde554414289a69526bc16638546e..98c9b2a865adc06b14c21b8e3718b527dc64a891 100644 |
--- a/packages/csslib/lib/css.dart |
+++ b/packages/csslib/lib/css.dart |
@@ -2,10 +2,12 @@ |
// for details. All rights reserved. Use of this source code is governed by a |
// BSD-style license that can be found in the LICENSE file. |
+@Deprecated('Will be removed in v0.15.0') |
library css; |
import 'dart:io'; |
+import 'package:args/args.dart'; |
import 'package:path/path.dart' as path; |
import 'package:source_span/source_span.dart'; |
@@ -15,7 +17,7 @@ import 'visitor.dart'; |
void main(List<String> arguments) { |
// TODO(jmesserly): fix this to return a proper exit code |
- var options = PreprocessorOptions.parse(arguments); |
+ var options = _parseOptions(arguments); |
if (options == null) return; |
messages = new Messages(options: options); |
@@ -35,7 +37,7 @@ void _compile(String inputPath, bool verbose) { |
// Read the file. |
var filename = path.basename(inputPath); |
var contents = new File(inputPath).readAsStringSync(); |
- var file = new SourceFile(contents, url: path.toUri(inputPath)); |
+ var file = new SourceFile.fromString(contents, url: path.toUri(inputPath)); |
// Parse the CSS. |
StyleSheet tree = _time( |
@@ -78,3 +80,67 @@ void _printMessage(String message, int duration) { |
buf..write(duration)..write(' ms'); |
print(buf.toString()); |
} |
+ |
+PreprocessorOptions _fromArgs(ArgResults args) => new PreprocessorOptions( |
+ warningsAsErrors: args['warnings_as_errors'], |
+ throwOnWarnings: args['throw_on_warnings'], |
+ throwOnErrors: args['throw_on_errors'], |
+ verbose: args['verbose'], |
+ checked: args['checked'], |
+ lessSupport: args['less'], |
+ useColors: args['colors'], |
+ polyfill: args['polyfill'], |
+ inputFile: args.rest.length > 0 ? args.rest[0] : null); |
+ |
+// tool.dart [options...] <css file> |
+PreprocessorOptions _parseOptions(List<String> arguments) { |
+ var parser = new ArgParser() |
+ ..addFlag('verbose', |
+ abbr: 'v', |
+ defaultsTo: false, |
+ negatable: false, |
+ help: 'Display detail info') |
+ ..addFlag('checked', |
+ defaultsTo: false, |
+ negatable: false, |
+ help: 'Validate CSS values invalid value display a warning message') |
+ ..addFlag('less', |
+ defaultsTo: true, |
+ negatable: true, |
+ help: 'Supports subset of Less syntax') |
+ ..addFlag('suppress_warnings', |
+ defaultsTo: true, help: 'Warnings not displayed') |
+ ..addFlag('warnings_as_errors', |
+ defaultsTo: false, help: 'Warning handled as errors') |
+ ..addFlag('throw_on_errors', |
+ defaultsTo: false, help: 'Throw on errors encountered') |
+ ..addFlag('throw_on_warnings', |
+ defaultsTo: false, help: 'Throw on warnings encountered') |
+ ..addFlag('colors', |
+ defaultsTo: true, help: 'Display errors/warnings in colored text') |
+ ..addFlag('polyfill', |
+ defaultsTo: false, help: 'Generate polyfill for new CSS features') |
+ ..addFlag('help', |
+ abbr: 'h', |
+ defaultsTo: false, |
+ negatable: false, |
+ help: 'Displays this help message'); |
+ |
+ try { |
+ var results = parser.parse(arguments); |
+ if (results['help'] || results.rest.length == 0) { |
+ _showUsage(parser); |
+ return null; |
+ } |
+ return _fromArgs(results); |
+ } on FormatException catch (e) { |
+ print(e.message); |
+ _showUsage(parser); |
+ return null; |
+ } |
+} |
+ |
+void _showUsage(ArgParser parser) { |
+ print('Usage: css [options...] input.css'); |
+ print(parser.usage); |
+} |