Skip to content

Commit

Permalink
fix: streamline module functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
hzxjy1 committed Dec 6, 2023
1 parent 3dd2307 commit 468797f
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 106 deletions.
86 changes: 0 additions & 86 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion maa-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 2 additions & 5 deletions maa-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
#[arg(short, long)]
/// Allow maa to read the clipboard
paste: bool,
uri: String,
#[command(flatten)]
common: run::CommonArgs,
},
Expand Down Expand Up @@ -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)?,

Check warning on line 307 in maa-cli/src/main.rs

View check run for this annotation

Codecov / codecov/patch

maa-cli/src/main.rs#L307

Added line #L307 was not covered by tests
}

Ok(())
Expand Down
15 changes: 1 addition & 14 deletions maa-cli/src/run/copilot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -22,12 +21,7 @@ use std::{
path::{Path, PathBuf},
};

pub fn copilot(uri_opt: Option<String>, 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)?;
Expand Down Expand Up @@ -187,10 +181,3 @@ fn find_json(json_file_name: &str, mut dir_path: PathBuf) -> Result<JsonValue> {

Ok(json_value)

Check warning on line 182 in maa-cli/src/run/copilot.rs

View check run for this annotation

Codecov / codecov/patch

maa-cli/src/run/copilot.rs#L182

Added line #L182 was not covered by tests
}

fn clipboard_reader() -> Result<String> {
let mut ctx: ClipboardContext = ClipboardProvider::new().map_err(|err| anyhow!("{}", err))?;
let content = ctx.get_contents().map_err(|err| anyhow!("{}", err))?;

Ok(content)
}

0 comments on commit 468797f

Please sign in to comment.