feat: qrlogin command

This commit is contained in:
mokurin000
2025-07-29 20:16:04 +08:00
parent 084d4846d6
commit 097e332aa7
6 changed files with 339 additions and 20 deletions

19
sdgb-cli/src/commands.rs Normal file
View File

@@ -0,0 +1,19 @@
use palc::Parser;
use palc::Subcommand;
#[derive(Parser)]
#[command(about = "SDGB api tool", long_about = env!("CARGO_PKG_DESCRIPTION"))]
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
}
#[derive(Subcommand)]
pub enum Commands {
/// Login with QRCode from wechat
QRLogin {
/// content of the qrcode, only the last 64 characters were used
#[arg(short, long)]
qrcode_content: String,
},
}

View File

@@ -1,6 +1,28 @@
use nyquest_preset::nyquest::ClientBuilder;
use palc::Parser;
use sdgb_api::all_net::QRCode;
use spdlog::{error, info};
use crate::commands::Cli;
mod commands;
#[compio::main]
async fn main() -> Result<(), Box<dyn snafu::Error>> {
nyquest_preset::register();
let cmd = <Cli as Parser>::parse();
let client = ClientBuilder::default().build_async().await?;
match cmd.command {
commands::Commands::QRLogin { ref qrcode_content } => {
let qrcode = QRCode { qrcode_content };
match qrcode.login(&client).await {
Ok(user_id) => info!("login succeed: {user_id}"),
Err(e) => error!("login failed: {e}"),
}
}
}
Ok(())
}