diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-01-27 06:02:59 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-01-27 06:02:59 +0800 |
| commit | 4eef9ce364bb660421a96052a3fb126a33b22c63 (patch) | |
| tree | a36947411d83205dc743881cd2a30d8c907d4b57 | |
| parent | 243d521fd19af169910506529e737a797e9bc583 (diff) | |
Extract CLI utilities into a separate crate
| -rw-r--r-- | Cargo.lock | 19 | ||||
| -rw-r--r-- | Cargo.toml | 11 | ||||
| -rw-r--r-- | src/bin/jv.rs | 19 | ||||
| -rw-r--r-- | src/bin/jvii.rs | 6 | ||||
| -rw-r--r-- | src/bin/jvn.rs | 10 | ||||
| -rw-r--r-- | src/bin/jvv.rs | 14 | ||||
| -rw-r--r-- | src/cmds/status.rs | 2 | ||||
| -rw-r--r-- | src/lib.rs | 3 | ||||
| -rw-r--r-- | src/renderers/status.rs | 8 | ||||
| -rw-r--r-- | src/systems/cmd.rs | 1 | ||||
| -rw-r--r-- | src/systems/cmd/workspace_reader.rs (renamed from src/utils/workspace_reader.rs) | 0 | ||||
| -rw-r--r-- | utils/Cargo.toml | 25 | ||||
| -rw-r--r-- | utils/src/display.rs (renamed from src/utils/display.rs) | 0 | ||||
| -rw-r--r-- | utils/src/env.rs (renamed from src/utils/env.rs) | 0 | ||||
| -rw-r--r-- | utils/src/fs.rs (renamed from src/utils/fs.rs) | 0 | ||||
| -rw-r--r-- | utils/src/globber.rs (renamed from src/utils/globber.rs) | 2 | ||||
| -rw-r--r-- | utils/src/input.rs (renamed from src/utils/input.rs) | 2 | ||||
| -rw-r--r-- | utils/src/levenshtein_distance.rs (renamed from src/utils/levenshtein_distance.rs) | 0 | ||||
| -rw-r--r-- | utils/src/lib.rs (renamed from src/utils.rs) | 1 | ||||
| -rw-r--r-- | utils/src/logger.rs (renamed from src/utils/logger.rs) | 0 | ||||
| -rw-r--r-- | utils/src/push_version.rs (renamed from src/utils/push_version.rs) | 0 | ||||
| -rw-r--r-- | utils/src/socket_addr_helper.rs (renamed from src/utils/socket_addr_helper.rs) | 0 |
22 files changed, 75 insertions, 48 deletions
@@ -396,6 +396,20 @@ dependencies = [ ] [[package]] +name = "cli_utils" +version = "0.1.0-dev" +dependencies = [ + "chrono", + "colored", + "dirs", + "env_logger", + "just_enough_vcs", + "log", + "strip-ansi-escapes", + "tokio", +] + +[[package]] name = "colorchoice" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -999,18 +1013,15 @@ version = "0.0.0" dependencies = [ "chrono", "clap", + "cli_utils", "colored", "crossterm", - "dirs", - "env_logger", "just_enough_vcs", "log", - "regex", "rust-i18n", "serde", "serde_json", "string_proc", - "strip-ansi-escapes", "thiserror", "tokio", "toml 0.9.8", @@ -6,7 +6,7 @@ authors = ["JustEnoughVCS Team"] homepage = "https://github.com/JustEnoughVCS/CommandLine/" [workspace] -members = ["tools/build_helper"] +members = ["utils/", "tools/build_helper"] [workspace.package] version = "0.1.0-dev" @@ -41,6 +41,9 @@ toml = "0.9" # Just Enough VCS just_enough_vcs = { path = "../VersionControl", features = ["all"] } +# CommandLine Utilities +cli_utils = { path = "utils" } + # Error thiserror = "2.0.17" @@ -56,14 +59,12 @@ chrono = "0.4" # Logging log = "0.4" -env_logger = "0.11" # Async tokio = { version = "1", features = ["full"] } # Display colored = "3.0" -strip-ansi-escapes = "0.2.1" # Terminal crossterm = "0.27" @@ -71,9 +72,5 @@ crossterm = "0.27" # i18n rust-i18n = "3" -# Regex -regex = "1.12.1" - # File & Directory walkdir = "2.5.0" -dirs = "6.0.0" diff --git a/src/bin/jv.rs b/src/bin/jv.rs index a0de5a8..9593c9d 100644 --- a/src/bin/jv.rs +++ b/src/bin/jv.rs @@ -1,3 +1,4 @@ +use cli_utils::input::input_with_editor; use colored::Colorize; use just_enough_vcs::{ data::compile_info::CoreCompileInfo, @@ -92,6 +93,15 @@ use std::{ }; use clap::{Parser, Subcommand}; +use cli_utils::{ + display::{SimpleTable, display_width, md, render_share_path_tree, size_str}, + env::{auto_update_outdate, current_locales, enable_auto_update}, + fs::move_across_partitions, + globber::{GlobItem, Globber}, + input::{confirm_hint, confirm_hint_or, show_in_pager}, + push_version::push_version, + socket_addr_helper, +}; use just_enough_vcs::utils::tcp_connection::error::TcpTargetError; use just_enough_vcs_cli::{ data::{ @@ -107,15 +117,6 @@ use just_enough_vcs_cli::{ share::{SeeShareResult, ShareItem, ShareListResult}, sheets::{SheetItem, SheetListJsonResult}, }, - utils::{ - display::{SimpleTable, display_width, md, render_share_path_tree, size_str}, - env::{auto_update_outdate, current_locales, enable_auto_update}, - fs::move_across_partitions, - globber::{GlobItem, Globber}, - input::{confirm_hint, confirm_hint_or, input_with_editor, show_in_pager}, - push_version::push_version, - socket_addr_helper, - }, }; use rust_i18n::{set_locale, t}; use tokio::{ diff --git a/src/bin/jvii.rs b/src/bin/jvii.rs index 2dfbeb7..2f9cb6d 100644 --- a/src/bin/jvii.rs +++ b/src/bin/jvii.rs @@ -5,6 +5,9 @@ use std::path::PathBuf; use std::time::Duration; use clap::Parser; +use cli_utils::display::display_width; +use cli_utils::display::md; +use cli_utils::env::current_locales; use crossterm::{ QueueableCommand, cursor::MoveTo, @@ -16,9 +19,6 @@ use crossterm::{ enable_raw_mode, }, }; -use just_enough_vcs_cli::utils::display::display_width; -use just_enough_vcs_cli::utils::display::md; -use just_enough_vcs_cli::utils::env::current_locales; use rust_i18n::set_locale; use rust_i18n::t; #[cfg(windows)] diff --git a/src/bin/jvn.rs b/src/bin/jvn.rs index c1d90c9..598be3d 100644 --- a/src/bin/jvn.rs +++ b/src/bin/jvn.rs @@ -1,14 +1,12 @@ use std::process::exit; +use cli_utils::display::md; +use cli_utils::env::current_locales; +use cli_utils::levenshtein_distance::levenshtein_distance; use just_enough_vcs_cli::systems::cmd::_registry::jv_cmd_nodes; use just_enough_vcs_cli::systems::cmd::cmd_system::JVCommandContext; use just_enough_vcs_cli::systems::cmd::errors::{CmdExecuteError, CmdPrepareError, CmdRenderError}; -use just_enough_vcs_cli::utils::display::md; -use just_enough_vcs_cli::utils::levenshtein_distance::levenshtein_distance; -use just_enough_vcs_cli::{ - systems::cmd::{errors::CmdProcessError, processer::jv_cmd_process}, - utils::env::current_locales, -}; +use just_enough_vcs_cli::systems::cmd::{errors::CmdProcessError, processer::jv_cmd_process}; use rust_i18n::{set_locale, t}; rust_i18n::i18n!("resources/locales/jvn", fallback = "en"); diff --git a/src/bin/jvv.rs b/src/bin/jvv.rs index 0e1eaa5..1fae774 100644 --- a/src/bin/jvv.rs +++ b/src/bin/jvv.rs @@ -1,4 +1,9 @@ use clap::{Parser, Subcommand}; +use cli_utils::{ + display::{md, size_str}, + env::current_locales, + logger::build_env_logger, +}; use just_enough_vcs::{ data::compile_info::CoreCompileInfo, utils::{ @@ -15,14 +20,7 @@ use just_enough_vcs::{ env::current_vault_path, }, }; -use just_enough_vcs_cli::{ - data::compile_info::CompileInfo, - utils::{ - display::{md, size_str}, - env::current_locales, - logger::build_env_logger, - }, -}; +use just_enough_vcs_cli::data::compile_info::CompileInfo; use log::{error, info}; use rust_i18n::{set_locale, t}; use tokio::fs::{self}; diff --git a/src/cmds/status.rs b/src/cmds/status.rs index 42d8e27..6f04408 100644 --- a/src/cmds/status.rs +++ b/src/cmds/status.rs @@ -13,8 +13,8 @@ use crate::{ systems::cmd::{ cmd_system::{JVCommand, JVCommandContext}, errors::{CmdExecuteError, CmdPrepareError}, + workspace_reader::LocalWorkspaceReader, }, - utils::workspace_reader::LocalWorkspaceReader, }; pub struct JVStatusCommand; @@ -2,9 +2,6 @@ rust_i18n::i18n!("resources/locales/jvn", fallback = "en"); // --- LIBS --- -/// Utils -pub mod utils; - /// Data pub mod data; diff --git a/src/renderers/status.rs b/src/renderers/status.rs index d51252e..549211e 100644 --- a/src/renderers/status.rs +++ b/src/renderers/status.rs @@ -1,3 +1,7 @@ +use cli_utils::{ + display::{SimpleTable, md}, + env::auto_update_outdate, +}; use rust_i18n::t; use crate::{ @@ -7,10 +11,6 @@ use crate::{ errors::CmdRenderError, renderer::{JVRenderResult, JVResultRenderer}, }, - utils::{ - display::{SimpleTable, md}, - env::auto_update_outdate, - }, }; pub struct JVStatusRenderer; diff --git a/src/systems/cmd.rs b/src/systems/cmd.rs index 8983892..ea8bbd7 100644 --- a/src/systems/cmd.rs +++ b/src/systems/cmd.rs @@ -3,3 +3,4 @@ pub mod cmd_system; pub mod errors; pub mod processer; pub mod renderer; +pub mod workspace_reader; diff --git a/src/utils/workspace_reader.rs b/src/systems/cmd/workspace_reader.rs index c001330..c001330 100644 --- a/src/utils/workspace_reader.rs +++ b/src/systems/cmd/workspace_reader.rs diff --git a/utils/Cargo.toml b/utils/Cargo.toml new file mode 100644 index 0000000..b4df110 --- /dev/null +++ b/utils/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "cli_utils" +edition = "2024" +version.workspace = true + +[dependencies] +# Just Enough VCS +just_enough_vcs = { path = "../../VersionControl", features = ["all"] } + +# Display +colored = "3.0" +strip-ansi-escapes = "0.2.1" + +# Async +tokio = { version = "1", features = ["full"] } + +# Logging +log = "0.4" +env_logger = "0.11" + +# File & Directory +dirs = "6.0.0" + +# Time +chrono = "0.4" diff --git a/src/utils/display.rs b/utils/src/display.rs index 835313b..835313b 100644 --- a/src/utils/display.rs +++ b/utils/src/display.rs diff --git a/src/utils/env.rs b/utils/src/env.rs index 81dfbd7..81dfbd7 100644 --- a/src/utils/env.rs +++ b/utils/src/env.rs diff --git a/src/utils/fs.rs b/utils/src/fs.rs index 0050cf1..0050cf1 100644 --- a/src/utils/fs.rs +++ b/utils/src/fs.rs diff --git a/src/utils/globber.rs b/utils/src/globber.rs index dbb77ea..e20caf9 100644 --- a/src/utils/globber.rs +++ b/utils/src/globber.rs @@ -2,7 +2,7 @@ use std::{io::Error, path::PathBuf, str::FromStr}; use just_enough_vcs::utils::string_proc::format_path::format_path_str; -use crate::utils::globber::constants::{SPLIT_STR, get_base_dir_current}; +use crate::globber::constants::{SPLIT_STR, get_base_dir_current}; pub struct Globber { pattern: String, diff --git a/src/utils/input.rs b/utils/src/input.rs index 1edcc5d..80ea569 100644 --- a/src/utils/input.rs +++ b/utils/src/input.rs @@ -1,6 +1,6 @@ use tokio::{fs, process::Command}; -use crate::utils::env::get_default_editor; +use crate::env::get_default_editor; /// Confirm the current operation /// Waits for user input of 'y' or 'n' diff --git a/src/utils/levenshtein_distance.rs b/utils/src/levenshtein_distance.rs index 6bdb7e7..6bdb7e7 100644 --- a/src/utils/levenshtein_distance.rs +++ b/utils/src/levenshtein_distance.rs diff --git a/src/utils.rs b/utils/src/lib.rs index 7d3cb5e..682c679 100644 --- a/src/utils.rs +++ b/utils/src/lib.rs @@ -7,4 +7,3 @@ pub mod levenshtein_distance; pub mod logger; pub mod push_version; pub mod socket_addr_helper; -pub mod workspace_reader; diff --git a/src/utils/logger.rs b/utils/src/logger.rs index 7dd4f62..7dd4f62 100644 --- a/src/utils/logger.rs +++ b/utils/src/logger.rs diff --git a/src/utils/push_version.rs b/utils/src/push_version.rs index 6da9039..6da9039 100644 --- a/src/utils/push_version.rs +++ b/utils/src/push_version.rs diff --git a/src/utils/socket_addr_helper.rs b/utils/src/socket_addr_helper.rs index 29ccd9f..29ccd9f 100644 --- a/src/utils/socket_addr_helper.rs +++ b/utils/src/socket_addr_helper.rs |
