实现句子翻译
This commit is contained in:
10
src/main.rs
10
src/main.rs
@@ -4,7 +4,8 @@ use serde::Deserialize;
|
|||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[command(name = "fy")]
|
#[command(name = "fy")]
|
||||||
struct Args {
|
struct Args {
|
||||||
input: String,
|
#[arg(trailing_var_arg = true)]
|
||||||
|
input: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
@@ -54,8 +55,13 @@ async fn translate(text: &str) -> Result<String, Box<dyn std::error::Error>> {
|
|||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
let text = args.input.join(" ");
|
||||||
|
if text.is_empty() {
|
||||||
|
eprintln!("Usage: fy <text>");
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
let result = translate(&args.input).await?;
|
let result = translate(&text).await?;
|
||||||
println!("{}", result);
|
println!("{}", result);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user