Skip to content

Commit

Permalink
add scarb fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
GianfrancoBazzani authored and mkaput committed Aug 3, 2023
1 parent 2ec321a commit b82f220
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
2 changes: 2 additions & 0 deletions scarb/src/bin/scarb/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ pub enum Command {
Clean,
/// List installed commands.
Commands,
// Fetch dependencies of packages from the network.
Fetch,
/// Format project files.
Fmt(FmtArgs),
/// Create a new Scarb package in existing directory.
Expand Down
14 changes: 14 additions & 0 deletions scarb/src/bin/scarb/commands/fetch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use anyhow::Result;

use scarb::core::Config;
use scarb::ops;

#[tracing::instrument(skip_all, level = "info")]
pub fn run(config: &Config) -> Result<()> {
let ws = ops::read_workspace(config.manifest_path(), config)?;

match ops::resolve_workspace(&ws) {
Ok(_) => Ok(()),
Err(e) => Err(e),
}
}
2 changes: 2 additions & 0 deletions scarb/src/bin/scarb/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod build;
pub mod clean;
pub mod commands;
pub mod external;
pub mod fetch;
pub mod fmt;
pub mod init;
pub mod manifest_path;
Expand All @@ -30,6 +31,7 @@ pub fn run(command: Command, config: &mut Config) -> Result<()> {
Clean => clean::run(config),
Commands => commands::run(config),
External(args) => external::run(args, config),
Fetch => fetch::run(config),
Fmt(args) => fmt::run(args, config),
Init(args) => init::run(args, config),
ManifestPath => manifest_path::run(config),
Expand Down
42 changes: 42 additions & 0 deletions scarb/tests/fetch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use indoc::indoc;
use scarb_test_support::gitx;

use scarb_test_support::command::Scarb;
use scarb_test_support::project_builder::ProjectBuilder;

#[test]
fn simple() {
let t = assert_fs::TempDir::new().unwrap();
ProjectBuilder::start()
.name("hello")
.version("0.1.0")
.build(&t);

Scarb::quick_snapbox()
.arg("fetch")
.current_dir(&t)
.assert()
.success();
}

#[test]
fn check_git_fetch_stdout() {
let t = assert_fs::TempDir::new().unwrap();

let git_dep = gitx::new("dep1", |t| ProjectBuilder::start().name("dep1").build(&t));

ProjectBuilder::start()
.name("hello")
.version("0.1.0")
.dep("dep1", &git_dep)
.build(&t);

Scarb::quick_snapbox()
.arg("fetch")
.current_dir(&t)
.assert()
.success()
.stdout_matches(indoc! {r#"
[..] Updating git repository file://[..]/dep1
"#});
}

0 comments on commit b82f220

Please sign in to comment.