Merge pull request #109 from vireshk/i2c/trim

i2c: Trim the device list to avoid errors
This commit is contained in:
Viresh Kumar 2022-02-23 02:39:06 +05:30 committed by GitHub
commit 02fdac85e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -163,9 +163,9 @@ impl TryFrom<I2cArgs> for I2cConfiguration {
return Err(Error::SocketCountInvalid(0));
}
let devices = AdapterConfig::try_from(args.device_list.as_str())?;
let devices = AdapterConfig::try_from(args.device_list.trim())?;
Ok(I2cConfiguration {
socket_path: args.socket_path,
socket_path: args.socket_path.trim().to_string(),
socket_count: args.socket_count,
devices,
})
@ -324,6 +324,12 @@ mod tests {
fn test_parse_successful() {
let socket_name = "vi2c.sock";
// Space before and after the device list and socket name
let cmd_args = I2cArgs::from_args(" ./vi2c.sock", " 1:4 ", 1);
let config = I2cConfiguration::try_from(cmd_args).unwrap();
Listener::new(config.socket_path, true).unwrap();
// Valid configuration
let cmd_args = I2cArgs::from_args(socket_name, "1:4,2:32:21,5:5:23", 5);
let config = I2cConfiguration::try_from(cmd_args).unwrap();