summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-04-09 10:35:02 +0200
committerMatthias Beyer <matthias.beyer@atos.net>2021-04-09 10:35:02 +0200
commit2be2b17cbb339d401c4e961c0d39ab1a131c0363 (patch)
tree552550f609c6fffd7f3a065e70bcb8a14b00d2a7
parentf718a548ea18d51925c8f361bb709927726dd6bc (diff)
parent853680633f56c29832198c85937ab39d9eafee72 (diff)
Merge branch 'source-get-path'
-rw-r--r--src/cli.rs18
-rw-r--r--src/commands/source.rs46
2 files changed, 64 insertions, 0 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 1473164..c43cc0e 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -691,6 +691,24 @@ pub fn cli<'a>() -> App<'a> {
.about("Overwrite existing cache entry")
)
)
+ .subcommand(App::new("of")
+ .version(crate_version!())
+ .about("Get the pathes of the sources of a package")
+ .arg(Arg::new("package_name")
+ .required(false)
+ .multiple(false)
+ .index(1)
+ .value_name("PKG")
+ .about("Get the source file pathes for this package")
+ )
+ .arg(Arg::new("package_version")
+ .required(false)
+ .multiple(false)
+ .index(2)
+ .value_name("VERSION")
+ .about("Get the source file pathes for the package in this version")
+ )
+ )
)
.subcommand(App::new("release")
diff --git a/src/commands/source.rs b/src/commands/source.rs
index f194134..792c036 100644
--- a/src/commands/source.rs
+++ b/src/commands/source.rs
@@ -42,6 +42,7 @@ pub async fn source(
Some(("list-missing", matches)) => list_missing(matches, config, repo).await,
Some(("url", matches)) => url(matches, repo).await,
Some(("download", matches)) => download(matches, config, repo, progressbars).await,
+ Some(("of", matches)) => of(matches, config, repo).await,
Some((other, _)) => return Err(anyhow!("Unknown subcommand: {}", other)),
None => return Err(anyhow!("No subcommand")),
}
@@ -307,3 +308,48 @@ pub async fn download(
let (r, _) = tokio::join!(r, multibar_block);
r
}
+
+async fn of(
+ matches: &ArgMatches,
+ config: &Configuration,
+ repo: Repository,
+) -> Result<()> {
+ let cache = PathBuf::from(config.source_cache_root());
+ let sc = SourceCache::new(cache);
+ let pname = matches
+ .value_of("package_name")
+ .map(String::from)
+ .map(PackageName::from);
+ let pvers = matches
+ .value_of("package_version")
+ .map(PackageVersionConstraint::try_from)
+ .transpose()?;
+
+ repo.packages()
+ .filter(|p| pname.as_ref().map(|n| p.name() == n).unwrap_or(true))
+ .filter(|p| {
+ pvers
+ .as_ref()
+ .map(|v| v.matches(p.version()))
+ .unwrap_or(true)
+ })
+ .map(|p| {
+ let pathes = sc.sources_for(p)
+ .into_iter()
+ .map(|source| source.path())
+ .collect::<Vec<PathBuf>>();
+
+ (p, pathes)
+ })
+ .fold(Ok(std::io::stdout()), |out, (package, pathes)| {
+ out.and_then(|mut out| {
+ writeln!(out, "{} {}", package.name(), package.version())?;
+ for path in pathes {
+ writeln!(out, "\t{}", path.display())?;
+ }
+
+ Ok(out)
+ })
+ })
+ .map(|_| ())
+}