mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Removed unecessary Option<&ConfigClient> in filetransfer; use degraded mode instead
This commit is contained in:
@@ -67,6 +67,7 @@ impl SshKeyStorage {
|
|||||||
/// ### empty
|
/// ### empty
|
||||||
///
|
///
|
||||||
/// Create an empty ssh key storage; used in case `ConfigClient` is not available
|
/// Create an empty ssh key storage; used in case `ConfigClient` is not available
|
||||||
|
#[cfg(test)]
|
||||||
pub fn empty() -> Self {
|
pub fn empty() -> Self {
|
||||||
SshKeyStorage {
|
SshKeyStorage {
|
||||||
hosts: HashMap::new(),
|
hosts: HashMap::new(),
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ impl Browser {
|
|||||||
/// ### new
|
/// ### new
|
||||||
///
|
///
|
||||||
/// Build a new `Browser` struct
|
/// Build a new `Browser` struct
|
||||||
pub fn new(cli: Option<&ConfigClient>) -> Self {
|
pub fn new(cli: &ConfigClient) -> Self {
|
||||||
Self {
|
Self {
|
||||||
local: Self::build_local_explorer(cli),
|
local: Self::build_local_explorer(cli),
|
||||||
remote: Self::build_remote_explorer(cli),
|
remote: Self::build_remote_explorer(cli),
|
||||||
@@ -120,45 +120,32 @@ impl Browser {
|
|||||||
/// ### build_local_explorer
|
/// ### build_local_explorer
|
||||||
///
|
///
|
||||||
/// Build a file explorer with local host setup
|
/// Build a file explorer with local host setup
|
||||||
pub fn build_local_explorer(cli: Option<&ConfigClient>) -> FileExplorer {
|
pub fn build_local_explorer(cli: &ConfigClient) -> FileExplorer {
|
||||||
let mut builder = Self::build_explorer(cli);
|
let mut builder = Self::build_explorer(cli);
|
||||||
if let Some(cli) = cli {
|
builder.with_formatter(cli.get_local_file_fmt().as_deref());
|
||||||
builder.with_formatter(cli.get_local_file_fmt().as_deref());
|
|
||||||
}
|
|
||||||
builder.build()
|
builder.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ### build_remote_explorer
|
/// ### build_remote_explorer
|
||||||
///
|
///
|
||||||
/// Build a file explorer with remote host setup
|
/// Build a file explorer with remote host setup
|
||||||
pub fn build_remote_explorer(cli: Option<&ConfigClient>) -> FileExplorer {
|
pub fn build_remote_explorer(cli: &ConfigClient) -> FileExplorer {
|
||||||
let mut builder = Self::build_explorer(cli);
|
let mut builder = Self::build_explorer(cli);
|
||||||
if let Some(cli) = cli {
|
builder.with_formatter(cli.get_remote_file_fmt().as_deref());
|
||||||
builder.with_formatter(cli.get_remote_file_fmt().as_deref());
|
|
||||||
}
|
|
||||||
builder.build()
|
builder.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ### build_explorer
|
/// ### build_explorer
|
||||||
///
|
///
|
||||||
/// Build explorer reading configuration from `ConfigClient`
|
/// Build explorer reading configuration from `ConfigClient`
|
||||||
fn build_explorer(cli: Option<&ConfigClient>) -> FileExplorerBuilder {
|
fn build_explorer(cli: &ConfigClient) -> FileExplorerBuilder {
|
||||||
let mut builder: FileExplorerBuilder = FileExplorerBuilder::new();
|
let mut builder: FileExplorerBuilder = FileExplorerBuilder::new();
|
||||||
// Set common keys
|
// Set common keys
|
||||||
builder
|
builder
|
||||||
.with_file_sorting(FileSorting::ByName)
|
.with_file_sorting(FileSorting::ByName)
|
||||||
.with_stack_size(16);
|
.with_stack_size(16)
|
||||||
match &cli {
|
.with_group_dirs(cli.get_group_dirs())
|
||||||
Some(cli) => {
|
.with_hidden_files(cli.get_show_hidden_files());
|
||||||
builder // Build according to current configuration
|
|
||||||
.with_group_dirs(cli.get_group_dirs())
|
|
||||||
.with_hidden_files(cli.get_show_hidden_files());
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
builder // Build default
|
|
||||||
.with_group_dirs(Some(GroupDirs::First));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
builder
|
builder
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ impl FileTransferActivity {
|
|||||||
///
|
///
|
||||||
/// Initialize configuration client if possible.
|
/// Initialize configuration client if possible.
|
||||||
/// This function doesn't return errors.
|
/// This function doesn't return errors.
|
||||||
pub(super) fn init_config_client() -> Option<ConfigClient> {
|
pub(super) fn init_config_client() -> ConfigClient {
|
||||||
match environment::init_config_dir() {
|
match environment::init_config_dir() {
|
||||||
Ok(termscp_dir) => match termscp_dir {
|
Ok(termscp_dir) => match termscp_dir {
|
||||||
Some(termscp_dir) => {
|
Some(termscp_dir) => {
|
||||||
@@ -79,24 +79,21 @@ impl FileTransferActivity {
|
|||||||
let (config_path, ssh_keys_path): (PathBuf, PathBuf) =
|
let (config_path, ssh_keys_path): (PathBuf, PathBuf) =
|
||||||
environment::get_config_paths(termscp_dir.as_path());
|
environment::get_config_paths(termscp_dir.as_path());
|
||||||
match ConfigClient::new(config_path.as_path(), ssh_keys_path.as_path()) {
|
match ConfigClient::new(config_path.as_path(), ssh_keys_path.as_path()) {
|
||||||
Ok(config_client) => Some(config_client),
|
Ok(config_client) => config_client,
|
||||||
Err(_) => None,
|
Err(_) => ConfigClient::degraded(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => None,
|
None => ConfigClient::degraded(),
|
||||||
},
|
},
|
||||||
Err(_) => None,
|
Err(_) => ConfigClient::degraded(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ### make_ssh_storage
|
/// ### make_ssh_storage
|
||||||
///
|
///
|
||||||
/// Make ssh storage from `ConfigClient` if possible, empty otherwise
|
/// Make ssh storage from `ConfigClient` if possible, empty otherwise (empty is implicit if degraded)
|
||||||
pub(super) fn make_ssh_storage(cli: Option<&ConfigClient>) -> SshKeyStorage {
|
pub(super) fn make_ssh_storage(cli: &ConfigClient) -> SshKeyStorage {
|
||||||
match cli {
|
SshKeyStorage::storage_from_config(cli)
|
||||||
Some(cli) => SshKeyStorage::storage_from_config(cli),
|
|
||||||
None => SshKeyStorage::empty(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ### setup_text_editor
|
/// ### setup_text_editor
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ impl FileTransferActivity {
|
|||||||
/// Instantiates a new FileTransferActivity
|
/// Instantiates a new FileTransferActivity
|
||||||
pub fn new(host: Localhost, protocol: FileTransferProtocol) -> FileTransferActivity {
|
pub fn new(host: Localhost, protocol: FileTransferProtocol) -> FileTransferActivity {
|
||||||
// Get config client
|
// Get config client
|
||||||
let config_client: Option<ConfigClient> = Self::init_config_client();
|
let config_client: ConfigClient = Self::init_config_client();
|
||||||
FileTransferActivity {
|
FileTransferActivity {
|
||||||
exit_reason: None,
|
exit_reason: None,
|
||||||
context: None,
|
context: None,
|
||||||
@@ -149,14 +149,14 @@ impl FileTransferActivity {
|
|||||||
host,
|
host,
|
||||||
client: match protocol {
|
client: match protocol {
|
||||||
FileTransferProtocol::Sftp => Box::new(SftpFileTransfer::new(
|
FileTransferProtocol::Sftp => Box::new(SftpFileTransfer::new(
|
||||||
Self::make_ssh_storage(config_client.as_ref()),
|
Self::make_ssh_storage(&config_client),
|
||||||
)),
|
)),
|
||||||
FileTransferProtocol::Ftp(ftps) => Box::new(FtpFileTransfer::new(ftps)),
|
FileTransferProtocol::Ftp(ftps) => Box::new(FtpFileTransfer::new(ftps)),
|
||||||
FileTransferProtocol::Scp => Box::new(ScpFileTransfer::new(
|
FileTransferProtocol::Scp => {
|
||||||
Self::make_ssh_storage(config_client.as_ref()),
|
Box::new(ScpFileTransfer::new(Self::make_ssh_storage(&config_client)))
|
||||||
)),
|
}
|
||||||
},
|
},
|
||||||
browser: Browser::new(config_client.as_ref()),
|
browser: Browser::new(&config_client),
|
||||||
log_records: VecDeque::with_capacity(256), // 256 events is enough I guess
|
log_records: VecDeque::with_capacity(256), // 256 events is enough I guess
|
||||||
transfer: TransferStates::default(),
|
transfer: TransferStates::default(),
|
||||||
cache: match TempDir::new() {
|
cache: match TempDir::new() {
|
||||||
|
|||||||
Reference in New Issue
Block a user