diff --git a/pkg6dev/Cargo.toml b/pkg6dev/Cargo.toml index 2d5d149..c759d9d 100644 --- a/pkg6dev/Cargo.toml +++ b/pkg6dev/Cargo.toml @@ -13,6 +13,7 @@ keywords = ["packaging", "illumos"] [dependencies] libips = {path = "../libips", version = "0.1.0"} +userland = {path = "../userland"} failure = "0.1.8" failure_derive = "0.1.8" clap = "~3.0.0-beta.2" \ No newline at end of file diff --git a/pkg6dev/src/main.rs b/pkg6dev/src/main.rs index 9a92c44..a6ce813 100644 --- a/pkg6dev/src/main.rs +++ b/pkg6dev/src/main.rs @@ -16,16 +16,22 @@ use errors::Result; use std::collections::HashMap; use std::fs::{read_dir}; use std::path::Path; +use userland::Makefile; +use userland::repology::{find_newest_version}; fn main() { + let component_arg = Arg::new("component") + .takes_value(true) + .default_value("../sample_data/pkgs/cups"); + let opts = app_from_crate!().subcommand(App::new("diff-component") .about("shows differences between sample-manifest and manifests") - .arg(Arg::new("component") - .takes_value(true) - .default_value("../sample_data/pkgs/cups") - ) - ).get_matches(); - //.get_matches_from(vec!["pkg6dev", "diff-component"]); + .arg(&component_arg) + ).subcommand(App::new("show-component") + .about("Show informations about the component") + .arg(&component_arg) + )//.get_matches(); + .get_matches_from(vec!["pkg6dev", "show-component"]); if let Some(diff_component_opts) = opts.subcommand_matches("diff-component") { let res = diff_component(diff_component_opts); @@ -34,6 +40,13 @@ fn main() { } } + if let Some(show_component_opts) = opts.subcommand_matches("show-component") { + let res = show_component_info(show_component_opts); + if res.is_err() { + println!("error: {:?}", res.unwrap_err()) + } + } + } fn diff_component(matches: &ArgMatches) -> Result<()> { @@ -70,6 +83,61 @@ fn diff_component(matches: &ArgMatches) -> Result<()> { Ok(()) } +fn show_component_info(opts: &ArgMatches) -> Result<()> { + let component_path = opts.value_of("component").unwrap(); + + let makefile = Makefile::parse_file(Path::new(&(component_path.to_string() + "/Makefile")))?; + + //println!("{:#?}", makefile); + + let mut name = String::new(); + + if let Some(var) = makefile.variables.get("COMPONENT_NAME") { + println!("Name: {}", var.join(" ")); + name = var.first().unwrap().to_string(); + } + + if let Some(var) = makefile.variables.get("COMPONENT_VERSION") { + println!("Version: {}", var.join(" ")); + let latest_version = find_newest_version(&name); + if latest_version.is_ok() { + println!("Latest Version: {}", latest_version?); + } else { + eprintln!("{:?}", latest_version.unwrap_err()) + } + } + + if let Some(var) = makefile.variables.get("BUILD_BITS") { + println!("Build bits: {}", var.join(" ")); + } + + if let Some(var) = makefile.variables.get("COMPONENT_PROJECT_URL") { + println!("Project URl: {}", var.join("\t")); + } + + if let Some(var) = makefile.variables.get("COMPONENT_ARCHIVE_URL") { + println!("Source URl: {}", var.join("\t")); + } + + if let Some(var) = makefile.variables.get("COMPONENT_ARCHIVE_HASH") { + println!("Source Archive File Hash: {}", var.join(" ")); + } + + if let Some(var) = makefile.variables.get("CONFIGURE_ENV") { + println!("Configure Environment: {}", var.join("\n\t")); + } + + if let Some(var) = makefile.variables.get("CONFIGURE_OPTIONS") { + println!("./configure {}", var.join("\n\t")); + } + + if let Some(var) = makefile.variables.get("REQUIRED_PACKAGES") { + println!("Dependencies:\n\t{}", var.join("\n\t")); + } + + Ok(()) +} + // Show all files that have been removed in the sample-manifest fn find_removed_files(sample_manifest: &Manifest, manifests: Vec, component_path: &str) -> Result> { let f_map = make_file_map(sample_manifest.files.clone());