mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Clippy
This commit is contained in:
@@ -166,10 +166,10 @@ impl FtpFileTransfer {
|
||||
let mut abs_path: PathBuf = PathBuf::from(path);
|
||||
abs_path.push(file_name.as_str());
|
||||
// get extension
|
||||
let extension: Option<String> = match abs_path.as_path().extension() {
|
||||
None => None,
|
||||
Some(s) => Some(String::from(s.to_string_lossy())),
|
||||
};
|
||||
let extension: Option<String> = abs_path
|
||||
.as_path()
|
||||
.extension()
|
||||
.map(|s| String::from(s.to_string_lossy()));
|
||||
// Return
|
||||
// Push to entries
|
||||
Ok(match is_dir {
|
||||
@@ -254,10 +254,10 @@ impl FtpFileTransfer {
|
||||
let mut abs_path: PathBuf = PathBuf::from(path);
|
||||
abs_path.push(file_name.as_str());
|
||||
// Get extension
|
||||
let extension: Option<String> = match abs_path.as_path().extension() {
|
||||
None => None,
|
||||
Some(s) => Some(String::from(s.to_string_lossy())),
|
||||
};
|
||||
let extension: Option<String> = abs_path
|
||||
.as_path()
|
||||
.extension()
|
||||
.map(|s| String::from(s.to_string_lossy()));
|
||||
// Return entry
|
||||
Ok(match is_dir {
|
||||
true => FsEntry::Directory(FsDirectory {
|
||||
|
||||
@@ -175,10 +175,10 @@ impl ScpFileTransfer {
|
||||
let mut abs_path: PathBuf = PathBuf::from(path);
|
||||
abs_path.push(file_name.as_str());
|
||||
// Get extension
|
||||
let extension: Option<String> = match abs_path.as_path().extension() {
|
||||
None => None,
|
||||
Some(s) => Some(String::from(s.to_string_lossy())),
|
||||
};
|
||||
let extension: Option<String> = abs_path
|
||||
.as_path()
|
||||
.extension()
|
||||
.map(|s| String::from(s.to_string_lossy()));
|
||||
// Return
|
||||
// Push to entries
|
||||
Ok(match is_dir {
|
||||
@@ -220,10 +220,7 @@ impl ScpFileTransfer {
|
||||
fn get_name_and_link(&self, token: &str) -> (String, Option<PathBuf>) {
|
||||
let tokens: Vec<&str> = token.split(" -> ").collect();
|
||||
let filename: String = String::from(*tokens.get(0).unwrap());
|
||||
let symlink: Option<PathBuf> = match tokens.get(1) {
|
||||
Some(s) => Some(PathBuf::from(s)),
|
||||
None => None,
|
||||
};
|
||||
let symlink: Option<PathBuf> = tokens.get(1).map(PathBuf::from);
|
||||
(filename, symlink)
|
||||
}
|
||||
|
||||
@@ -382,10 +379,7 @@ impl FileTransfer for ScpFileTransfer {
|
||||
}
|
||||
}
|
||||
// Get banner
|
||||
let banner: Option<String> = match session.banner() {
|
||||
Some(s) => Some(String::from(s)),
|
||||
None => None,
|
||||
};
|
||||
let banner: Option<String> = session.banner().map(String::from);
|
||||
// Set session
|
||||
self.session = Some(session);
|
||||
// Get working directory
|
||||
|
||||
@@ -123,20 +123,18 @@ impl SftpFileTransfer {
|
||||
fn make_fsentry(&mut self, path: &Path, metadata: &FileStat) -> FsEntry {
|
||||
// Get common parameters
|
||||
let file_name: String = String::from(path.file_name().unwrap().to_str().unwrap_or(""));
|
||||
let file_type: Option<String> = match path.extension() {
|
||||
Some(ext) => Some(String::from(ext.to_str().unwrap_or(""))),
|
||||
None => None,
|
||||
};
|
||||
let file_type: Option<String> = path
|
||||
.extension()
|
||||
.map(|ext| String::from(ext.to_str().unwrap_or("")));
|
||||
let uid: Option<u32> = metadata.uid;
|
||||
let gid: Option<u32> = metadata.gid;
|
||||
let pex: Option<(u8, u8, u8)> = match metadata.perm {
|
||||
Some(perms) => Some((
|
||||
((perms >> 6) & 0x7) as u8,
|
||||
((perms >> 3) & 0x7) as u8,
|
||||
(perms & 0x7) as u8,
|
||||
)),
|
||||
None => None,
|
||||
};
|
||||
let pex: Option<(u8, u8, u8)> = metadata.perm.map(|x| {
|
||||
(
|
||||
((x >> 6) & 0x7) as u8,
|
||||
((x >> 3) & 0x7) as u8,
|
||||
(x & 0x7) as u8,
|
||||
)
|
||||
});
|
||||
let size: u64 = metadata.size.unwrap_or(0);
|
||||
let mut atime: SystemTime = SystemTime::UNIX_EPOCH;
|
||||
atime = atime
|
||||
@@ -365,10 +363,7 @@ impl FileTransfer for SftpFileTransfer {
|
||||
}
|
||||
};
|
||||
// Set session
|
||||
let banner: Option<String> = match session.banner() {
|
||||
Some(s) => Some(String::from(s)),
|
||||
None => None,
|
||||
};
|
||||
let banner: Option<String> = session.banner().map(String::from);
|
||||
self.session = Some(session);
|
||||
// Set sftp
|
||||
self.sftp = Some(sftp);
|
||||
|
||||
@@ -510,10 +510,10 @@ impl Formatter {
|
||||
None => None,
|
||||
};
|
||||
// Match format extra: group 2 + 1
|
||||
let fmt_extra: Option<String> = match ®ex_match.get(5) {
|
||||
Some(extra) => Some(extra.as_str().to_string()),
|
||||
None => None,
|
||||
};
|
||||
let fmt_extra: Option<String> = regex_match
|
||||
.get(5)
|
||||
.as_ref()
|
||||
.map(|extra| extra.as_str().to_string());
|
||||
// Create a callchain or push new element to its back
|
||||
match callchain.as_mut() {
|
||||
None => {
|
||||
|
||||
@@ -190,10 +190,7 @@ impl FileExplorer {
|
||||
pass
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
match filtered.get(idx) {
|
||||
None => None,
|
||||
Some(file) => Some(file),
|
||||
}
|
||||
filtered.get(idx).copied()
|
||||
}
|
||||
|
||||
// Formatting
|
||||
|
||||
@@ -353,10 +353,9 @@ impl Localhost {
|
||||
}),
|
||||
false => {
|
||||
// Is File
|
||||
let extension: Option<String> = match path.extension() {
|
||||
Some(s) => Some(String::from(s.to_str().unwrap_or(""))),
|
||||
None => None,
|
||||
};
|
||||
let extension: Option<String> = path
|
||||
.extension()
|
||||
.map(|s| String::from(s.to_str().unwrap_or("")));
|
||||
FsEntry::File(FsFile {
|
||||
name: file_name,
|
||||
abs_path: path.clone(),
|
||||
@@ -534,13 +533,11 @@ impl Localhost {
|
||||
Err(err) => return Err(HostError::new(HostErrorType::DirNotAccessible, Some(err))),
|
||||
};
|
||||
let mut fs_entries: Vec<FsEntry> = Vec::new();
|
||||
for entry in entries {
|
||||
if let Ok(entry) = entry {
|
||||
fs_entries.push(match self.stat(entry.path().as_path()) {
|
||||
Ok(entry) => entry,
|
||||
Err(err) => return Err(err),
|
||||
});
|
||||
}
|
||||
for entry in entries.flatten() {
|
||||
fs_entries.push(match self.stat(entry.path().as_path()) {
|
||||
Ok(entry) => entry,
|
||||
Err(err) => return Err(err),
|
||||
});
|
||||
}
|
||||
Ok(fs_entries)
|
||||
}
|
||||
|
||||
@@ -342,10 +342,7 @@ impl BookmarksClient {
|
||||
port,
|
||||
username,
|
||||
protocol: protocol.to_string(),
|
||||
password: match password {
|
||||
Some(p) => Some(self.encrypt_str(p.as_str())), // Encrypt password if provided
|
||||
None => None,
|
||||
},
|
||||
password: password.map(|p| self.encrypt_str(p.as_str())),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -173,10 +173,7 @@ impl ConfigClient {
|
||||
/// Set value for group_dir in configuration.
|
||||
/// Provided value, if `Some` will be converted to `GroupDirs`
|
||||
pub fn set_group_dirs(&mut self, val: Option<GroupDirs>) {
|
||||
self.config.user_interface.group_dirs = match val {
|
||||
None => None,
|
||||
Some(val) => Some(val.to_string()),
|
||||
};
|
||||
self.config.user_interface.group_dirs = val.map(|val| val.to_string());
|
||||
}
|
||||
|
||||
/// ### get_file_fmt
|
||||
|
||||
@@ -45,10 +45,7 @@ impl AuthActivity {
|
||||
/// Update auth activity model based on msg
|
||||
/// The function exits when returns None
|
||||
pub(super) fn update(&mut self, msg: Option<(String, Msg)>) -> Option<(String, Msg)> {
|
||||
let ref_msg: Option<(&str, &Msg)> = match msg.as_ref() {
|
||||
None => None,
|
||||
Some((s, msg)) => Some((s, msg)),
|
||||
};
|
||||
let ref_msg: Option<(&str, &Msg)> = msg.as_ref().map(|(s, msg)| (s.as_str(), msg));
|
||||
// Match msg
|
||||
match ref_msg {
|
||||
None => None, // Exit after None
|
||||
|
||||
@@ -185,10 +185,7 @@ impl FileTransferActivity {
|
||||
}
|
||||
|
||||
pub(super) fn action_local_rename(&mut self, input: String) {
|
||||
let entry: Option<FsEntry> = match self.get_local_file_entry() {
|
||||
Some(f) => Some(f.clone()),
|
||||
None => None,
|
||||
};
|
||||
let entry: Option<FsEntry> = self.get_local_file_entry().cloned();
|
||||
if let Some(entry) = entry {
|
||||
let mut dst_path: PathBuf = PathBuf::from(input);
|
||||
// Check if path is relative
|
||||
@@ -265,10 +262,7 @@ impl FileTransferActivity {
|
||||
}
|
||||
|
||||
pub(super) fn action_local_delete(&mut self) {
|
||||
let entry: Option<FsEntry> = match self.get_local_file_entry() {
|
||||
Some(f) => Some(f.clone()),
|
||||
None => None,
|
||||
};
|
||||
let entry: Option<FsEntry> = self.get_local_file_entry().cloned();
|
||||
if let Some(entry) = entry {
|
||||
let full_path: PathBuf = entry.get_abs_path();
|
||||
// Delete file or directory and report status as popup
|
||||
@@ -528,10 +522,7 @@ impl FileTransferActivity {
|
||||
}
|
||||
|
||||
pub(super) fn action_find_transfer(&mut self, idx: usize, name: Option<String>) {
|
||||
let entry: Option<FsEntry> = match self.found.as_ref().unwrap().get(idx) {
|
||||
None => None,
|
||||
Some(e) => Some(e.clone()),
|
||||
};
|
||||
let entry: Option<FsEntry> = self.found.as_ref().unwrap().get(idx).cloned();
|
||||
if let Some(entry) = entry {
|
||||
// Download file
|
||||
match self.tab {
|
||||
@@ -548,10 +539,7 @@ impl FileTransferActivity {
|
||||
}
|
||||
|
||||
pub(super) fn action_find_delete(&mut self, idx: usize) {
|
||||
let entry: Option<FsEntry> = match self.found.as_ref().unwrap().get(idx) {
|
||||
None => None,
|
||||
Some(e) => Some(e.clone()),
|
||||
};
|
||||
let entry: Option<FsEntry> = self.found.as_ref().unwrap().get(idx).cloned();
|
||||
if let Some(entry) = entry {
|
||||
// Download file
|
||||
match self.tab {
|
||||
|
||||
@@ -57,10 +57,7 @@ impl FileTransferActivity {
|
||||
/// Update auth activity model based on msg
|
||||
/// The function exits when returns None
|
||||
pub(super) fn update(&mut self, msg: Option<(String, Msg)>) -> Option<(String, Msg)> {
|
||||
let ref_msg: Option<(&str, &Msg)> = match msg.as_ref() {
|
||||
None => None,
|
||||
Some((s, msg)) => Some((s, msg)),
|
||||
};
|
||||
let ref_msg: Option<(&str, &Msg)> = msg.as_ref().map(|(s, msg)| (s.as_str(), msg));
|
||||
// Match msg
|
||||
match ref_msg {
|
||||
None => None, // Exit after None
|
||||
@@ -132,10 +129,7 @@ impl FileTransferActivity {
|
||||
self.update_local_filelist()
|
||||
}
|
||||
(COMPONENT_EXPLORER_LOCAL, &MSG_KEY_CHAR_I) => {
|
||||
let file: Option<FsEntry> = match self.get_local_file_entry() {
|
||||
Some(f) => Some(f.clone()),
|
||||
None => None,
|
||||
};
|
||||
let file: Option<FsEntry> = self.get_local_file_entry().cloned();
|
||||
if let Some(file) = file {
|
||||
self.mount_file_info(&file);
|
||||
}
|
||||
@@ -251,10 +245,7 @@ impl FileTransferActivity {
|
||||
self.update_remote_filelist()
|
||||
}
|
||||
(COMPONENT_EXPLORER_REMOTE, &MSG_KEY_CHAR_I) => {
|
||||
let file: Option<FsEntry> = match self.get_remote_file_entry() {
|
||||
Some(f) => Some(f.clone()),
|
||||
None => None,
|
||||
};
|
||||
let file: Option<FsEntry> = self.get_remote_file_entry().cloned();
|
||||
if let Some(file) = file {
|
||||
self.mount_file_info(&file);
|
||||
}
|
||||
|
||||
@@ -68,10 +68,7 @@ impl SetupActivity {
|
||||
_ => None,
|
||||
};
|
||||
if let Some(idx) = idx {
|
||||
let key: Option<String> = match config_cli.iter_ssh_keys().nth(idx) {
|
||||
Some(k) => Some(k.clone()),
|
||||
None => None,
|
||||
};
|
||||
let key: Option<String> = config_cli.iter_ssh_keys().nth(idx).cloned();
|
||||
if let Some(key) = key {
|
||||
match config_cli.get_ssh_key(&key) {
|
||||
Ok(opt) => {
|
||||
|
||||
@@ -43,10 +43,7 @@ impl SetupActivity {
|
||||
/// Update auth activity model based on msg
|
||||
/// The function exits when returns None
|
||||
pub(super) fn update(&mut self, msg: Option<(String, Msg)>) -> Option<(String, Msg)> {
|
||||
let ref_msg: Option<(&str, &Msg)> = match msg.as_ref() {
|
||||
None => None,
|
||||
Some((s, msg)) => Some((s, msg)),
|
||||
};
|
||||
let ref_msg: Option<(&str, &Msg)> = msg.as_ref().map(|(s, msg)| (s.as_str(), msg));
|
||||
// Match msg
|
||||
match ref_msg {
|
||||
None => None,
|
||||
|
||||
@@ -35,23 +35,10 @@ use tui::{
|
||||
widgets::Paragraph,
|
||||
};
|
||||
|
||||
// -- state
|
||||
|
||||
struct OwnStates {
|
||||
focus: bool,
|
||||
}
|
||||
|
||||
impl Default for OwnStates {
|
||||
fn default() -> Self {
|
||||
OwnStates { focus: false }
|
||||
}
|
||||
}
|
||||
|
||||
// -- component
|
||||
|
||||
pub struct Text {
|
||||
props: Props,
|
||||
states: OwnStates,
|
||||
}
|
||||
|
||||
impl Text {
|
||||
@@ -59,10 +46,7 @@ impl Text {
|
||||
///
|
||||
/// Instantiate a new Text component
|
||||
pub fn new(props: Props) -> Self {
|
||||
Text {
|
||||
props,
|
||||
states: OwnStates::default(),
|
||||
}
|
||||
Text { props }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,16 +135,12 @@ impl Component for Text {
|
||||
/// ### blur
|
||||
///
|
||||
/// Blur component
|
||||
fn blur(&mut self) {
|
||||
self.states.focus = false;
|
||||
}
|
||||
fn blur(&mut self) {}
|
||||
|
||||
/// ### active
|
||||
///
|
||||
/// Active component
|
||||
fn active(&mut self) {
|
||||
self.states.focus = true;
|
||||
}
|
||||
fn active(&mut self) {}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -189,12 +169,6 @@ mod tests {
|
||||
))
|
||||
.build(),
|
||||
);
|
||||
// Focus
|
||||
assert_eq!(component.states.focus, false);
|
||||
component.active();
|
||||
assert_eq!(component.states.focus, true);
|
||||
component.blur();
|
||||
assert_eq!(component.states.focus, false);
|
||||
// Get value
|
||||
assert_eq!(component.get_value(), Payload::None);
|
||||
// Event
|
||||
|
||||
@@ -99,10 +99,7 @@ impl View {
|
||||
///
|
||||
/// Get component properties
|
||||
pub fn get_props(&self, id: &str) -> Option<PropsBuilder> {
|
||||
match self.components.get(id) {
|
||||
None => None,
|
||||
Some(cmp) => Some(cmp.get_props()),
|
||||
}
|
||||
self.components.get(id).map(|cmp| cmp.get_props())
|
||||
}
|
||||
|
||||
/// update
|
||||
@@ -110,10 +107,9 @@ impl View {
|
||||
/// Update component properties
|
||||
/// Returns `None` if component doesn't exist
|
||||
pub fn update(&mut self, id: &str, props: Props) -> Option<(String, Msg)> {
|
||||
match self.components.get_mut(id) {
|
||||
None => None,
|
||||
Some(cmp) => Some((id.to_string(), cmp.update(props))),
|
||||
}
|
||||
self.components
|
||||
.get_mut(id)
|
||||
.map(|cmp| (id.to_string(), cmp.update(props)))
|
||||
}
|
||||
|
||||
// -- state
|
||||
@@ -122,10 +118,7 @@ impl View {
|
||||
///
|
||||
/// Get component value
|
||||
pub fn get_value(&self, id: &str) -> Option<Payload> {
|
||||
match self.components.get(id) {
|
||||
None => None,
|
||||
Some(cmp) => Some(cmp.get_value()),
|
||||
}
|
||||
self.components.get(id).map(|cmp| cmp.get_value())
|
||||
}
|
||||
|
||||
// -- events
|
||||
@@ -137,10 +130,10 @@ impl View {
|
||||
pub fn on(&mut self, ev: InputEvent) -> Option<(String, Msg)> {
|
||||
match self.focus.as_ref() {
|
||||
None => None,
|
||||
Some(id) => match self.components.get_mut(id) {
|
||||
None => None,
|
||||
Some(cmp) => Some((id.to_string(), cmp.on(ev))),
|
||||
},
|
||||
Some(id) => self
|
||||
.components
|
||||
.get_mut(id)
|
||||
.map(|cmp| (id.to_string(), cmp.on(ev))),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -154,10 +154,7 @@ pub fn parse_remote_opt(remote: &str) -> Result<RemoteOptions, String> {
|
||||
};
|
||||
}
|
||||
// Get workdir
|
||||
let wrkdir: Option<PathBuf> = match groups.get(5) {
|
||||
Some(group) => Some(PathBuf::from(group.as_str())),
|
||||
None => None,
|
||||
};
|
||||
let wrkdir: Option<PathBuf> = groups.get(5).map(|group| PathBuf::from(group.as_str()));
|
||||
Ok(RemoteOptions {
|
||||
hostname,
|
||||
port,
|
||||
@@ -225,10 +222,7 @@ pub fn parse_datetime(tm: &str, fmt: &str) -> Result<SystemTime, ParseError> {
|
||||
/// Parse semver string
|
||||
pub fn parse_semver(haystack: &str) -> Option<String> {
|
||||
match SEMVER_REGEX.captures(haystack) {
|
||||
Some(groups) => match groups.get(1) {
|
||||
Some(version) => Some(version.as_str().to_string()),
|
||||
None => None,
|
||||
},
|
||||
Some(groups) => groups.get(1).map(|version| version.as_str().to_string()),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user