summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-11-09 16:42:26 +0100
committerMatthias Beyer <mail@beyermatthias.de>2020-11-09 16:42:26 +0100
commit2acac26f6cc378eec5b0b5a10d39239499d92ba3 (patch)
treecf5f3b5285af64ec7b74ede038e4c8d952bb162f /src
parent2801f5603771beb5af5d46f860b8b40b0ad85be3 (diff)
Add subcommand: env-of
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src')
-rw-r--r--src/cli.rs18
-rw-r--r--src/commands/env_of.rs42
-rw-r--r--src/commands/mod.rs3
-rw-r--r--src/main.rs5
-rw-r--r--src/package/version.rs1
5 files changed, 69 insertions, 0 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 3470503..1bba3d3 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -189,6 +189,24 @@ pub fn cli<'a>() -> App<'a> {
.help("The name of the package")
)
)
+ .subcommand(App::new("env-of")
+ .alias("env")
+ .about("Show the ENV configured for a package")
+ .arg(Arg::with_name("package_name")
+ .required(true)
+ .multiple(false)
+ .index(1)
+ .value_name("PACKAGE_NAME")
+ .help("The name of the package")
+ )
+ .arg(Arg::with_name("package_version_constraint")
+ .required(false)
+ .multiple(false)
+ .index(2)
+ .value_name("VERSION_CONSTRAINT")
+ .help("A version constraint to search for (optional)")
+ )
+ )
}
diff --git a/src/commands/env_of.rs b/src/commands/env_of.rs
new file mode 100644
index 0000000..4ce5161
--- /dev/null
+++ b/src/commands/env_of.rs
@@ -0,0 +1,42 @@
+use anyhow::Error;
+use anyhow::Context;
+use anyhow::Result;
+use clap_v3::ArgMatches;
+
+use crate::package::PackageName;
+use crate::package::PackageVersionConstraint;
+use crate::repository::Repository;
+
+pub async fn env_of(matches: &ArgMatches, repo: Repository) -> Result<()> {
+ use filters::filter::Filter;
+ use std::io::Write;
+
+ let package_filter = {
+ let name = matches.value_of("package_name").map(String::from).map(PackageName::from).unwrap();
+ let constraint = matches.value_of("package_version_constraint").map(String::from).map(PackageVersionConstraint::new).unwrap()?;
+ trace!("Checking for package with name = {} and version = {:?}", name, constraint);
+
+ crate::util::filters::build_package_filter_by_name(name)
+ .and(crate::util::filters::build_package_filter_by_version_constraint(constraint))
+ };
+
+ let mut stdout = std::io::stdout();
+ repo.packages()
+ .filter(|package| package_filter.filter(package))
+ .inspect(|pkg| trace!("Found package: {:?}", pkg))
+ .map(|pkg| {
+ if let Some(hm) = pkg.environment() {
+ for (key, value) in hm {
+ writeln!(stdout, "{} = '{}'", key, value)?;
+ }
+ } else {
+ writeln!(stdout, "No environment")?;
+ }
+
+ Ok(())
+ })
+ .collect::<Result<_>>()
+}
+
+
+
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index d44c6f1..a745f8a 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -1,6 +1,9 @@
mod build;
pub use build::build;
+mod env_of;
+pub use env_of::env_of;
+
mod dependencies_of;
pub use dependencies_of::dependencies_of;
diff --git a/src/main.rs b/src/main.rs
index 7edd932..de25f13 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -86,6 +86,11 @@ async fn main() -> Result<()> {
("versions-of", Some(matches)) => {
let repo = load_repo()?;
crate::commands::versions_of(matches, repo).await?
+ },
+
+ ("env-of", Some(matches)) => {
+ let repo = load_repo()?;
+ crate::commands::env_of(matches, repo).await?
}
(other, _) => return Err(anyhow!("Unknown subcommand: {}", other)),
diff --git a/src/package/version.rs b/src/package/version.rs
index f6f7d2c..8cc2c84 100644
--- a/src/package/version.rs
+++ b/src/package/version.rs
@@ -1,5 +1,6 @@
use std::ops::Deref;
+use anyhow::Error;
use anyhow::Result;
use pom::parser::Parser as PomParser;
use serde::Deserialize;