From 468797fe21ce1a70f592f5004bcd07a831e5be87 Mon Sep 17 00:00:00 2001 From: hzxjy Date: Wed, 6 Dec 2023 22:13:19 +0800 Subject: [PATCH] fix: streamline module functionality --- Cargo.lock | 86 -------------------------------------- maa-cli/Cargo.toml | 1 - maa-cli/src/main.rs | 7 +--- maa-cli/src/run/copilot.rs | 15 +------ 4 files changed, 3 insertions(+), 106 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 64acfc5c..d4d9b25f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -125,12 +125,6 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" -[[package]] -name = "block" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" - [[package]] name = "block-buffer" version = "0.10.4" @@ -235,28 +229,6 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" -[[package]] -name = "clipboard" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25a904646c0340239dcf7c51677b33928bf24fdf424b79a57909c0109075b2e7" -dependencies = [ - "clipboard-win", - "objc", - "objc-foundation", - "objc_id", - "x11-clipboard", -] - -[[package]] -name = "clipboard-win" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3a093d6fed558e5fe24c3dfc85a68bb68f1c824f440d3ba5aca189e2998786b" -dependencies = [ - "winapi", -] - [[package]] name = "colorchoice" version = "1.0.0" @@ -834,7 +806,6 @@ dependencies = [ "chrono", "clap", "clap_complete", - "clipboard", "digest", "directories", "dunce", @@ -868,15 +839,6 @@ dependencies = [ "libloading", ] -[[package]] -name = "malloc_buf" -version = "0.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" -dependencies = [ - "libc", -] - [[package]] name = "memchr" version = "2.6.4" @@ -934,35 +896,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" -[[package]] -name = "objc" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" -dependencies = [ - "malloc_buf", -] - -[[package]] -name = "objc-foundation" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" -dependencies = [ - "block", - "objc", - "objc_id", -] - -[[package]] -name = "objc_id" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b" -dependencies = [ - "objc", -] - [[package]] name = "object" version = "0.32.1" @@ -1978,15 +1911,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "x11-clipboard" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89bd49c06c9eb5d98e6ba6536cf64ac9f7ee3a009b2f53996d405b3944f6bcea" -dependencies = [ - "xcb", -] - [[package]] name = "xattr" version = "1.0.1" @@ -1996,16 +1920,6 @@ dependencies = [ "libc", ] -[[package]] -name = "xcb" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e917a3f24142e9ff8be2414e36c649d47d6cc2ba81f16201cdef96e533e02de" -dependencies = [ - "libc", - "log", -] - [[package]] name = "zip" version = "0.6.6" diff --git a/maa-cli/Cargo.toml b/maa-cli/Cargo.toml index 41c3e1f0..5bc09f90 100644 --- a/maa-cli/Cargo.toml +++ b/maa-cli/Cargo.toml @@ -46,7 +46,6 @@ semver = { version = "1.0.19", features = ["serde"] } flate2 = { version = "1", optional = true } tar = { version = "0.4.40", optional = true } prettytable = "0.10.0" -clipboard = "0.5.0" [dependencies.chrono] version = "0.4.31" diff --git a/maa-cli/src/main.rs b/maa-cli/src/main.rs index 33f5341b..1297f904 100644 --- a/maa-cli/src/main.rs +++ b/maa-cli/src/main.rs @@ -140,10 +140,7 @@ enum SubCommand { Copilot { /// A code copied from "https://prts.plus" or a json file, /// such as "maa://12345" or "/your/json/path.json". - uri: Option, - #[arg(short, long)] - /// Allow maa to read the clipboard - paste: bool, + uri: String, #[command(flatten)] common: run::CommonArgs, }, @@ -307,7 +304,7 @@ fn main() -> Result<()> { SubCommand::Complete { shell } => { generate(shell, &mut CLI::command(), "maa", &mut std::io::stdout()); } - SubCommand::Copilot { uri, paste, common } => run::copilot(uri, paste, common)?, + SubCommand::Copilot { uri, common } => run::copilot(uri, common)?, } Ok(()) diff --git a/maa-cli/src/run/copilot.rs b/maa-cli/src/run/copilot.rs index 109b1dc1..d69a551b 100644 --- a/maa-cli/src/run/copilot.rs +++ b/maa-cli/src/run/copilot.rs @@ -12,7 +12,6 @@ use crate::{ use anyhow::Result; use anyhow::{anyhow, Error}; use anyhow::{Context, Ok}; -use clipboard::{ClipboardContext, ClipboardProvider}; use prettytable::{format, row, Table}; use reqwest::blocking::Client; use serde_json::{from_str, Value as JsonValue}; @@ -22,12 +21,7 @@ use std::{ path::{Path, PathBuf}, }; -pub fn copilot(uri_opt: Option, paste: bool, common: CommonArgs) -> Result<()> { - let uri = if paste { - clipboard_reader()? - } else { - uri_opt.ok_or_else(|| anyhow!("No input"))? - }; +pub fn copilot(uri: String, common: CommonArgs) -> Result<()> { debug!("uri: ", uri); let jpr = "JSON Prase Error"; let results = json_reader(&uri)?; @@ -187,10 +181,3 @@ fn find_json(json_file_name: &str, mut dir_path: PathBuf) -> Result { Ok(json_value) } - -fn clipboard_reader() -> Result { - let mut ctx: ClipboardContext = ClipboardProvider::new().map_err(|err| anyhow!("{}", err))?; - let content = ctx.get_contents().map_err(|err| anyhow!("{}", err))?; - - Ok(content) -}