summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2025-10-24 16:16:45 +0800
committer魏曹先生 <1992414357@qq.com>2025-10-24 16:16:45 +0800
commit1dd3c4abec5a84ae1bd8dd0a93670a5bef601ab3 (patch)
treef37abdbe37957fa122aedb0954b5451007339f22 /src/bin
parentc7a7785eda77e96a99c58291d08a091a5d8846eb (diff)
Add cli error handle.
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/jv.rs180
1 files changed, 180 insertions, 0 deletions
diff --git a/src/bin/jv.rs b/src/bin/jv.rs
index 9530203..f67b37b 100644
--- a/src/bin/jv.rs
+++ b/src/bin/jv.rs
@@ -1,4 +1,11 @@
+use std::{net::SocketAddr, str::FromStr};
+
use clap::{Parser, Subcommand, arg, command};
+use just_enough_vcs::{
+ system::action_system::action::ActionContext,
+ utils::tcp_connection::error::TcpTargetError,
+ vcs::{actions::local_actions::proc_set_upstream_vault_action, registry::client_registry},
+};
use just_enough_vcs_cli::utils::{lang_selector::current_locales, md_colored::md};
use rust_i18n::{set_locale, t};
@@ -84,6 +91,12 @@ enum AccountManage {
/// Show help information
#[command(alias = "--help", alias = "-h")]
Help,
+
+ /// Register a member to this computer
+ Add(AccountAddArgs),
+
+ /// Remove a account from this computer
+ Remove(AccountRemoveArgs),
}
#[derive(Subcommand, Debug)]
@@ -94,6 +107,18 @@ enum SheetManage {
}
#[derive(Parser, Debug)]
+struct AccountAddArgs {
+ /// Member name
+ member_name: String,
+}
+
+#[derive(Parser, Debug)]
+struct AccountRemoveArgs {
+ /// Member name
+ member_name: String,
+}
+
+#[derive(Parser, Debug)]
struct CreateWorkspaceArgs {
/// Show help information
#[arg(short, long)]
@@ -161,6 +186,9 @@ struct DirectArgs {
/// Show help information
#[arg(short, long)]
help: bool,
+
+ /// Upstream vault address
+ upstream: String,
}
#[derive(Parser, Debug)]
@@ -196,24 +224,29 @@ async fn main() {
AccountManage::Help => {
println!("{}", md(t!("jv.account")));
}
+ AccountManage::Add(account_add_args) => todo!(),
+ AccountManage::Remove(account_remove_args) => todo!(),
},
JustEnoughVcsWorkspaceCommand::Create(create_workspace_args) => {
if create_workspace_args.help {
println!("{}", md(t!("jv.create")));
return;
}
+ jv_create(create_workspace_args).await;
}
JustEnoughVcsWorkspaceCommand::Init(init_workspace_args) => {
if init_workspace_args.help {
println!("{}", md(t!("jv.init")));
return;
}
+ jv_init(init_workspace_args).await;
}
JustEnoughVcsWorkspaceCommand::Here(here_args) => {
if here_args.help {
println!("{}", md(t!("jv.here")));
return;
}
+ jv_here(here_args).await;
}
JustEnoughVcsWorkspaceCommand::Sheet(sheet_manage) => match sheet_manage {
SheetManage::Help => {
@@ -226,54 +259,201 @@ async fn main() {
println!("{}", md(t!("jv.track")));
return;
}
+ jv_track(track_file_args).await;
}
JustEnoughVcsWorkspaceCommand::Hold(hold_file_args) => {
if hold_file_args.help {
println!("{}", md(t!("jv.hold")));
return;
}
+ jv_hold(hold_file_args).await;
}
JustEnoughVcsWorkspaceCommand::Throw(throw_file_args) => {
if throw_file_args.help {
println!("{}", md(t!("jv.throw")));
return;
}
+ jv_throw(throw_file_args).await;
}
JustEnoughVcsWorkspaceCommand::Move(move_file_args) => {
if move_file_args.help {
println!("{}", md(t!("jv.move")));
return;
}
+ jv_move(move_file_args).await;
}
JustEnoughVcsWorkspaceCommand::Export(export_file_args) => {
if export_file_args.help {
println!("{}", md(t!("jv.export")));
return;
}
+ jv_export(export_file_args).await;
}
JustEnoughVcsWorkspaceCommand::Import(import_file_args) => {
if import_file_args.help {
println!("{}", md(t!("jv.import")));
return;
}
+ jv_import(import_file_args).await;
}
JustEnoughVcsWorkspaceCommand::Direct(direct_args) => {
if direct_args.help {
println!("{}", md(t!("jv.direct")));
return;
}
+ jv_direct(direct_args).await;
}
JustEnoughVcsWorkspaceCommand::Unstain(unstain_args) => {
if unstain_args.help {
println!("{}", md(t!("jv.unstain")));
return;
}
+ jv_unstain(unstain_args).await;
}
JustEnoughVcsWorkspaceCommand::Docs(docs_args) => {
if docs_args.help {
println!("{}", md(t!("jv.docs")));
return;
}
+ jv_docs(docs_args).await;
+ }
+ }
+}
+
+async fn jv_create(_args: CreateWorkspaceArgs) {
+ todo!()
+}
+
+async fn jv_init(_args: InitWorkspaceArgs) {
+ todo!()
+}
+
+async fn jv_here(_args: HereArgs) {
+ todo!()
+}
+
+async fn jv_track(_args: TrackFileArgs) {
+ todo!()
+}
+
+async fn jv_hold(_args: HoldFileArgs) {
+ todo!()
+}
+
+async fn jv_throw(_args: ThrowFileArgs) {
+ todo!()
+}
+
+async fn jv_move(_args: MoveFileArgs) {
+ todo!()
+}
+
+async fn jv_export(_args: ExportFileArgs) {
+ todo!()
+}
+
+async fn jv_import(_args: ImportFileArgs) {
+ todo!()
+}
+
+async fn jv_direct(args: DirectArgs) {
+ let pool = client_registry::client_action_pool();
+ let upstream = match SocketAddr::from_str(&args.upstream) {
+ Ok(result) => result,
+ Err(_) => {
+ eprintln!(
+ "{}",
+ md(t!(
+ "jv.fail.parse.str_to_sockaddr",
+ str = &args.upstream.trim()
+ ))
+ );
+ return;
+ }
+ };
+ let ctx = ActionContext::local();
+ match proc_set_upstream_vault_action(&pool, ctx, upstream).await {
+ Err(e) => handle_err(e),
+ _ => {}
+ };
+}
+
+async fn jv_unstain(_args: UnstainArgs) {
+ todo!()
+}
+
+async fn jv_docs(_args: DocsArgs) {
+ todo!()
+}
+
+pub fn handle_err(err: TcpTargetError) {
+ let e: Option<(String, String, bool)> = match err {
+ TcpTargetError::Io(err) => Some(fsio(err)),
+ TcpTargetError::File(err) => Some(fsio(err)),
+
+ TcpTargetError::Serialization(err) => Some(serialize(err)),
+
+ TcpTargetError::Authentication(err) => Some(auth(err)),
+
+ TcpTargetError::Network(err) => Some(connection(err)),
+ TcpTargetError::Timeout(err) => Some(connection(err)),
+ TcpTargetError::Protocol(err) => Some(connection(err)),
+
+ _ => Some((
+ err.to_string(),
+ md(t!("jv.fail.action_operation_fail.type_other")),
+ false,
+ )),
+ };
+
+ if let Some((err_text, err_tip, has_tip)) = e {
+ eprintln!(
+ "{}\n{}",
+ md(t!("jv.fail.action_operation_fail.main", err = err_text)),
+ err_tip,
+ );
+
+ if has_tip {
+ eprintln!(
+ "{}",
+ md(t!("jv.fail.action_operation_fail.info_contact_admin"))
+ )
}
}
}
+
+type ErrorText = String;
+type ErrorTip = String;
+type HasTip = bool;
+
+fn fsio(err: String) -> (ErrorText, ErrorTip, HasTip) {
+ (
+ err,
+ md(t!("jv.fail.action_operation_fail.type_fsio")).to_string(),
+ true,
+ )
+}
+
+fn serialize(err: String) -> (ErrorText, ErrorTip, HasTip) {
+ (
+ err,
+ md(t!("jv.fail.action_operation_fail.type_serialize")).to_string(),
+ true,
+ )
+}
+
+fn auth(err: String) -> (ErrorText, ErrorTip, HasTip) {
+ (
+ err,
+ md(t!("jv.fail.action_operation_fail.type_auth")).to_string(),
+ true,
+ )
+}
+
+fn connection(err: String) -> (ErrorText, ErrorTip, HasTip) {
+ (
+ err,
+ md(t!("jv.fail.action_operation_fail.type_connection")).to_string(),
+ true,
+ )
+}