| OLD | NEW |
| 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 library command_uploader; | 5 library command_uploader; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'dart:uri'; | 9 import 'dart:uri'; |
| 10 | 10 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 if (!['add', 'remove'].contains(command)) { | 51 if (!['add', 'remove'].contains(command)) { |
| 52 log.error('Unknown uploader command "$command".'); | 52 log.error('Unknown uploader command "$command".'); |
| 53 this.printUsage(); | 53 this.printUsage(); |
| 54 exit(exit_codes.USAGE); | 54 exit(exit_codes.USAGE); |
| 55 } else if (commandOptions.rest.isEmpty) { | 55 } else if (commandOptions.rest.isEmpty) { |
| 56 log.error('No uploader given for "pub uploader $command".'); | 56 log.error('No uploader given for "pub uploader $command".'); |
| 57 this.printUsage(); | 57 this.printUsage(); |
| 58 exit(exit_codes.USAGE); | 58 exit(exit_codes.USAGE); |
| 59 } | 59 } |
| 60 | 60 |
| 61 return new Future.immediate(null).then((_) { | 61 return defer(() { |
| 62 var package = commandOptions['package']; | 62 var package = commandOptions['package']; |
| 63 if (package != null) return package; | 63 if (package != null) return package; |
| 64 return Entrypoint.load(path.current, cache) | 64 return new Entrypoint(path.current, cache).root.name; |
| 65 .then((entrypoint) => entrypoint.root.name); | |
| 66 }).then((package) { | 65 }).then((package) { |
| 67 var uploader = commandOptions.rest[0]; | 66 var uploader = commandOptions.rest[0]; |
| 68 return oauth2.withClient(cache, (client) { | 67 return oauth2.withClient(cache, (client) { |
| 69 if (command == 'add') { | 68 if (command == 'add') { |
| 70 var url = server.resolve("/packages/${encodeUriComponent(package)}" | 69 var url = server.resolve("/packages/${encodeUriComponent(package)}" |
| 71 "/uploaders.json"); | 70 "/uploaders.json"); |
| 72 return client.post(url, fields: {"email": uploader}); | 71 return client.post(url, fields: {"email": uploader}); |
| 73 } else { // command == 'remove' | 72 } else { // command == 'remove' |
| 74 var url = server.resolve("/packages/${encodeUriComponent(package)}" | 73 var url = server.resolve("/packages/${encodeUriComponent(package)}" |
| 75 "/uploaders/${encodeUriComponent(uploader)}.json"); | 74 "/uploaders/${encodeUriComponent(uploader)}.json"); |
| 76 return client.delete(url); | 75 return client.delete(url); |
| 77 } | 76 } |
| 78 }); | 77 }); |
| 79 }).then(handleJsonSuccess).catchError((asyncError) { | 78 }).then(handleJsonSuccess).catchError((asyncError) { |
| 80 if (asyncError.error is! PubHttpException) throw asyncError; | 79 if (asyncError.error is! PubHttpException) throw asyncError; |
| 81 handleJsonError(asyncError.error.response); | 80 handleJsonError(asyncError.error.response); |
| 82 }); | 81 }); |
| 83 } | 82 } |
| 84 } | 83 } |
| OLD | NEW |