feat: qrlogin command
This commit is contained in:
19
sdgb-cli/src/commands.rs
Normal file
19
sdgb-cli/src/commands.rs
Normal 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,
|
||||
},
|
||||
}
|
||||
@@ -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(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user