Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow using a list as linux dev value #647

Merged
merged 13 commits into from
Dec 2, 2023
19 changes: 9 additions & 10 deletions parser/src/cfg/defcfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,18 @@ pub fn parse_defcfg(expr: &[SExpr]) -> Result<CfgOptions> {
#[cfg(any(target_os = "linux", target_os = "unknown"))]
{
cfg.linux_dev = parse_linux_dev(val)?;
if cfg.linux_dev.is_empty() {
bail_expr!(val, "device list is empty, no devices will be intercepted");
}
}
}
"linux-dev-names-include" => {
#[cfg(any(target_os = "linux", target_os = "unknown"))]
{
cfg.linux_dev_names_include = Some(parse_linux_dev(val)?);
if cfg.linux_dev.is_empty() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be if cfg.linux_dev_names_include... ?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching that, I'll fix it in main directly

log::warn!("linux-dev-names-include is empty");
}
}
}
"linux-dev-names-exclude" => {
Expand Down Expand Up @@ -344,7 +350,7 @@ pub fn parse_linux_dev(val: &SExpr) -> Result<Vec<String>> {
SExpr::Atom(a) => {
let devs = parse_colon_separated_text(a.t.trim_matches('"'));
if devs.len() == 1 && devs[0].is_empty() {
bail_expr!(val, "empty string is not a valid device name or path")
bail_expr!(val, "an empty string is not a valid device name or path")
}
devs
}
Expand All @@ -355,23 +361,16 @@ pub fn parse_linux_dev(val: &SExpr) -> Result<Vec<String>> {
SExpr::Atom(path) => {
let trimmed_path = path.t.trim_matches('"').to_string();
if trimmed_path.is_empty() {
bail_span!(&path, "empty string is not a valid device name or path")
bail_span!(&path, "an empty string is not a valid device name or path")
}
acc.push(trimmed_path);
Ok(acc)
}
SExpr::List(inner_list) => {
bail_span!(&inner_list, "expected string, found list")
bail_span!(&inner_list, "expected strings, found a list")
}
});
let devs = r?;
if devs.is_empty() {
// This errors, because linux-dev, linux-dev-include-names and linux-dev-exclude-names
// are all mutually exclusive, and only one of them can be effective at a time.
// For all of them, if device list is empty, running kanata will effectively be
// a no-op which is surely not desired.
bail_expr!(val, "device list is empty, no devices will be intercepted")
}
devs
}
})
Expand Down
Loading