56 cli_config_args: impl IntoIterator<Item = impl AsRef<[u8]>>, |
56 cli_config_args: impl IntoIterator<Item = impl AsRef<[u8]>>, |
57 ) -> Result<Option<Self>, ConfigError> { |
57 ) -> Result<Option<Self>, ConfigError> { |
58 fn parse_one(arg: &[u8]) -> Option<(Vec<u8>, Vec<u8>, Vec<u8>)> { |
58 fn parse_one(arg: &[u8]) -> Option<(Vec<u8>, Vec<u8>, Vec<u8>)> { |
59 use crate::utils::SliceExt; |
59 use crate::utils::SliceExt; |
60 |
60 |
61 let (section_and_item, value) = split_2(arg, b'=')?; |
61 let (section_and_item, value) = arg.split_2(b'=')?; |
62 let (section, item) = split_2(section_and_item.trim(), b'.')?; |
62 let (section, item) = section_and_item.trim().split_2(b'.')?; |
63 Some(( |
63 Some(( |
64 section.to_owned(), |
64 section.to_owned(), |
65 item.to_owned(), |
65 item.to_owned(), |
66 value.trim().to_owned(), |
66 value.trim().to_owned(), |
67 )) |
67 )) |
68 } |
|
69 |
|
70 fn split_2(bytes: &[u8], separator: u8) -> Option<(&[u8], &[u8])> { |
|
71 let mut iter = bytes.splitn(2, |&byte| byte == separator); |
|
72 let a = iter.next()?; |
|
73 let b = iter.next()?; |
|
74 Some((a, b)) |
|
75 } |
68 } |
76 |
69 |
77 let mut layer = Self::new(ConfigOrigin::CommandLine); |
70 let mut layer = Self::new(ConfigOrigin::CommandLine); |
78 for arg in cli_config_args { |
71 for arg in cli_config_args { |
79 let arg = arg.as_ref(); |
72 let arg = arg.as_ref(); |