mirror of
https://github.com/veeso/termscp.git
synced 2025-12-06 17:15:35 -08:00
@@ -44,6 +44,7 @@
|
|||||||
|
|
||||||
Released on ??
|
Released on ??
|
||||||
|
|
||||||
|
- [issue 317](https://github.com/veeso/termscp/issues/317): the return value of `--version` should be `0`
|
||||||
- [issue 319](https://github.com/veeso/termscp/issues/319): fixed a crash when the local directory specified in the auth form does not exist
|
- [issue 319](https://github.com/veeso/termscp/issues/319): fixed a crash when the local directory specified in the auth form does not exist
|
||||||
- [issue 327](https://github.com/veeso/termscp/issues/327): fixed a panic when trying to go up from local directory on localhost in the auth form
|
- [issue 327](https://github.com/veeso/termscp/issues/327): fixed a panic when trying to go up from local directory on localhost in the auth form
|
||||||
- Dependencies:
|
- Dependencies:
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ pub enum Task {
|
|||||||
Activity(NextActivity),
|
Activity(NextActivity),
|
||||||
ImportTheme(PathBuf),
|
ImportTheme(PathBuf),
|
||||||
InstallUpdate,
|
InstallUpdate,
|
||||||
|
Version,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, FromArgs)]
|
#[derive(Default, FromArgs)]
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ pub enum HostErrorType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// HostError is a wrapper for the error type and the exact io error
|
/// HostError is a wrapper for the error type and the exact io error
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Error)]
|
||||||
pub struct HostError {
|
pub struct HostError {
|
||||||
pub error: HostErrorType,
|
pub error: HostErrorType,
|
||||||
ioerr: Option<std::io::Error>,
|
ioerr: Option<std::io::Error>,
|
||||||
|
|||||||
55
src/main.rs
55
src/main.rs
@@ -33,24 +33,24 @@ const APP_NAME: &str = env!("CARGO_PKG_NAME");
|
|||||||
const APP_BUILD_DATE: &str = env!("VERGEN_BUILD_TIMESTAMP");
|
const APP_BUILD_DATE: &str = env!("VERGEN_BUILD_TIMESTAMP");
|
||||||
const APP_GIT_BRANCH: &str = env!("VERGEN_GIT_BRANCH");
|
const APP_GIT_BRANCH: &str = env!("VERGEN_GIT_BRANCH");
|
||||||
const APP_GIT_HASH: &str = env!("VERGEN_GIT_SHA");
|
const APP_GIT_HASH: &str = env!("VERGEN_GIT_SHA");
|
||||||
const EXIT_CODE_SUCCESS: i32 = 0;
|
|
||||||
const EXIT_CODE_ERROR: i32 = 1;
|
|
||||||
const TERMSCP_VERSION: &str = env!("CARGO_PKG_VERSION");
|
const TERMSCP_VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
const TERMSCP_AUTHORS: &str = env!("CARGO_PKG_AUTHORS");
|
const TERMSCP_AUTHORS: &str = env!("CARGO_PKG_AUTHORS");
|
||||||
|
|
||||||
|
type MainResult<T> = std::result::Result<T, Box<dyn std::error::Error>>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn git_hash() -> &'static str {
|
fn git_hash() -> &'static str {
|
||||||
APP_GIT_HASH[0..8].as_ref()
|
APP_GIT_HASH[0..8].as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() -> MainResult<()> {
|
||||||
let args: Args = argh::from_env();
|
let args: Args = argh::from_env();
|
||||||
// Parse args
|
// Parse args
|
||||||
let run_opts: RunOpts = match parse_args(args) {
|
let run_opts: RunOpts = match parse_args(args) {
|
||||||
Ok(opts) => opts,
|
Ok(opts) => opts,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("{err}");
|
eprintln!("{err}");
|
||||||
std::process::exit(255);
|
return Err(err.into());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Setup logging
|
// Setup logging
|
||||||
@@ -63,10 +63,7 @@ fn main() {
|
|||||||
);
|
);
|
||||||
// Run
|
// Run
|
||||||
info!("Starting activity manager...");
|
info!("Starting activity manager...");
|
||||||
let rc = run(run_opts);
|
run(run_opts)
|
||||||
info!("termscp terminated with exitcode {}", rc);
|
|
||||||
// Then return
|
|
||||||
std::process::exit(rc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse arguments
|
/// Parse arguments
|
||||||
@@ -81,10 +78,8 @@ fn parse_args(args: Args) -> Result<RunOpts, String> {
|
|||||||
let mut run_opts: RunOpts = RunOpts::default();
|
let mut run_opts: RunOpts = RunOpts::default();
|
||||||
// Version
|
// Version
|
||||||
if args.version {
|
if args.version {
|
||||||
return Err(format!(
|
run_opts.task = Task::Version;
|
||||||
"{APP_NAME} v{TERMSCP_VERSION} ({APP_GIT_BRANCH}, {git_hash}, {APP_BUILD_DATE}) - Developed by {TERMSCP_AUTHORS}",
|
return Ok(run_opts);
|
||||||
git_hash = git_hash()
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
// Logging
|
// Logging
|
||||||
if args.debug {
|
if args.debug {
|
||||||
@@ -125,57 +120,71 @@ fn parse_args(args: Args) -> Result<RunOpts, String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Run task and return rc
|
/// Run task and return rc
|
||||||
fn run(run_opts: RunOpts) -> i32 {
|
fn run(run_opts: RunOpts) -> MainResult<()> {
|
||||||
match run_opts.task {
|
match run_opts.task {
|
||||||
Task::ImportTheme(theme) => run_import_theme(&theme),
|
Task::ImportTheme(theme) => run_import_theme(&theme),
|
||||||
Task::InstallUpdate => run_install_update(),
|
Task::InstallUpdate => run_install_update(),
|
||||||
Task::Activity(activity) => run_activity(activity, run_opts.ticks, run_opts.remote),
|
Task::Activity(activity) => run_activity(activity, run_opts.ticks, run_opts.remote),
|
||||||
|
Task::Version => print_version(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_import_theme(theme: &Path) -> i32 {
|
fn print_version() -> MainResult<()> {
|
||||||
|
println!(
|
||||||
|
"{APP_NAME} v{TERMSCP_VERSION} ({APP_GIT_BRANCH}, {git_hash}, {APP_BUILD_DATE}) - Developed by {TERMSCP_AUTHORS}",
|
||||||
|
git_hash = git_hash()
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_import_theme(theme: &Path) -> MainResult<()> {
|
||||||
match support::import_theme(theme) {
|
match support::import_theme(theme) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
println!("Theme has been successfully imported!");
|
println!("Theme has been successfully imported!");
|
||||||
EXIT_CODE_ERROR
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("{err}");
|
eprintln!("{err}");
|
||||||
EXIT_CODE_ERROR
|
Err(err.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_install_update() -> i32 {
|
fn run_install_update() -> MainResult<()> {
|
||||||
match support::install_update() {
|
match support::install_update() {
|
||||||
Ok(msg) => {
|
Ok(msg) => {
|
||||||
println!("{msg}");
|
println!("{msg}");
|
||||||
EXIT_CODE_SUCCESS
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Could not install update: {err}");
|
eprintln!("Could not install update: {err}");
|
||||||
EXIT_CODE_ERROR
|
Err(err.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_activity(activity: NextActivity, ticks: Duration, remote_args: RemoteArgs) -> i32 {
|
fn run_activity(
|
||||||
|
activity: NextActivity,
|
||||||
|
ticks: Duration,
|
||||||
|
remote_args: RemoteArgs,
|
||||||
|
) -> MainResult<()> {
|
||||||
// Create activity manager (and context too)
|
// Create activity manager (and context too)
|
||||||
let mut manager: ActivityManager = match ActivityManager::new(ticks) {
|
let mut manager: ActivityManager = match ActivityManager::new(ticks) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Could not start activity manager: {err}");
|
eprintln!("Could not start activity manager: {err}");
|
||||||
return EXIT_CODE_ERROR;
|
return Err(err.into());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Set file transfer params if set
|
// Set file transfer params if set
|
||||||
if let Err(err) = manager.configure_remote_args(remote_args) {
|
if let Err(err) = manager.configure_remote_args(remote_args) {
|
||||||
eprintln!("{err}");
|
eprintln!("{err}");
|
||||||
return EXIT_CODE_ERROR;
|
return Err(err.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
manager.run(activity);
|
manager.run(activity);
|
||||||
|
|
||||||
EXIT_CODE_SUCCESS
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user