Refactor match session name (#1582)
This commit is contained in:
parent
f983651759
commit
cf521aaf60
1 changed files with 17 additions and 18 deletions
|
|
@ -151,24 +151,23 @@ pub enum SessionNameMatch {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn match_session_name(prefix: &str) -> Result<SessionNameMatch, io::ErrorKind> {
|
pub(crate) fn match_session_name(prefix: &str) -> Result<SessionNameMatch, io::ErrorKind> {
|
||||||
return match get_sessions() {
|
let sessions = get_sessions()?;
|
||||||
Ok(sessions) => Ok({
|
|
||||||
let filtered_sessions: Vec<String> = sessions
|
let filtered_sessions: Vec<_> = sessions.iter().filter(|s| s.starts_with(prefix)).collect();
|
||||||
.iter()
|
|
||||||
.filter(|s| s.starts_with(prefix))
|
if filtered_sessions.iter().any(|s| *s == prefix) {
|
||||||
.cloned()
|
|
||||||
.collect();
|
|
||||||
if filtered_sessions.iter().any(|s| s == prefix) {
|
|
||||||
return Ok(SessionNameMatch::Exact(prefix.to_string()));
|
return Ok(SessionNameMatch::Exact(prefix.to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok({
|
||||||
match &filtered_sessions[..] {
|
match &filtered_sessions[..] {
|
||||||
[] => SessionNameMatch::None,
|
[] => SessionNameMatch::None,
|
||||||
[s] => SessionNameMatch::UniquePrefix(s.to_string()),
|
[s] => SessionNameMatch::UniquePrefix(s.to_string()),
|
||||||
_ => SessionNameMatch::AmbiguousPrefix(filtered_sessions),
|
_ => {
|
||||||
|
SessionNameMatch::AmbiguousPrefix(filtered_sessions.into_iter().cloned().collect())
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}),
|
})
|
||||||
Err(e) => Err(e),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn session_exists(name: &str) -> Result<bool, io::ErrorKind> {
|
pub(crate) fn session_exists(name: &str) -> Result<bool, io::ErrorKind> {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue