File tree Expand file tree Collapse file tree 5 files changed +73
-0
lines changed Expand file tree Collapse file tree 5 files changed +73
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
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.
4
+
5
+ import 'dart:async' ;
6
+
7
+ import '../command.dart' ;
8
+ import '../oauth2.dart' as oauth2;
9
+
10
+ /// Handles the `logout` pub command.
11
+ class LogoutCommand extends PubCommand {
12
+ String get name => "logout" ;
13
+ String get description => 'Log out of pub.dartlang.org.' ;
14
+ String get invocation => 'pub logout' ;
15
+
16
+ LogoutCommand ();
17
+
18
+ Future run () async {
19
+ oauth2.logout (cache);
20
+ }
21
+ }
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import 'command/get.dart';
18
18
import 'command/global.dart' ;
19
19
import 'command/lish.dart' ;
20
20
import 'command/list_package_dirs.dart' ;
21
+ import 'command/logout.dart' ;
21
22
import 'command/run.dart' ;
22
23
import 'command/serve.dart' ;
23
24
import 'command/upgrade.dart' ;
@@ -104,6 +105,7 @@ class PubCommandRunner extends CommandRunner {
104
105
addCommand (ServeCommand ());
105
106
addCommand (UpgradeCommand ());
106
107
addCommand (UploaderCommand ());
108
+ addCommand (LogoutCommand ());
107
109
addCommand (VersionCommand ());
108
110
}
109
111
Original file line number Diff line number Diff line change @@ -73,6 +73,19 @@ void _clearCredentials(SystemCache cache) {
73
73
if (entryExists (credentialsFile)) deleteEntry (credentialsFile);
74
74
}
75
75
76
+ /// Try to delete the cached credentials.
77
+ void logout (SystemCache cache) {
78
+ var credentialsFile = _credentialsFile (cache);
79
+ if (entryExists (_credentialsFile (cache))) {
80
+ log.message ("Logging out of pub.dartlang.org." );
81
+ log.message ("Deleting $credentialsFile " );
82
+ _clearCredentials (cache);
83
+ } else {
84
+ log.message (
85
+ "No existing credentials file $credentialsFile . Cannot log out." );
86
+ }
87
+ }
88
+
76
89
/// Asynchronously passes an OAuth2 [Client] to [fn] , and closes the client when
77
90
/// the [Future] returned by [fn] completes.
78
91
///
Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
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.
4
+
5
+ import 'package:shelf_test_handler/shelf_test_handler.dart' ;
6
+ import 'package:test/test.dart' ;
7
+
8
+ import '../descriptor.dart' as d;
9
+ import '../test_pub.dart' ;
10
+
11
+ main () {
12
+ test ('with an existing credentials.json, deletes it.' , () async {
13
+ var server = await ShelfTestServer .create ();
14
+ await d
15
+ .credentialsFile (server, 'access token' ,
16
+ refreshToken: 'refresh token' ,
17
+ expiration: DateTime .now ().add (Duration (hours: 1 )))
18
+ .create ();
19
+
20
+ await runPub (
21
+ args: ['logout' ],
22
+ output: contains ('Logging out of pub.dartlang.org.' ),
23
+ exitCode: 0 );
24
+
25
+ await d.dir (cachePath, [d.nothing ('credentials.json' )]).validate ();
26
+ });
27
+ test ('with no existing credentials.json, notifies.' , () async {
28
+ await d.dir (cachePath, [d.nothing ('credentials.json' )]).create ();
29
+ await runPub (
30
+ args: ['logout' ],
31
+ output: contains ('No existing credentials file' ),
32
+ exitCode: 0 );
33
+
34
+ await d.dir (cachePath, [d.nothing ('credentials.json' )]).validate ();
35
+ });
36
+ }
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ main() {
35
35
get Get the current package's dependencies.
36
36
global Work with global packages.
37
37
help Display help information for pub.
38
+ logout Log out of pub.dartlang.org.
38
39
publish Publish the current package to pub.dartlang.org.
39
40
run Run an executable from a package.
40
41
upgrade Upgrade the current package's dependencies to latest versions.
You can’t perform that action at this time.
0 commit comments