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

Side by Side Diff: utils/pub/pub.dart

Issue 11485012: Clean up command help. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Test command help with options. Created 8 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
« no previous file with comments | « utils/pub/command_version.dart ('k') | utils/tests/pub/pub_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 /** 5 /**
6 * The main entrypoint for the pub command line application. 6 * The main entrypoint for the pub command line application.
7 */ 7 */
8 library pub; 8 library pub;
9 9
10 import '../../pkg/args/lib/args.dart'; 10 import '../../pkg/args/lib/args.dart';
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 return commands; 49 return commands;
50 } 50 }
51 51
52 /** 52 /**
53 * The parser for arguments that are global to Pub rather than specific to a 53 * The parser for arguments that are global to Pub rather than specific to a
54 * single command. 54 * single command.
55 */ 55 */
56 ArgParser get pubArgParser { 56 ArgParser get pubArgParser {
57 var parser = new ArgParser(); 57 var parser = new ArgParser();
58 parser.addFlag('help', abbr: 'h', negatable: false, 58 parser.addFlag('help', abbr: 'h', negatable: false,
59 help: 'print this usage information'); 59 help: 'Print this usage information.');
60 parser.addFlag('version', negatable: false, 60 parser.addFlag('version', negatable: false,
61 help: 'print the version of pub'); 61 help: 'Print pub version.');
62 parser.addFlag('trace', 62 parser.addFlag('trace',
63 help: 'print debugging information when an error occurs'); 63 help: 'Print debugging information when an error occurs.');
64 parser.addOption('verbosity', 64 parser.addOption('verbosity',
65 help: 'control output verbosity', 65 help: 'Control output verbosity.',
66 allowed: ['normal', 'io', 'all'], 66 allowed: ['normal', 'io', 'all'],
67 allowedHelp: { 67 allowedHelp: {
68 'normal': 'errors, warnings, and user messages are shown', 68 'normal': 'Errors, warnings, and user messages are shown.',
69 'io': 'IO operations are also shown', 69 'io': 'IO operations are also shown.',
70 'all': 'all output including internal tracing messages are shown' 70 'all': 'All output including internal tracing messages are shown.'
71 }); 71 });
72 parser.addFlag('verbose', abbr: 'v', negatable: false, 72 parser.addFlag('verbose', abbr: 'v', negatable: false,
73 help: 'shortcut for "--verbosity=all"'); 73 help: 'Shortcut for "--verbosity=all"');
74 return parser; 74 return parser;
75 } 75 }
76 76
77 main() { 77 main() {
78 var globalOptions; 78 var globalOptions;
79 try { 79 try {
80 globalOptions = pubArgParser.parse(new Options().arguments); 80 globalOptions = pubArgParser.parse(new Options().arguments);
81 } on FormatException catch (e) { 81 } on FormatException catch (e) {
82 log.error(e.message); 82 log.error(e.message);
83 log.error('Run "pub help" to see available options.'); 83 log.error('Run "pub help" to see available options.');
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 * completes when the command is done or fails if the command fails. If the 290 * completes when the command is done or fails if the command fails. If the
291 * command is synchronous, it may return `null`. 291 * command is synchronous, it may return `null`.
292 */ 292 */
293 Future onRun(); 293 Future onRun();
294 294
295 /** Displays usage information for this command. */ 295 /** Displays usage information for this command. */
296 void printUsage([String description]) { 296 void printUsage([String description]) {
297 if (description == null) description = this.description; 297 if (description == null) description = this.description;
298 298
299 var buffer = new StringBuffer(); 299 var buffer = new StringBuffer();
300 buffer.add(description); 300 buffer.add('$description\n\nUsage: $usage');
301 buffer.add('');
302 buffer.add('Usage: $usage');
303 301
304 var commandUsage = commandParser.getUsage(); 302 var commandUsage = commandParser.getUsage();
305 if (!commandUsage.isEmpty) { 303 if (!commandUsage.isEmpty) {
306 buffer.add(''); 304 buffer.add('\n');
307 buffer.add(commandUsage); 305 buffer.add(commandUsage);
308 } 306 }
309 307
310 log.message(buffer.toString()); 308 log.message(buffer.toString());
311 } 309 }
312 310
313 /// Returns the appropriate exit code for [exception], falling back on 1 if no 311 /// Returns the appropriate exit code for [exception], falling back on 1 if no
314 /// appropriate exit code could be found. 312 /// appropriate exit code could be found.
315 int _chooseExitCode(exception) { 313 int _chooseExitCode(exception) {
316 if (exception is HttpException || exception is HttpParserException || 314 if (exception is HttpException || exception is HttpParserException ||
317 exception is SocketIOException || exception is PubHttpException) { 315 exception is SocketIOException || exception is PubHttpException) {
318 return exit_codes.UNAVAILABLE; 316 return exit_codes.UNAVAILABLE;
319 } else if (exception is FormatException) { 317 } else if (exception is FormatException) {
320 return exit_codes.DATA; 318 return exit_codes.DATA;
321 } else { 319 } else {
322 return 1; 320 return 1;
323 } 321 }
324 } 322 }
325 } 323 }
OLDNEW
« no previous file with comments | « utils/pub/command_version.dart ('k') | utils/tests/pub/pub_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698