diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/bin/jv.rs | 274 | ||||
| -rw-r--r-- | src/bin/jvv.rs | 44 |
2 files changed, 299 insertions, 19 deletions
diff --git a/src/bin/jv.rs b/src/bin/jv.rs index a8b0a1f..9530203 100644 --- a/src/bin/jv.rs +++ b/src/bin/jv.rs @@ -1,7 +1,279 @@ +use clap::{Parser, Subcommand, arg, command}; +use just_enough_vcs_cli::utils::{lang_selector::current_locales, md_colored::md}; +use rust_i18n::{set_locale, t}; + // Import i18n files rust_i18n::i18n!("locales", fallback = "en"); +#[derive(Parser, Debug)] +#[command( + disable_help_flag = true, + disable_version_flag = true, + disable_help_subcommand = true, + help_template = "{all-args}" +)] + +struct JustEnoughVcsWorkspace { + #[command(subcommand)] + command: JustEnoughVcsWorkspaceCommand, +} + +#[derive(Subcommand, Debug)] +enum JustEnoughVcsWorkspaceCommand { + // Member management + /// Manage your local accounts + #[command(subcommand)] + Account(AccountManage), + + /// Create an empty workspace + Create(CreateWorkspaceArgs), + + /// Create an empty workspace in the current directory + Init(InitWorkspaceArgs), + + /// Get workspace information in the current directory + #[command(alias = "h")] + Here(HereArgs), + + // Sheet management + /// Manage sheets in the workspace + #[command(subcommand)] + Sheet(SheetManage), + + // File management + /// Track files to the upstream vault + /// First track - Create and upload the "First Version", then hold them + /// Subsequent tracks - Update files with new versions + #[command(alias = "t")] + Track(TrackFileArgs), + + /// Hold files for editing + #[command(alias = "hd")] + Hold(HoldFileArgs), + + /// Throw files, and release edit rights + #[command(alias = "tr")] + Throw(ThrowFileArgs), + + /// Move or rename files safely + #[command(alias = "mv")] + Move(MoveFileArgs), + + /// Export files to other worksheet + #[command(alias = "out")] + Export(ExportFileArgs), + + /// Import files from reference sheet or import area + #[command(alias = "in")] + Import(ImportFileArgs), + + // Connection management + /// Direct to an upstream vault and stain this workspace + Direct(DirectArgs), + + /// DANGER ZONE : Unstain this workspace + Unstain(UnstainArgs), + + // Other + /// Query built-in documentation + Docs(DocsArgs), +} + +#[derive(Subcommand, Debug)] +enum AccountManage { + /// Show help information + #[command(alias = "--help", alias = "-h")] + Help, +} + +#[derive(Subcommand, Debug)] +enum SheetManage { + /// Show help information + #[command(alias = "--help", alias = "-h")] + Help, +} + +#[derive(Parser, Debug)] +struct CreateWorkspaceArgs { + /// Show help information + #[arg(short, long)] + help: bool, +} + +#[derive(Parser, Debug)] +struct InitWorkspaceArgs { + /// Show help information + #[arg(short, long)] + help: bool, +} + +#[derive(Parser, Debug)] +struct HereArgs { + /// Show help information + #[arg(short, long)] + help: bool, +} + +#[derive(Parser, Debug)] +struct TrackFileArgs { + /// Show help information + #[arg(short, long)] + help: bool, +} + +#[derive(Parser, Debug)] +struct HoldFileArgs { + /// Show help information + #[arg(short, long)] + help: bool, +} + +#[derive(Parser, Debug)] +struct ThrowFileArgs { + /// Show help information + #[arg(short, long)] + help: bool, +} + +#[derive(Parser, Debug)] +struct MoveFileArgs { + /// Show help information + #[arg(short, long)] + help: bool, +} + +#[derive(Parser, Debug)] +struct ExportFileArgs { + /// Show help information + #[arg(short, long)] + help: bool, +} + +#[derive(Parser, Debug)] +struct ImportFileArgs { + /// Show help information + #[arg(short, long)] + help: bool, +} + +#[derive(Parser, Debug)] +struct DirectArgs { + /// Show help information + #[arg(short, long)] + help: bool, +} + +#[derive(Parser, Debug)] +struct UnstainArgs { + /// Show help information + #[arg(short, long)] + help: bool, +} + +#[derive(Parser, Debug)] +struct DocsArgs { + /// Show help information + #[arg(short, long)] + help: bool, +} + #[tokio::main] async fn main() { - println!("Hello, World!") + // Init i18n + set_locale(¤t_locales()); + + // Init colored + #[cfg(windows)] + colored::control::set_virtual_terminal(true).unwrap(); + + let Ok(parser) = JustEnoughVcsWorkspace::try_parse() else { + println!("{}", md(t!("jv.help"))); + return; + }; + + match parser.command { + JustEnoughVcsWorkspaceCommand::Account(account_manage) => match account_manage { + AccountManage::Help => { + println!("{}", md(t!("jv.account"))); + } + }, + JustEnoughVcsWorkspaceCommand::Create(create_workspace_args) => { + if create_workspace_args.help { + println!("{}", md(t!("jv.create"))); + return; + } + } + JustEnoughVcsWorkspaceCommand::Init(init_workspace_args) => { + if init_workspace_args.help { + println!("{}", md(t!("jv.init"))); + return; + } + } + JustEnoughVcsWorkspaceCommand::Here(here_args) => { + if here_args.help { + println!("{}", md(t!("jv.here"))); + return; + } + } + JustEnoughVcsWorkspaceCommand::Sheet(sheet_manage) => match sheet_manage { + SheetManage::Help => { + println!("{}", md(t!("jv.sheet"))); + return; + } + }, + JustEnoughVcsWorkspaceCommand::Track(track_file_args) => { + if track_file_args.help { + println!("{}", md(t!("jv.track"))); + return; + } + } + JustEnoughVcsWorkspaceCommand::Hold(hold_file_args) => { + if hold_file_args.help { + println!("{}", md(t!("jv.hold"))); + return; + } + } + JustEnoughVcsWorkspaceCommand::Throw(throw_file_args) => { + if throw_file_args.help { + println!("{}", md(t!("jv.throw"))); + return; + } + } + JustEnoughVcsWorkspaceCommand::Move(move_file_args) => { + if move_file_args.help { + println!("{}", md(t!("jv.move"))); + return; + } + } + JustEnoughVcsWorkspaceCommand::Export(export_file_args) => { + if export_file_args.help { + println!("{}", md(t!("jv.export"))); + return; + } + } + JustEnoughVcsWorkspaceCommand::Import(import_file_args) => { + if import_file_args.help { + println!("{}", md(t!("jv.import"))); + return; + } + } + JustEnoughVcsWorkspaceCommand::Direct(direct_args) => { + if direct_args.help { + println!("{}", md(t!("jv.direct"))); + return; + } + } + JustEnoughVcsWorkspaceCommand::Unstain(unstain_args) => { + if unstain_args.help { + println!("{}", md(t!("jv.unstain"))); + return; + } + } + JustEnoughVcsWorkspaceCommand::Docs(docs_args) => { + if docs_args.help { + println!("{}", md(t!("jv.docs"))); + return; + } + } + } } diff --git a/src/bin/jvv.rs b/src/bin/jvv.rs index 1dd2275..50dc3b3 100644 --- a/src/bin/jvv.rs +++ b/src/bin/jvv.rs @@ -8,7 +8,7 @@ use just_enough_vcs::{ }, vcs::{ connection::action_service::server_entry, - constants::{SERVER_FILE_VAULT, SERVER_FILE_VF_META}, + constants::SERVER_FILE_VAULT, current::current_vault_path, data::{ member::Member, @@ -35,11 +35,11 @@ rust_i18n::i18n!("locales/help_docs", fallback = "en"); )] struct JustEnoughVcsVault { #[command(subcommand)] - command: JustEnoughVcsCommand, + command: JustEnoughVcsVaultCommand, } #[derive(Subcommand, Debug)] -enum JustEnoughVcsCommand { +enum JustEnoughVcsVaultCommand { /// Get vault info in the current directory Here(HereArgs), @@ -161,28 +161,28 @@ async fn main() { }; match parser.command { - JustEnoughVcsCommand::Here(here_args) => { + JustEnoughVcsVaultCommand::Here(here_args) => { if here_args.help { println!("{}", md(t!("jvv.here"))); return; } jvv_here(here_args).await; } - JustEnoughVcsCommand::Create(create_vault_args) => { + JustEnoughVcsVaultCommand::Create(create_vault_args) => { if create_vault_args.help { println!("{}", md(t!("jvv.create"))); return; } jvv_create(create_vault_args).await; } - JustEnoughVcsCommand::Init(init_vault_args) => { + JustEnoughVcsVaultCommand::Init(init_vault_args) => { if init_vault_args.help { println!("{}", md(t!("jvv.init"))); return; } jvv_init(init_vault_args).await; } - JustEnoughVcsCommand::Member(member_manage) => { + JustEnoughVcsVaultCommand::Member(member_manage) => { let vault_cfg = VaultConfig::read() .await .unwrap_or_else(|_| panic!("{}", t!("jvv.fail.no_vault_here").trim().to_string())); @@ -226,7 +226,7 @@ async fn main() { } } } - JustEnoughVcsCommand::Service(service_manage) => match service_manage { + JustEnoughVcsVaultCommand::Service(service_manage) => match service_manage { ServiceManage::Listen(listen_args) => { if listen_args.help { println!("{}", md(t!("jvv.service"))); @@ -284,14 +284,8 @@ async fn jvv_here(_args: HereArgs) { while let Ok(Some(entry)) = entries.next_entry().await { if let Ok(metadata) = entry.metadata().await { if metadata.is_file() { - if entry - .file_name() - .to_string_lossy() - .ends_with(SERVER_FILE_VF_META) - { - num_vf += 1; - total_size += metadata.len(); - } + num_vf += 1; + total_size += metadata.len(); } } } @@ -332,6 +326,21 @@ async fn jvv_here(_args: HereArgs) { }; let num_ref_sheet_managed_files = ref_sheet.mapping().len(); + let total_size_str = if total_size < 1024 { + format!("{} B", total_size) + } else if total_size < 1024 * 1024 { + format!("{:.2} KB", total_size as f64 / 1024.0) + } else if total_size < 1024 * 1024 * 1024 { + format!("{:.2} MB", total_size as f64 / (1024.0 * 1024.0)) + } else if total_size < 1024 * 1024 * 1024 * 1024 { + format!("{:.2} GB", total_size as f64 / (1024.0 * 1024.0 * 1024.0)) + } else { + format!( + "{:.2} TB", + total_size as f64 / (1024.0 * 1024.0 * 1024.0 * 1024.0) + ) + }; + // Success println!( "{}", @@ -340,11 +349,10 @@ async fn jvv_here(_args: HereArgs) { name = vault_name, num_sheets = num_sheets, num_vf = num_vf, - total_size = total_size, num_mem = num_mem, num_pk = num_pk, num_ref_sheet_managed_files = num_ref_sheet_managed_files, - total_size_gb = (total_size as f64) / (1024.0 * 1024.0 * 1024.0) + total_size = total_size_str )) ) } |
