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

Unified Diff: pkg/analysis_server/lib/driver.dart

Issue 239573002: Split off a Driver class from analysis server's HttpAnalysisServer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/lib/driver.dart
diff --git a/pkg/analysis_server/lib/driver.dart b/pkg/analysis_server/lib/driver.dart
new file mode 100644
index 0000000000000000000000000000000000000000..5fccb9d5d8ae5a71f99bdb328b6d82857acba3d7
--- /dev/null
+++ b/pkg/analysis_server/lib/driver.dart
@@ -0,0 +1,88 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library driver;
+
+import 'dart:io';
+
+import 'package:analysis_server/http_server.dart';
+import 'package:analysis_server/src/socket_server.dart';
+import 'package:args/args.dart';
+
+/**
+ * The [Driver] class represents a single running instance of the analysis
+ * server application. It is responsible for parsing command line options
+ * and starting the HTTP and/or stdio servers.
+ */
+class Driver {
+ /**
+ * The name of the application that is used to start a server.
+ */
+ static const BINARY_NAME = 'server';
+
+ /**
+ * The name of the option used to print usage information.
+ */
+ static const String HELP_OPTION = "help";
+
+ /**
+ * The name of the option used to specify the port to which the server will
+ * connect.
+ */
+ static const String PORT_OPTION = "port";
+
+ SocketServer socketServer = new SocketServer();
+
+ HttpAnalysisServer httpServer;
+
+ Driver() {
+ httpServer = new HttpAnalysisServer(socketServer);
+ }
+
+ /**
+ * Use the given command-line arguments to start this server.
+ */
+ void start(List<String> args) {
+ ArgParser parser = new ArgParser();
+ parser.addFlag(HELP_OPTION, help:
+ "print this help message without starting a server", defaultsTo: false,
+ negatable: false);
+ parser.addOption(PORT_OPTION, help:
+ "[port] the port on which the server will listen");
+
+ ArgResults results = parser.parse(args);
+ if (results[HELP_OPTION]) {
+ _printUsage(parser);
+ return;
+ }
+ if (results[PORT_OPTION] == null) {
+ print('Missing required port number');
+ print('');
+ _printUsage(parser);
+ exitCode = 1;
+ return;
+ }
+
+ try {
+ int port = int.parse(results[PORT_OPTION]);
+ httpServer.serveHttp(port);
+ } on FormatException {
+ print('Invalid port number: ${results[PORT_OPTION]}');
+ print('');
+ _printUsage(parser);
+ exitCode = 1;
+ return;
+ }
+ }
+
+ /**
+ * Print information about how to use the server.
+ */
+ void _printUsage(ArgParser parser) {
+ print('Usage: $BINARY_NAME [flags]');
+ print('');
+ print('Supported flags are:');
+ print(parser.getUsage());
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698