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

Side by Side Diff: pkg/dev_compiler/lib/src/compiler/command.dart

Issue 2569783003: add verbose option to show hidden args (Closed)
Patch Set: merge Created 4 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
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 import 'dart:io'; 5 import 'dart:io';
6 import 'package:analyzer/src/generated/source.dart' show Source; 6 import 'package:analyzer/src/generated/source.dart' show Source;
7 import 'package:analyzer/src/summary/package_bundle_reader.dart' 7 import 'package:analyzer/src/summary/package_bundle_reader.dart'
8 show InSummarySource; 8 show InSummarySource;
9 import 'package:args/args.dart' show ArgParser, ArgResults; 9 import 'package:args/args.dart' show ArgParser, ArgResults;
10 import 'package:args/command_runner.dart' show UsageException; 10 import 'package:args/command_runner.dart' show UsageException;
11 import 'package:path/path.dart' as path; 11 import 'package:path/path.dart' as path;
12 12
13 import '../analyzer/context.dart' show AnalyzerOptions, parseDeclaredVariables; 13 import '../analyzer/context.dart' show AnalyzerOptions, parseDeclaredVariables;
14 import 'compiler.dart' show BuildUnit, CompilerOptions, ModuleCompiler; 14 import 'compiler.dart' show BuildUnit, CompilerOptions, ModuleCompiler;
15 import 'module_builder.dart'; 15 import 'module_builder.dart';
16 16
17 final ArgParser _argParser = () { 17 bool _verbose = false;
18 var argParser = new ArgParser(allowTrailingOptions: true)
19 ..addFlag('help', abbr: 'h', help: 'Display this message.')
20 ..addOption('out',
21 abbr: 'o', allowMultiple: true, help: 'Output file (required).')
22 ..addOption('module-root',
23 help: 'Root module directory.\n'
24 'Generated module paths are relative to this root.')
25 ..addOption('library-root',
26 help: 'Root of source files.\n'
27 'Generated library names are relative to this root.');
28 addModuleFormatOptions(argParser, allowMultiple: true);
29 AnalyzerOptions.addArguments(argParser);
30 CompilerOptions.addArguments(argParser);
31 return argParser;
32 }();
33 18
34 /// Runs a single compile for dartdevc. 19 /// Runs a single compile for dartdevc.
35 /// 20 ///
36 /// This handles argument parsing, usage, error handling. 21 /// This handles argument parsing, usage, error handling.
37 /// See bin/dartdevc.dart for the actual entry point, which includes Bazel 22 /// See bin/dartdevc.dart for the actual entry point, which includes Bazel
38 /// worker support. 23 /// worker support.
39 int compile(List<String> args, {void printFn(Object obj)}) { 24 int compile(List<String> args, {void printFn(Object obj)}) {
40 printFn ??= print; 25 printFn ??= print;
41 ArgResults argResults; 26 ArgResults argResults;
42 var declaredVars = <String, String>{}; 27 var declaredVars = <String, String>{};
43 try { 28 try {
44 argResults = _argParser.parse(parseDeclaredVariables(args, declaredVars)); 29 argResults = _argParser().parse(parseDeclaredVariables(args, declaredVars));
30 _verbose = argResults['verbose'];
45 } on FormatException catch (error) { 31 } on FormatException catch (error) {
46 printFn('$error\n\n$_usageMessage'); 32 printFn('$error\n\n$_usageMessage');
47 return 64; 33 return 64;
48 } 34 }
49 try { 35 try {
50 _compile(argResults, declaredVars, printFn); 36 _compile(argResults, declaredVars, printFn);
51 return 0; 37 return 0;
52 } on UsageException catch (error) { 38 } on UsageException catch (error) {
53 // Incorrect usage, input file not found, etc. 39 // Incorrect usage, input file not found, etc.
54 printFn(error); 40 printFn(error);
(...skipping 18 matching lines...) Expand all
73 dartdevc arguments: ${args.join(' ')} 59 dartdevc arguments: ${args.join(' ')}
74 dart --version: ${Platform.version} 60 dart --version: ${Platform.version}
75 ``` 61 ```
76 $error 62 $error
77 $stackTrace 63 $stackTrace
78 ```'''); 64 ```''');
79 return 70; 65 return 70;
80 } 66 }
81 } 67 }
82 68
69 ArgParser _argParser({bool hide: true}) {
70 var argParser = new ArgParser(allowTrailingOptions: true)
71 ..addFlag('help',
72 abbr: 'h',
73 help: 'Display this message.\n'
74 'Add --verbose to show hidden options.',
75 negatable: false)
76 ..addFlag('verbose', abbr: 'v', help: 'Verbose output.')
77 ..addOption('out',
78 abbr: 'o', allowMultiple: true, help: 'Output file (required).')
79 ..addOption('module-root',
80 help: 'Root module directory.\n'
81 'Generated module paths are relative to this root.')
82 ..addOption('library-root',
83 help: 'Root of source files.\n'
84 'Generated library names are relative to this root.');
85 addModuleFormatOptions(argParser, allowMultiple: true, hide: hide);
86 AnalyzerOptions.addArguments(argParser, hide: hide);
87 CompilerOptions.addArguments(argParser, hide: hide);
88 return argParser;
89 }
90
83 bool _changed(List<int> list1, List<int> list2) { 91 bool _changed(List<int> list1, List<int> list2) {
84 var length = list1.length; 92 var length = list1.length;
85 if (length != list2.length) return true; 93 if (length != list2.length) return true;
86 for (var i = 0; i < length; ++i) { 94 for (var i = 0; i < length; ++i) {
87 if (list1[i] != list2[i]) return true; 95 if (list1[i] != list2[i]) return true;
88 } 96 }
89 return false; 97 return false;
90 } 98 }
91 99
92 void _compile(ArgResults argResults, Map<String, String> declaredVars, 100 void _compile(ArgResults argResults, Map<String, String> declaredVars,
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 'directory $moduleRoot'); 199 'directory $moduleRoot');
192 } 200 }
193 201
194 _usageException( 202 _usageException(
195 'Imported file "${source.uri}" was not found as a summary or source ' 203 'Imported file "${source.uri}" was not found as a summary or source '
196 'file. Please pass in either the summary or the source file ' 204 'file. Please pass in either the summary or the source file '
197 'for this import.'); 205 'for this import.');
198 return null; // unreachable 206 return null; // unreachable
199 } 207 }
200 208
201 final _usageMessage = 209 String get _usageMessage =>
202 'Dart Development Compiler compiles Dart into a JavaScript module.' 210 'Dart Development Compiler compiles Dart into a JavaScript module.'
203 '\n\n${_argParser.usage}'; 211 '\n\n${_argParser(hide: !_verbose).usage}';
204 212
205 void _usageException(String message) { 213 void _usageException(String message) {
206 throw new UsageException(message, _usageMessage); 214 throw new UsageException(message, _usageMessage);
207 } 215 }
208 216
209 /// Thrown when the input source code has errors. 217 /// Thrown when the input source code has errors.
210 class CompileErrorException implements Exception { 218 class CompileErrorException implements Exception {
211 toString() => '\nPlease fix all errors before compiling (warnings are okay).'; 219 toString() => '\nPlease fix all errors before compiling (warnings are okay).';
212 } 220 }
OLDNEW
« no previous file with comments | « pkg/dev_compiler/lib/src/analyzer/context.dart ('k') | pkg/dev_compiler/lib/src/compiler/compiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698