diff --git a/Cargo.lock b/Cargo.lock index 01b420f..7490116 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -311,6 +311,7 @@ dependencies = [ "inline_colorization", "inquire", "libc", + "log", "regex", "serde_json", "tempfile", diff --git a/Cargo.toml b/Cargo.toml index e2f5d64..c45858e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,4 +21,5 @@ regex = "1.10.4" tempfile = "3.10.1" ctrlc = "3.4" cli-table = "0.4" -inquire = "0.7.5" \ No newline at end of file +inquire = "0.7.5" +log = "0.4.22" \ No newline at end of file diff --git a/src/groups_config.rs b/src/groups_config.rs index dda6a55..58fb4e6 100644 --- a/src/groups_config.rs +++ b/src/groups_config.rs @@ -22,7 +22,7 @@ pub fn unified_node_list(items: Vec) -> Vec { sorted_vec } -pub fn dump_groups_for_completion(){ +pub fn dump_groups_for_completion() { let groups_map = get_groups_and_nodes(vec!["all".to_string()]); let groups: Vec = groups_map.keys().cloned().collect(); println!("{}", groups.join(" ")); @@ -57,7 +57,7 @@ fn get_groups_and_nodes(items: Vec) -> HashMap> { select_all = true; } - let re = Regex::new(r"^([a-z0-9-]+)\s*:\s*([a-z0-9-,\s]+)(#.*)?").unwrap(); + let re = Regex::new(r"^([a-z0-9-.]+)\s*:\s*([a-z0-9-.,%\s]+)(#.*)?").unwrap(); for cfg_file in &cfg_files { if let Ok(lines) = utils::read_lines(cfg_file) { @@ -82,5 +82,26 @@ fn get_groups_and_nodes(items: Vec) -> HashMap> { } } } - groups_map + resolve_aliases_from_map(&mut groups_map) +} + +fn resolve_aliases_from_map(groups_map: &mut HashMap>) -> HashMap> { + let mut groups_map_resolved = std::collections::HashMap::new(); + for (group_name, unresolved_items) in groups_map.iter() { + let mut nodes_final = Vec::new(); + for unresolved_item in unresolved_items { + if unresolved_item.starts_with("%") { + let group_alias = unresolved_item.strip_prefix('%').unwrap(); + let nodes_resolved = groups_map.get(group_alias).unwrap(); + nodes_final.append(&mut nodes_resolved.clone()); + } else { + nodes_final.push(unresolved_item.clone()); + } + } + let group = groups_map_resolved + .entry(group_name.to_string()) + .or_insert(Vec::new()); + group.extend(nodes_final); + } + groups_map_resolved } diff --git a/src/parameters.rs b/src/parameters.rs index 4d79e09..b98f577 100644 --- a/src/parameters.rs +++ b/src/parameters.rs @@ -44,6 +44,15 @@ use std::process::exit; Default search order: ~/.hostctl/hostctl.conf, /hostctl.conf + The format of this file looks like this: + + # : , , %, ... + private: vim.org, 256bit.org, blinky, vim.linetics.de + private-test: 213.95.54.132 + # Combine the hosts of both of the previous groups + private-all: %private-test, %private + + "### )] pub struct CommandLineArgs {