Skip to content

Commit

Permalink
chwd: Change argument from vector to optional string
Browse files Browse the repository at this point in the history
  • Loading branch information
ventureoo committed Aug 21, 2024
1 parent 41df586 commit 7e62b18
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 30 deletions.
6 changes: 3 additions & 3 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ pub struct Args {

/// Install profile
#[arg(short, long, value_name = "profile", conflicts_with("remove"))]
pub install: Option<Vec<String>>,
pub install: Option<String>,

/// Remove profile
#[arg(short, long, value_name = "profile", conflicts_with("install"))]
pub remove: Option<Vec<String>>,
pub remove: Option<String>,

/// Show detailed info for listings
#[arg(short, long)]
Expand All @@ -55,7 +55,7 @@ pub struct Args {

/// Autoconfigure
#[arg(short, long, value_name = "classid", conflicts_with_all(["install", "remove"]))]
pub autoconfigure: Option<Vec<String>>,
pub autoconfigure: Option<String>,

/// Toggle AI SDK profiles
#[arg(long = "ai_sdk")]
Expand Down
38 changes: 11 additions & 27 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,6 @@ use i18n_embed::DesktopLanguageRequester;
use nix::unistd::Uid;
use subprocess::Exec;

fn perceed_inst_rem(
args: &Option<Vec<String>>,
working_profiles: &mut Vec<String>,
) -> anyhow::Result<()> {
if let Some(values) = args {
let profile = values[0].to_lowercase();
working_profiles.push(profile);
}

Ok(())
}

fn perceed_autoconf(
args: &Option<Vec<String>>,
autoconf_class_id: &mut String,
) -> anyhow::Result<()> {
if let Some(values) = args {
*autoconf_class_id = values[0].to_lowercase();
}

Ok(())
}

fn main() -> anyhow::Result<()> {
let requested_languages = DesktopLanguageRequester::requested_languages();
let localizer = crate::localization::localizer();
Expand All @@ -79,10 +56,17 @@ fn main() -> anyhow::Result<()> {
let mut working_profiles: Vec<String> = vec![];

let mut autoconf_class_id = String::new();
perceed_autoconf(&argstruct.autoconfigure, &mut autoconf_class_id)?;
if let Some(profile) = &argstruct.install {
working_profiles.push(profile.to_lowercase());
}

perceed_inst_rem(&argstruct.install, &mut working_profiles)?;
perceed_inst_rem(&argstruct.remove, &mut working_profiles)?;
if let Some(profile) = &argstruct.remove {
working_profiles.push(profile.to_lowercase());
}

if let Some(class_id) = &argstruct.autoconfigure {
autoconf_class_id = class_id.to_lowercase();
}

if !argstruct.show_pci {
argstruct.show_pci = true;
Expand Down Expand Up @@ -231,7 +215,7 @@ fn prepare_autoconfigure(
if !found_device {
console_writer::print_warning(&format!("No device of class '{autoconf_class_id}' found!"));
} else if !profiles_name.is_empty() {
args.install = Some(profiles_name.clone());
args.install = Some(profiles_name.first().unwrap().clone());
}

profiles_name
Expand Down

0 comments on commit 7e62b18

Please sign in to comment.