| OLD | NEW |
| 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:io'; | 6 import 'dart:io'; |
| 7 import 'dart:math' as math; | 7 import 'dart:math' as math; |
| 8 | 8 |
| 9 import 'package:args/args.dart'; | 9 import 'package:args/args.dart'; |
| 10 import 'package:path/path.dart' as path; | 10 import 'package:path/path.dart' as path; |
| 11 | 11 |
| 12 import '../lib/src/command.dart'; | 12 import '../lib/src/command.dart'; |
| 13 import '../lib/src/exit_codes.dart' as exit_codes; | 13 import '../lib/src/exit_codes.dart' as exit_codes; |
| 14 import '../lib/src/io.dart'; | 14 import '../lib/src/io.dart'; |
| 15 import '../lib/src/log.dart' as log; | 15 import '../lib/src/log.dart' as log; |
| 16 import '../lib/src/sdk.dart' as sdk; | 16 import '../lib/src/sdk.dart' as sdk; |
| 17 import '../lib/src/utils.dart'; | 17 import '../lib/src/utils.dart'; |
| 18 | 18 |
| 19 final pubArgParser = initArgParser(); | 19 final pubArgParser = initArgParser(); |
| 20 | 20 |
| 21 void main() { | 21 void main() { |
| 22 ArgResults options; | 22 ArgResults options; |
| 23 | 23 |
| 24 try { | 24 try { |
| 25 options = pubArgParser.parse(new Options().arguments); | 25 options = pubArgParser.parse(new Options().arguments); |
| 26 } on FormatException catch (e) { | 26 } on FormatException catch (e) { |
| 27 log.error(e.message); | 27 log.error(e.message); |
| 28 log.error('Run "pub help" to see available options.'); | 28 log.error('Run "pub help" to see available options.'); |
| 29 exit(exit_codes.USAGE); | 29 flushThenExit(exit_codes.USAGE); |
| 30 return; |
| 30 } | 31 } |
| 31 | 32 |
| 32 if (options['version']) { | 33 if (options['version']) { |
| 33 log.message('Pub ${sdk.version}'); | 34 log.message('Pub ${sdk.version}'); |
| 34 return; | 35 return; |
| 35 } | 36 } |
| 36 | 37 |
| 37 if (options['help']) { | 38 if (options['help']) { |
| 38 printUsage(); | 39 printUsage(); |
| 39 return; | 40 return; |
| 40 } | 41 } |
| 41 | 42 |
| 42 if (options.command == null) { | 43 if (options.command == null) { |
| 43 if (options.rest.isEmpty) { | 44 if (options.rest.isEmpty) { |
| 44 // No command was chosen. | 45 // No command was chosen. |
| 45 printUsage(); | 46 printUsage(); |
| 46 } else { | 47 } else { |
| 47 log.error('Could not find a command named "${options.rest[0]}".'); | 48 log.error('Could not find a command named "${options.rest[0]}".'); |
| 48 log.error('Run "pub help" to see available commands.'); | 49 log.error('Run "pub help" to see available commands.'); |
| 49 exit(exit_codes.USAGE); | 50 flushThenExit(exit_codes.USAGE); |
| 51 return; |
| 50 } | 52 } |
| 51 return; | 53 return; |
| 52 } | 54 } |
| 53 | 55 |
| 54 if (options['trace']) { | 56 if (options['trace']) { |
| 55 log.recordTranscript(); | 57 log.recordTranscript(); |
| 56 } | 58 } |
| 57 | 59 |
| 58 switch (options['verbosity']) { | 60 switch (options['verbosity']) { |
| 59 case 'normal': log.showNormal(); break; | 61 case 'normal': log.showNormal(); break; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 121 |
| 120 /// Checks that pub is running on a supported platform. If it isn't, it prints | 122 /// Checks that pub is running on a supported platform. If it isn't, it prints |
| 121 /// an error message and exits. Completes when the validation is done. | 123 /// an error message and exits. Completes when the validation is done. |
| 122 Future validatePlatform() { | 124 Future validatePlatform() { |
| 123 return new Future.sync(() { | 125 return new Future.sync(() { |
| 124 if (Platform.operatingSystem != 'windows') return; | 126 if (Platform.operatingSystem != 'windows') return; |
| 125 | 127 |
| 126 return runProcess('ver', []).then((result) { | 128 return runProcess('ver', []).then((result) { |
| 127 if (result.stdout.join('\n').contains('XP')) { | 129 if (result.stdout.join('\n').contains('XP')) { |
| 128 log.error('Sorry, but pub is not supported on Windows XP.'); | 130 log.error('Sorry, but pub is not supported on Windows XP.'); |
| 129 exit(exit_codes.USAGE); | 131 return flushThenExit(exit_codes.USAGE); |
| 130 } | 132 } |
| 131 }); | 133 }); |
| 132 }); | 134 }); |
| 133 } | 135 } |
| 134 | 136 |
| 135 /// Displays usage information for the app. | 137 /// Displays usage information for the app. |
| 136 void printUsage([String description = 'Pub is a package manager for Dart.']) { | 138 void printUsage([String description = 'Pub is a package manager for Dart.']) { |
| 137 // Build up a buffer so it shows up as a single log entry. | 139 // Build up a buffer so it shows up as a single log entry. |
| 138 var buffer = new StringBuffer(); | 140 var buffer = new StringBuffer(); |
| 139 buffer.write(description); | 141 buffer.write(description); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 164 for (var name in names) { | 166 for (var name in names) { |
| 165 buffer.write(' ${padRight(name, length)} ' | 167 buffer.write(' ${padRight(name, length)} ' |
| 166 '${PubCommand.commands[name].description}\n'); | 168 '${PubCommand.commands[name].description}\n'); |
| 167 } | 169 } |
| 168 | 170 |
| 169 buffer.write('\n'); | 171 buffer.write('\n'); |
| 170 buffer.write( | 172 buffer.write( |
| 171 'Use "pub help [command]" for more information about a command.'); | 173 'Use "pub help [command]" for more information about a command.'); |
| 172 log.message(buffer.toString()); | 174 log.message(buffer.toString()); |
| 173 } | 175 } |
| OLD | NEW |