summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-04-08 20:24:59 +0200
committerMatthias Beyer <matthias.beyer@atos.net>2021-04-08 20:54:49 +0200
commit853680633f56c29832198c85937ab39d9eafee72 (patch)
tree04d25edd943feac889c275dd5192872bb2c1a67a
parent5c36c119f9448baf6bfe5245c6ebac1aa09d5b43 (diff)
Add subcommand to get path to source file
Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
-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 7f4a1bb..0267673 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")),
}
@@ -306,3 +307,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(|_| ())
+}