refactor: unify error handling with anyhow and add From conversions
Phase 5: Replace all Box<dyn Error> return types with anyhow::Result<T>
throughout the codebase. Replace string-based Err("msg".into()) and
format!().into() patterns with bail!() and anyhow!() macros. Fix
dirs::home_dir().unwrap() in settings.rs to use a fallback path instead
of panicking when HOME is unset. Remove stray use std::error::Error
imports no longer needed.
Phase 6: Add From<&User> for CacheUser in models/user.rs and
From<&Laboratory>/From<&Laboratories> for CacheLaboratory/CacheLabsWrapper
in models/laboratory.rs. Simplify commands/login.rs to use .into()
conversions, removing the redundant to_cache_user() and to_cache_labs()
helper functions.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
+114
@@ -0,0 +1,114 @@
|
||||
use clap::{Parser, Subcommand};
|
||||
|
||||
use crate::commands::config_subcommand::*;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(name = "mdrs")]
|
||||
#[command(about = "MDRS Rust CLI client", long_about = None)]
|
||||
pub struct Cli {
|
||||
#[command(subcommand)]
|
||||
pub command: Commands,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
pub enum Commands {
|
||||
/// Config management (create, update, list, delete)
|
||||
#[command(subcommand)]
|
||||
Config(ConfigSubcommand),
|
||||
Login {
|
||||
#[arg(short, long)]
|
||||
username: Option<String>,
|
||||
#[arg(short, long)]
|
||||
password: Option<String>,
|
||||
remote: String,
|
||||
},
|
||||
/// Logout and remove cached credentials for a remote
|
||||
Logout {
|
||||
remote: String,
|
||||
},
|
||||
Upload {
|
||||
#[arg(short, long)]
|
||||
recursive: bool,
|
||||
#[arg(short = 's', long)]
|
||||
skip_if_exists: bool,
|
||||
local_path: String,
|
||||
remote_path: String,
|
||||
},
|
||||
Download {
|
||||
#[arg(short, long)]
|
||||
recursive: bool,
|
||||
#[arg(short = 's', long)]
|
||||
skip_if_exists: bool,
|
||||
#[arg(short = 'p', long)]
|
||||
password: Option<String>,
|
||||
#[arg(long)]
|
||||
exclude: Vec<String>,
|
||||
remote_path: String,
|
||||
local_path: String,
|
||||
},
|
||||
Ls {
|
||||
remote_path: String,
|
||||
#[arg(short = 'p', long)]
|
||||
password: Option<String>,
|
||||
#[arg(short = 'J', long = "json")]
|
||||
json: bool,
|
||||
#[arg(short = 'r', long)]
|
||||
recursive: bool,
|
||||
#[arg(short = 'q', long)]
|
||||
quiet: bool,
|
||||
},
|
||||
Whoami {
|
||||
remote: String,
|
||||
},
|
||||
Labs {
|
||||
remote: String,
|
||||
},
|
||||
Chacl {
|
||||
/// Access level key: private, public, pw_open, cbs_open, 5kikan_open,
|
||||
/// cbs_or_pw_open, 5kikan_or_pw_open, storage
|
||||
access_level_key: String,
|
||||
#[arg(short, long)]
|
||||
recursive: bool,
|
||||
#[arg(short = 'p', long)]
|
||||
password: Option<String>,
|
||||
remote_path: String,
|
||||
},
|
||||
Metadata {
|
||||
#[arg(short = 'p', long)]
|
||||
password: Option<String>,
|
||||
remote_path: String,
|
||||
},
|
||||
Mkdir {
|
||||
remote_path: String,
|
||||
},
|
||||
Rm {
|
||||
#[arg(short, long)]
|
||||
recursive: bool,
|
||||
remote_path: String,
|
||||
},
|
||||
Mv {
|
||||
src_path: String,
|
||||
dest_path: String,
|
||||
},
|
||||
Cp {
|
||||
#[arg(short, long)]
|
||||
recursive: bool,
|
||||
src_path: String,
|
||||
dest_path: String,
|
||||
},
|
||||
/// Show metadata for a remote file
|
||||
FileMetadata {
|
||||
#[arg(short = 'p', long)]
|
||||
password: Option<String>,
|
||||
remote_path: String,
|
||||
},
|
||||
/// Show the version of this tool
|
||||
Version,
|
||||
/// Update this binary to the latest release
|
||||
#[command(name = "selfupdate")]
|
||||
SelfUpdate {
|
||||
/// Skip the confirmation prompt
|
||||
#[arg(short = 'y', long)]
|
||||
yes: bool,
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user