add verbose option to show hidden args

R=vsm@google.com

Review-Url: https://codereview.chromium.org/2569783003 .
This commit is contained in:
Dan Rubel 2016-12-13 09:46:15 -05:00
parent 7ee023d2ed
commit f8cbc1423b
4 changed files with 48 additions and 39 deletions

View file

@ -74,14 +74,14 @@ class AnalyzerOptions {
declaredVariables: declaredVariables);
}
static void addArguments(ArgParser parser) {
static void addArguments(ArgParser parser, {bool hide: true}) {
parser
..addOption('summary',
abbr: 's', help: 'summary file(s) to include', allowMultiple: true)
..addOption('dart-sdk',
help: 'Dart SDK Path', defaultsTo: null, hide: true)
help: 'Dart SDK Path', defaultsTo: null, hide: hide)
..addOption('dart-sdk-summary',
help: 'Dart SDK Summary Path', defaultsTo: null, hide: true)
help: 'Dart SDK Summary Path', defaultsTo: null, hide: hide)
..addOption('package-root',
abbr: 'p', help: 'Package root to resolve "package:" imports')
..addOption('url-mapping',

View file

@ -14,22 +14,7 @@ import '../analyzer/context.dart' show AnalyzerOptions, parseDeclaredVariables;
import 'compiler.dart' show BuildUnit, CompilerOptions, ModuleCompiler;
import 'module_builder.dart';
final ArgParser _argParser = () {
var argParser = new ArgParser(allowTrailingOptions: true)
..addFlag('help', abbr: 'h', help: 'Display this message.')
..addOption('out',
abbr: 'o', allowMultiple: true, help: 'Output file (required).')
..addOption('module-root',
help: 'Root module directory.\n'
'Generated module paths are relative to this root.')
..addOption('library-root',
help: 'Root of source files.\n'
'Generated library names are relative to this root.');
addModuleFormatOptions(argParser, allowMultiple: true);
AnalyzerOptions.addArguments(argParser);
CompilerOptions.addArguments(argParser);
return argParser;
}();
bool _verbose = false;
/// Runs a single compile for dartdevc.
///
@ -41,7 +26,8 @@ int compile(List<String> args, {void printFn(Object obj)}) {
ArgResults argResults;
var declaredVars = <String, String>{};
try {
argResults = _argParser.parse(parseDeclaredVariables(args, declaredVars));
argResults = _argParser().parse(parseDeclaredVariables(args, declaredVars));
_verbose = argResults['verbose'];
} on FormatException catch (error) {
printFn('$error\n\n$_usageMessage');
return 64;
@ -80,6 +66,28 @@ $stackTrace
}
}
ArgParser _argParser({bool hide: true}) {
var argParser = new ArgParser(allowTrailingOptions: true)
..addFlag('help',
abbr: 'h',
help: 'Display this message.\n'
'Add --verbose to show hidden options.',
negatable: false)
..addFlag('verbose', abbr: 'v', help: 'Verbose output.')
..addOption('out',
abbr: 'o', allowMultiple: true, help: 'Output file (required).')
..addOption('module-root',
help: 'Root module directory.\n'
'Generated module paths are relative to this root.')
..addOption('library-root',
help: 'Root of source files.\n'
'Generated library names are relative to this root.');
addModuleFormatOptions(argParser, allowMultiple: true, hide: hide);
AnalyzerOptions.addArguments(argParser, hide: hide);
CompilerOptions.addArguments(argParser, hide: hide);
return argParser;
}
bool _changed(List<int> list1, List<int> list2) {
var length = list1.length;
if (length != list2.length) return true;
@ -198,9 +206,9 @@ String _moduleForLibrary(
return null; // unreachable
}
final _usageMessage =
String get _usageMessage =>
'Dart Development Compiler compiles Dart into a JavaScript module.'
'\n\n${_argParser.usage}';
'\n\n${_argParser(hide: !_verbose).usage}';
void _usageException(String message) {
throw new UsageException(message, _usageMessage);

View file

@ -305,19 +305,19 @@ class CompilerOptions {
bazelMapping = _parseBazelMappings(args['bazel-mapping']),
summaryOutPath = args['summary-out'];
static void addArguments(ArgParser parser) {
static void addArguments(ArgParser parser, {bool hide: true}) {
parser
..addFlag('summarize', help: 'emit an API summary file', defaultsTo: true)
..addOption('summary-extension',
help: 'file extension for Dart summary files',
defaultsTo: 'sum',
hide: true)
hide: hide)
..addFlag('source-map', help: 'emit source mapping', defaultsTo: true)
..addFlag('source-map-comment',
help: 'adds a sourceMappingURL comment to the end of the JS,\n'
'disable if using X-SourceMap header',
defaultsTo: true,
hide: true)
hide: hide)
..addFlag('inline-source-map',
help: 'emit source mapping inline', defaultsTo: false)
..addFlag('emit-metadata',
@ -327,39 +327,39 @@ class CompilerOptions {
help: 'emit Closure Compiler-friendly code (experimental)',
defaultsTo: false)
..addFlag('destructure-named-params',
help: 'Destructure named parameters', defaultsTo: false, hide: true)
help: 'Destructure named parameters', defaultsTo: false, hide: hide)
..addFlag('unsafe-force-compile',
help: 'Compile code even if it has errors. ಠ_ಠ\n'
'This has undefined behavior!',
defaultsTo: false,
hide: true)
hide: hide)
..addFlag('repl-compile',
help: 'Compile code more permissively when in REPL mode allowing '
'access to private members across library boundaries.',
help: 'Compile code more permissively when in REPL mode\n'
'allowing access to private members across library boundaries.',
defaultsTo: false,
hide: true)
hide: hide)
..addFlag('hoist-instance-creation',
help: 'Hoist the class type from generic instance creations',
defaultsTo: true,
hide: true)
hide: hide)
..addFlag('hoist-signature-types',
help: 'Hoist types from class signatures',
defaultsTo: false,
hide: true)
hide: hide)
..addFlag('name-type-tests',
help: 'Name types used in type tests', defaultsTo: true, hide: true)
help: 'Name types used in type tests', defaultsTo: true, hide: hide)
..addFlag('hoist-type-tests',
help: 'Hoist types used in type tests', defaultsTo: true, hide: true)
..addFlag('unsafe-angular2-whitelist', defaultsTo: false, hide: true)
help: 'Hoist types used in type tests', defaultsTo: true, hide: hide)
..addFlag('unsafe-angular2-whitelist', defaultsTo: false, hide: hide)
..addOption('bazel-mapping',
help:
'--bazel-mapping=genfiles/to/library.dart,to/library.dart uses \n'
'to/library.dart as the path for library.dart in source maps.',
allowMultiple: true,
splitCommas: false,
hide: true)
hide: hide)
..addOption('summary-out',
help: 'location to write the summary file', hide: true);
help: 'location to write the summary file', hide: hide);
}
static Map<String, String> _parseBazelMappings(Iterable argument) {

View file

@ -45,7 +45,8 @@ List<ModuleFormat> parseModuleFormatOption(ArgResults argResults) {
/// Adds an option to the [argParser] for choosing the module format, optionally
/// [allowMultiple] formats to be specified, with each emitted into a separate
/// file.
void addModuleFormatOptions(ArgParser argParser, {bool allowMultiple: false}) {
void addModuleFormatOptions(ArgParser argParser,
{bool allowMultiple: false, bool hide: true}) {
argParser
..addOption('modules',
help: 'module pattern to emit',
@ -68,7 +69,7 @@ void addModuleFormatOptions(ArgParser argParser, {bool allowMultiple: false}) {
help: 'emit modules that can be concatenated into one file.\n'
'Only compatible with legacy and amd module formats.',
defaultsTo: false,
hide: true);
hide: hide);
}
/// Transforms an ES6 [module] into a given module [format].