use std::collections::HashMap; use crate::{config::{Profile, Programs}, profile::active_profile, ErrorMessage}; pub fn append_arguments(mut command: String, args: Vec) -> String { for a in args { command = format!("{} {}",command,a); } command } pub fn profile_launch(profiles: Vec, programs_config: HashMap, program_arg: &String) -> Result { match programs_config.iter().find(|x|x.0.eq(program_arg)) { Some(p) => { let mut swaymsg_command = format!("exec {}", p.1.command); swaymsg_command = append_arguments(swaymsg_command, p.1.arguments.clone()); match active_profile(profiles) { Ok(profile) => { println!("{:#?}",profile); if let Some(profile_args) = profile.program_args.unwrap_or_default().iter().find(|x|x.0.eq(p.0)) { swaymsg_command = append_arguments(swaymsg_command, profile_args.1.to_owned()); } Ok(swaymsg_command) }, Err(e) => Err(e), } }, None => { Err(ErrorMessage { message: Some(String::from("No matching program found")), code: Some(3) }) }, } }