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