diff --git a/Cargo.lock b/Cargo.lock index 8d2c7ab..fb230ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1822,11 +1822,12 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "open" -version = "4.1.0" +version = "5.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d16814a067484415fda653868c9be0ac5f2abd2ef5d951082a5f2fe1b3662944" +checksum = "cfabf1927dce4d6fdf563d63328a0a506101ced3ec780ca2135747336c98cef8" dependencies = [ "is-wsl", + "libc", "pathdiff", ] diff --git a/Cargo.toml b/Cargo.toml index 468677d..60eba4c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,13 @@ description = "termscp is a feature rich terminal file transfer and explorer wit edition = "2021" homepage = "https://termscp.veeso.dev" include = ["src/**/*", "LICENSE", "README.md", "CHANGELOG.md"] -keywords = ["scp-client", "sftp-client", "ftp-client", "winscp", "command-line-utility"] +keywords = [ + "scp-client", + "sftp-client", + "ftp-client", + "winscp", + "command-line-utility", +] license = "MIT" name = "termscp" readme = "README.md" @@ -46,14 +52,23 @@ lazy_static = "^1.4" log = "^0.4" magic-crypt = "^3.1" notify = "^4.0" -notify-rust = { version = "^4.5", default-features = false, features = [ "d" ] } -open = "^4.0" +notify-rust = { version = "^4.5", default-features = false, features = ["d"] } +open = "^5.0" rand = "^0.8.5" remotefs = "^0.2.0" -remotefs-aws-s3 = { version = "^0.2.1", default-features = false, features = [ "find", "rustls" ] } +remotefs-aws-s3 = { version = "^0.2.1", default-features = false, features = [ + "find", + "rustls", +] } rpassword = "^7.0" -self_update = { version = "^0.36", default-features = false, features = [ "rustls", "archive-tar", "archive-zip", "compression-flate2", "compression-zip-deflate" ] } -serde = { version = "^1", features = [ "derive" ] } +self_update = { version = "^0.36", default-features = false, features = [ + "rustls", + "archive-tar", + "archive-zip", + "compression-flate2", + "compression-zip-deflate", +] } +serde = { version = "^1", features = ["derive"] } simplelog = "^0.12" ssh2-config = "^0.2" tempfile = "^3.4" @@ -74,9 +89,9 @@ serial_test = "^2.0" cfg_aliases = "0.1" [features] -default = [ "with-keyring" ] -github-actions = [ ] -with-keyring = [ "keyring" ] +default = ["with-keyring"] +github-actions = [] +with-keyring = ["keyring"] [target."cfg(not(target_os = \"macos\"))"] [target."cfg(not(target_os = \"macos\"))".dependencies] @@ -84,13 +99,13 @@ remotefs-smb = "^0.2" [target."cfg(target_family = \"windows\")"] [target."cfg(target_family = \"windows\")".dependencies] -remotefs-ftp = { version = "^0.1.2", features = [ "native-tls" ] } +remotefs-ftp = { version = "^0.1.2", features = ["native-tls"] } remotefs-ssh = "^0.2" [target."cfg(target_family = \"unix\")"] [target."cfg(target_family = \"unix\")".dependencies] -remotefs-ftp = { version = "^0.1.2", features = [ "vendored", "native-tls" ] } -remotefs-ssh = { version = "^0.2", features = [ "ssh2-vendored" ] } +remotefs-ftp = { version = "^0.1.2", features = ["vendored", "native-tls"] } +remotefs-ssh = { version = "^0.2", features = ["ssh2-vendored"] } users = "0.11.0" [profile.dev] diff --git a/src/main.rs b/src/main.rs index 0a8d68e..435dffc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,9 +14,9 @@ extern crate log; extern crate magic_crypt; // External libs -use std::env; use std::path::PathBuf; use std::time::Duration; +use std::{env, path::Path}; // Include mod activity_manager; @@ -139,59 +139,68 @@ fn parse_remote_address(remote: &str) -> Result { /// Run task and return rc fn run(run_opts: RunOpts) -> i32 { match run_opts.task { - Task::ImportTheme(theme) => match support::import_theme(theme.as_path()) { - Ok(_) => { - println!("Theme has been successfully imported!"); - 0 - } - Err(err) => { - eprintln!("{err}"); - 1 - } - }, - Task::InstallUpdate => match support::install_update() { - Ok(msg) => { - println!("{msg}"); - 0 - } - Err(err) => { - eprintln!("Could not install update: {err}"); - 1 - } - }, - Task::Activity(activity) => { - // Get working directory - let wrkdir: PathBuf = match env::current_dir() { - Ok(dir) => dir, - Err(_) => PathBuf::from("/"), - }; - // Create activity manager (and context too) - let mut manager: ActivityManager = - match ActivityManager::new(wrkdir.as_path(), run_opts.ticks) { - Ok(m) => m, - Err(err) => { - eprintln!("Could not start activity manager: {err}"); - return 1; - } - }; - // Set file transfer params if set - match run_opts.remote { - Remote::Bookmark(BookmarkParams { name, password }) => { - if let Err(err) = manager.resolve_bookmark_name(&name, password.as_deref()) { - eprintln!("{err}"); - return 1; - } - } - Remote::Host(HostParams { params, password }) => { - if let Err(err) = manager.set_filetransfer_params(params, password.as_deref()) { - eprintln!("{err}"); - return 1; - } - } - Remote::None => {} - } - manager.run(activity); + Task::ImportTheme(theme) => run_import_theme(&theme), + Task::InstallUpdate => run_install_update(), + Task::Activity(activity) => run_activity(activity, run_opts.ticks, run_opts.remote), + } +} + +fn run_import_theme(theme: &Path) -> i32 { + match support::import_theme(theme) { + Ok(_) => { + println!("Theme has been successfully imported!"); 0 } + Err(err) => { + eprintln!("{err}"); + 1 + } } } + +fn run_install_update() -> i32 { + match support::install_update() { + Ok(msg) => { + println!("{msg}"); + 0 + } + Err(err) => { + eprintln!("Could not install update: {err}"); + 1 + } + } +} + +fn run_activity(activity: NextActivity, ticks: Duration, remote: Remote) -> i32 { + // Get working directory + let wrkdir: PathBuf = match env::current_dir() { + Ok(dir) => dir, + Err(_) => PathBuf::from("/"), + }; + // Create activity manager (and context too) + let mut manager: ActivityManager = match ActivityManager::new(wrkdir.as_path(), ticks) { + Ok(m) => m, + Err(err) => { + eprintln!("Could not start activity manager: {err}"); + return 1; + } + }; + // Set file transfer params if set + match remote { + Remote::Bookmark(BookmarkParams { name, password }) => { + if let Err(err) = manager.resolve_bookmark_name(&name, password.as_deref()) { + eprintln!("{err}"); + return 1; + } + } + Remote::Host(HostParams { params, password }) => { + if let Err(err) = manager.set_filetransfer_params(params, password.as_deref()) { + eprintln!("{err}"); + return 1; + } + } + Remote::None => {} + } + manager.run(activity); + 0 +}