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

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

Issue 805393002: Update pub to use the new command runner API in args. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 5 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
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.serve; 5 library pub.command.serve;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:math' as math; 8 import 'dart:math' as math;
9 9
10 import 'package:barback/barback.dart'; 10 import 'package:barback/barback.dart';
11 11
12 import '../barback/asset_environment.dart'; 12 import '../barback/asset_environment.dart';
13 import '../barback/pub_package_provider.dart'; 13 import '../barback/pub_package_provider.dart';
14 import '../log.dart' as log; 14 import '../log.dart' as log;
15 import '../utils.dart'; 15 import '../utils.dart';
16 import 'barback.dart'; 16 import 'barback.dart';
17 17
18 final _arrow = getSpecial('\u2192', '=>'); 18 final _arrow = getSpecial('\u2192', '=>');
19 19
20 /// Handles the `serve` pub command. 20 /// Handles the `serve` pub command.
21 class ServeCommand extends BarbackCommand { 21 class ServeCommand extends BarbackCommand {
22 String get name => "serve";
22 String get description => 23 String get description =>
23 'Run a local web development server.\n\n' 24 'Run a local web development server.\n\n'
24 'By default, this serves "web/" and "test/", but an explicit list of \n' 25 'By default, this serves "web/" and "test/", but an explicit list of \n'
25 'directories to serve can be provided as well.'; 26 'directories to serve can be provided as well.';
26 String get usage => "pub serve [directories...]"; 27 String get invocation => "pub serve [directories...]";
27 String get docUrl => "http://dartlang.org/tools/pub/cmd/pub-serve.html"; 28 String get docUrl => "http://dartlang.org/tools/pub/cmd/pub-serve.html";
28 29
29 PubPackageProvider _provider; 30 PubPackageProvider _provider;
30 31
31 String get hostname => commandOptions['hostname']; 32 String get hostname => argResults['hostname'];
32 33
33 /// The base port for the servers. 34 /// The base port for the servers.
34 /// 35 ///
35 /// This will print a usage error and exit if the specified port is invalid. 36 /// This will print a usage error and exit if the specified port is invalid.
36 int get port => parseInt(commandOptions['port'], 'port'); 37 int get port => parseInt(argResults['port'], 'port');
37 38
38 /// The port for the admin UI. 39 /// The port for the admin UI.
39 /// 40 ///
40 /// This will print a usage error and exit if the specified port is invalid. 41 /// This will print a usage error and exit if the specified port is invalid.
41 int get adminPort { 42 int get adminPort {
42 var adminPort = commandOptions['admin-port']; 43 var adminPort = argResults['admin-port'];
43 return adminPort == null ? null : parseInt(adminPort, 'admin port'); 44 return adminPort == null ? null : parseInt(adminPort, 'admin port');
44 } 45 }
45 46
46 /// `true` if Dart entrypoints should be compiled to JavaScript. 47 /// `true` if Dart entrypoints should be compiled to JavaScript.
47 bool get useDart2JS => commandOptions['dart2js']; 48 bool get useDart2JS => argResults['dart2js'];
48 49
49 /// `true` if the admin server URL should be displayed on startup. 50 /// `true` if the admin server URL should be displayed on startup.
50 bool get logAdminUrl => commandOptions['log-admin-url']; 51 bool get logAdminUrl => argResults['log-admin-url'];
51 52
52 BarbackMode get defaultMode => BarbackMode.DEBUG; 53 BarbackMode get defaultMode => BarbackMode.DEBUG;
53 54
54 List<String> get defaultSourceDirectories => ["web", "test"]; 55 List<String> get defaultSourceDirectories => ["web", "test"];
55 56
56 /// This completer is used to keep pub running (by not completing) and to 57 /// This completer is used to keep pub running (by not completing) and to
57 /// pipe fatal errors to pub's top-level error-handling machinery. 58 /// pipe fatal errors to pub's top-level error-handling machinery.
58 final _completer = new Completer(); 59 final _completer = new Completer();
59 60
60 ServeCommand() { 61 ServeCommand() {
61 commandParser.addOption('hostname', defaultsTo: 'localhost', 62 argParser.addOption('hostname', defaultsTo: 'localhost',
62 help: 'The hostname to listen on.'); 63 help: 'The hostname to listen on.');
63 commandParser.addOption('port', defaultsTo: '8080', 64 argParser.addOption('port', defaultsTo: '8080',
64 help: 'The base port to listen on.'); 65 help: 'The base port to listen on.');
65 66
66 // TODO(rnystrom): A hidden option to print the URL that the admin server 67 // TODO(rnystrom): A hidden option to print the URL that the admin server
67 // is bound to on startup. Since this is currently only used for the Web 68 // is bound to on startup. Since this is currently only used for the Web
68 // Socket interface, we don't want to show it to users, but the tests and 69 // Socket interface, we don't want to show it to users, but the tests and
69 // Editor need this logged to know what port to bind to. 70 // Editor need this logged to know what port to bind to.
70 // Remove this (and always log) when #16954 is fixed. 71 // Remove this (and always log) when #16954 is fixed.
71 commandParser.addFlag('log-admin-url', defaultsTo: false, hide: true); 72 argParser.addFlag('log-admin-url', defaultsTo: false, hide: true);
72 73
73 // TODO(nweiz): Make this public when issue 16954 is fixed. 74 // TODO(nweiz): Make this public when issue 16954 is fixed.
74 commandParser.addOption('admin-port', hide: true); 75 argParser.addOption('admin-port', hide: true);
75 76
76 commandParser.addFlag('dart2js', defaultsTo: true, 77 argParser.addFlag('dart2js', defaultsTo: true,
77 help: 'Compile Dart to JavaScript.'); 78 help: 'Compile Dart to JavaScript.');
78 commandParser.addFlag('force-poll', defaultsTo: false, 79 argParser.addFlag('force-poll', defaultsTo: false,
79 help: 'Force the use of a polling filesystem watcher.'); 80 help: 'Force the use of a polling filesystem watcher.');
80 } 81 }
81 82
82 Future onRunTransformerCommand() async { 83 Future onRunTransformerCommand() async {
83 var port = parseInt(commandOptions['port'], 'port'); 84 var port = parseInt(argResults['port'], 'port');
84 var adminPort = commandOptions['admin-port'] == null ? null : 85 var adminPort = argResults['admin-port'] == null ? null :
85 parseInt(commandOptions['admin-port'], 'admin port'); 86 parseInt(argResults['admin-port'], 'admin port');
86 87
87 var watcherType = commandOptions['force-poll'] ? 88 var watcherType = argResults['force-poll'] ?
88 WatcherType.POLLING : WatcherType.AUTO; 89 WatcherType.POLLING : WatcherType.AUTO;
89 90
90 var environment = await AssetEnvironment.create(entrypoint, mode, 91 var environment = await AssetEnvironment.create(entrypoint, mode,
91 watcherType: watcherType, hostname: hostname, basePort: port, 92 watcherType: watcherType, hostname: hostname, basePort: port,
92 useDart2JS: useDart2JS); 93 useDart2JS: useDart2JS);
93 var directoryLength = sourceDirectories.map((dir) => dir.length) 94 var directoryLength = sourceDirectories.map((dir) => dir.length)
94 .reduce(math.max); 95 .reduce(math.max);
95 96
96 var server = await environment.startAdminServer(adminPort); 97 var server = await environment.startAdminServer(adminPort);
97 server.results.listen((_) { 98 server.results.listen((_) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 "${padRight(server.rootDirectory, directoryLength)} " 170 "${padRight(server.rootDirectory, directoryLength)} "
170 "on ${log.bold('http://$hostname:${server.port}')}"); 171 "on ${log.bold('http://$hostname:${server.port}')}");
171 } 172 }
172 173
173 /// Reports [error] and exits the server. 174 /// Reports [error] and exits the server.
174 void _fatalError(error, [stackTrace]) { 175 void _fatalError(error, [stackTrace]) {
175 if (_completer.isCompleted) return; 176 if (_completer.isCompleted) return;
176 _completer.completeError(error, stackTrace); 177 _completer.completeError(error, stackTrace);
177 } 178 }
178 } 179 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/command/run.dart ('k') | sdk/lib/_internal/pub/lib/src/command/upgrade.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698