Add new command to show info about oi-userland components

This commit is contained in:
Till Wegmueller 2021-04-25 18:40:31 -03:00
parent 37d7d8ee08
commit af324e31f8
2 changed files with 75 additions and 6 deletions

View file

@ -13,6 +13,7 @@ keywords = ["packaging", "illumos"]
[dependencies] [dependencies]
libips = {path = "../libips", version = "0.1.0"} libips = {path = "../libips", version = "0.1.0"}
userland = {path = "../userland"}
failure = "0.1.8" failure = "0.1.8"
failure_derive = "0.1.8" failure_derive = "0.1.8"
clap = "~3.0.0-beta.2" clap = "~3.0.0-beta.2"

View file

@ -16,16 +16,22 @@ use errors::Result;
use std::collections::HashMap; use std::collections::HashMap;
use std::fs::{read_dir}; use std::fs::{read_dir};
use std::path::Path; use std::path::Path;
use userland::Makefile;
use userland::repology::{find_newest_version};
fn main() { 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") let opts = app_from_crate!().subcommand(App::new("diff-component")
.about("shows differences between sample-manifest and manifests") .about("shows differences between sample-manifest and manifests")
.arg(Arg::new("component") .arg(&component_arg)
.takes_value(true) ).subcommand(App::new("show-component")
.default_value("../sample_data/pkgs/cups") .about("Show informations about the component")
) .arg(&component_arg)
).get_matches(); )//.get_matches();
//.get_matches_from(vec!["pkg6dev", "diff-component"]); .get_matches_from(vec!["pkg6dev", "show-component"]);
if let Some(diff_component_opts) = opts.subcommand_matches("diff-component") { if let Some(diff_component_opts) = opts.subcommand_matches("diff-component") {
let res = diff_component(diff_component_opts); 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<()> { fn diff_component(matches: &ArgMatches) -> Result<()> {
@ -70,6 +83,61 @@ fn diff_component(matches: &ArgMatches) -> Result<()> {
Ok(()) 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 // Show all files that have been removed in the sample-manifest
fn find_removed_files(sample_manifest: &Manifest, manifests: Vec<Manifest>, component_path: &str) -> Result<Vec<File>> { fn find_removed_files(sample_manifest: &Manifest, manifests: Vec<Manifest>, component_path: &str) -> Result<Vec<File>> {
let f_map = make_file_map(sample_manifest.files.clone()); let f_map = make_file_map(sample_manifest.files.clone());