Skip to content

Commit ff9b157

Browse files
ametel01maciektr
authored andcommitted
added cache-path command
fmt implemented review requests added cache path test changed printing fn
1 parent 6a5b5d0 commit ff9b157

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

scarb/src/bin/scarb/args.rs

+2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ impl ScarbArgs {
115115
pub enum CacheSubcommand {
116116
/// Remove all cached dependencies.
117117
Clean,
118+
/// Print the path of the cache directory.
119+
Path,
118120
}
119121

120122
/// Subcommand and its arguments.
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use anyhow::{Ok, Result};
2+
3+
use scarb::{core::Config, ui::ValueMessage};
4+
5+
#[tracing::instrument(skip_all, level = "info")]
6+
pub fn run(config: &Config) -> Result<()> {
7+
let path = config.dirs().cache_dir.path_unchecked();
8+
config.ui().print(ValueMessage::new("path", &path));
9+
Ok(())
10+
}

scarb/src/bin/scarb/commands/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::args::{CacheSubcommand, Command};
99
pub mod add;
1010
pub mod build;
1111
pub mod cache_clean;
12+
pub mod cache_path;
1213
pub mod clean;
1314
pub mod commands;
1415
pub mod external;
@@ -30,6 +31,7 @@ pub fn run(command: Command, config: &mut Config) -> Result<()> {
3031
Add(args) => add::run(args, config),
3132
Build(args) => build::run(args, config),
3233
Cache(CacheSubcommand::Clean) => cache_clean::run(config),
34+
Cache(CacheSubcommand::Path) => cache_path::run(config),
3335
Clean => clean::run(config),
3436
Commands => commands::run(config),
3537
External(args) => external::run(args, config),

scarb/tests/cache.rs

+17
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,20 @@ fn simple_clean() {
2626
.success();
2727
cache_dir.assert(predicates::path::missing());
2828
}
29+
30+
#[test]
31+
fn path_print() {
32+
let t = TempDir::new().unwrap();
33+
ProjectBuilder::start().build(&t);
34+
let cache_dir = TempDir::new().unwrap();
35+
36+
Scarb::quick_snapbox()
37+
.arg("cache")
38+
.arg("path")
39+
.env("SCARB_CACHE", cache_dir.path())
40+
.current_dir(&t)
41+
.assert()
42+
.stdout_eq(format!("{}\n", cache_dir.path().display()))
43+
.success();
44+
cache_dir.assert(predicates::path::is_dir());
45+
}

0 commit comments

Comments
 (0)