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

Side by Side Diff: sdk/lib/_internal/pub/lib/src/command.dart

Issue 122483003: Make "pub help" show global help. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 months 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 | « sdk/lib/_internal/pub/bin/pub.dart ('k') | sdk/lib/_internal/pub/lib/src/command/help.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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library pub.command; 5 library pub.command;
6 6
7 import 'dart:async';
7 import 'dart:io'; 8 import 'dart:io';
8 import 'dart:async'; 9 import 'dart:math' as math;
9 10
10 import 'package:args/args.dart'; 11 import 'package:args/args.dart';
11 import 'package:path/path.dart' as path; 12 import 'package:path/path.dart' as path;
12 import 'package:stack_trace/stack_trace.dart'; 13 import 'package:stack_trace/stack_trace.dart';
13 14
14 import 'command/build.dart'; 15 import 'command/build.dart';
15 import 'command/cache.dart'; 16 import 'command/cache.dart';
16 import 'command/get.dart'; 17 import 'command/get.dart';
17 import 'command/help.dart'; 18 import 'command/help.dart';
18 import 'command/lish.dart'; 19 import 'command/lish.dart';
19 import 'command/list_package_dirs.dart'; 20 import 'command/list_package_dirs.dart';
20 import 'command/serve.dart'; 21 import 'command/serve.dart';
21 import 'command/upgrade.dart'; 22 import 'command/upgrade.dart';
22 import 'command/uploader.dart'; 23 import 'command/uploader.dart';
23 import 'command/version.dart'; 24 import 'command/version.dart';
24 import 'entrypoint.dart'; 25 import 'entrypoint.dart';
25 import 'exit_codes.dart' as exit_codes; 26 import 'exit_codes.dart' as exit_codes;
26 import 'http.dart'; 27 import 'http.dart';
27 import 'io.dart'; 28 import 'io.dart';
28 import 'log.dart' as log; 29 import 'log.dart' as log;
29 import 'system_cache.dart'; 30 import 'system_cache.dart';
30 import 'utils.dart'; 31 import 'utils.dart';
31 32
32 /// The base class for commands for the pub executable. 33 /// The base class for commands for the pub executable.
33 abstract class PubCommand { 34 abstract class PubCommand {
34 /// The commands that pub understands. 35 /// The commands that pub understands.
35 static final Map<String, PubCommand> commands = _initCommands(); 36 static final Map<String, PubCommand> commands = _initCommands();
36 37
38 /// The top-level [ArgParser] used to parse the pub command line.
39 static final pubArgParser = _initArgParser();
40
41 /// Displays usage information for the app.
42 static void printGlobalUsage() {
43 // Build up a buffer so it shows up as a single log entry.
44 var buffer = new StringBuffer();
45 buffer.writeln('Pub is a package manager for Dart.');
46 buffer.writeln();
47 buffer.writeln('Usage: pub command [arguments]');
48 buffer.writeln();
49 buffer.writeln('Global options:');
50 buffer.writeln('${pubArgParser.getUsage()}');
nweiz 2014/01/06 23:43:20 '${}' is unnecessary here.
Bob Nystrom 2014/01/07 19:37:05 Done.
51 buffer.writeln();
52
53 // Show the public commands alphabetically.
54 var names = ordered(commands.keys.where((name) =>
55 !commands[name].aliases.contains(name) &&
56 !commands[name].hidden));
57
58 var length = names.map((name) => name.length).reduce(math.max);
59
60 buffer.writeln('Available commands:');
61 for (var name in names) {
62 buffer.writeln(' ${padRight(name, length)} '
63 '${commands[name].description}');
64 }
65
66 buffer.writeln();
67 buffer.write(
68 'Use "pub help [command]" for more information about a command.');
69 log.message(buffer.toString());
70 }
71
37 SystemCache cache; 72 SystemCache cache;
38 73
39 /// The parsed options for this command. 74 /// The parsed options for this command.
40 ArgResults commandOptions; 75 ArgResults commandOptions;
41 76
42 Entrypoint entrypoint; 77 Entrypoint entrypoint;
43 78
44 /// A one-line description of this command. 79 /// A one-line description of this command.
45 String get description; 80 String get description;
46 81
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 }; 239 };
205 240
206 for (var command in commands.values.toList()) { 241 for (var command in commands.values.toList()) {
207 for (var alias in command.aliases) { 242 for (var alias in command.aliases) {
208 commands[alias] = command; 243 commands[alias] = command;
209 } 244 }
210 } 245 }
211 246
212 return commands; 247 return commands;
213 } 248 }
249
250 /// Creates the top-level [ArgParser] used to parse the pub command line.
251 ArgParser _initArgParser() {
252 var argParser = new ArgParser();
253
254 // Add the global options.
255 argParser.addFlag('help', abbr: 'h', negatable: false,
256 help: 'Print this usage information.');
257 argParser.addFlag('version', negatable: false,
258 help: 'Print pub version.');
259 argParser.addFlag('trace',
260 help: 'Print debugging information when an error occurs.');
261 argParser.addOption('verbosity',
262 help: 'Control output verbosity.',
263 allowed: ['normal', 'io', 'solver', 'all'],
264 allowedHelp: {
265 'normal': 'Show errors, warnings, and user messages.',
266 'io': 'Also show IO operations.',
267 'solver': 'Show steps during version resolution.',
268 'all': 'Show all output including internal tracing messages.'
269 });
270 argParser.addFlag('verbose', abbr: 'v', negatable: false,
271 help: 'Shortcut for "--verbosity=all".');
272
273 // Register the commands.
274 PubCommand.commands.forEach((name, command) {
275 argParser.addCommand(name, command.commandParser);
276 });
277
278 return argParser;
279 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/pub/bin/pub.dart ('k') | sdk/lib/_internal/pub/lib/src/command/help.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698