Skip to content

Add a 'dart pub cache path' command #4624

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/src/command/cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import '../command.dart';
import 'cache_add.dart';
import 'cache_clean.dart';
import 'cache_list.dart';
import 'cache_path.dart';
import 'cache_preload.dart';
import 'cache_repair.dart';

Expand All @@ -22,6 +23,7 @@ class CacheCommand extends PubCommand {
addSubcommand(CacheAddCommand());
addSubcommand(CacheListCommand());
addSubcommand(CacheCleanCommand());
addSubcommand(CachePathCommand());
addSubcommand(CacheRepairCommand());
addSubcommand(CachePreloadCommand());
}
Expand Down
22 changes: 22 additions & 0 deletions lib/src/command/cache_path.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) 2021, 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.

import '../command.dart';
import '../log.dart' as log;

class CachePathCommand extends PubCommand {
@override
String get name => 'path';
@override
String get description => 'Prints the path to the global PUB_CACHE.';
@override
bool get takesArguments => false;

CachePathCommand();

@override
Future<void> runProtected() async {
log.message(cache.rootDir);
}
}
27 changes: 27 additions & 0 deletions test/cache/path_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2013, 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.

import 'package:path/path.dart' as p;
import 'package:test/test.dart';

import '../descriptor.dart' as d;
import '../test_pub.dart';

void main() {
test('running pub cache path', () async {
final cache = p.join(d.sandbox, cachePath);
await runPub(args: ['cache', 'path'], output: cache);
});
test(
'running pub cache path with PUB_CACHE set prints the right path',
() async {
final envCache = p.join(d.sandbox, 'otherCache');
await runPub(
args: ['cache', 'path'],
environment: {'PUB_CACHE': envCache},
output: envCache,
);
},
);
}
1 change: 1 addition & 0 deletions test/testdata/goldens/help_test/pub cache --help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Usage: pub cache [arguments...]
Available subcommands:
add Install a package.
clean Clears the global PUB_CACHE.
path Prints the path to the global PUB_CACHE.
repair Reinstall cached packages.

Run "pub help" to see global options.
Expand Down
11 changes: 11 additions & 0 deletions test/testdata/goldens/help_test/pub cache path --help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# GENERATED BY: test/help_test.dart

## Section 0
$ pub cache path --help
Prints the path to the global PUB_CACHE.

Usage: pub cache path <subcommand> [arguments...]
-h, --help Print this usage information.

Run "pub help" to see global options.

Loading