feat: qrlogin command
This commit is contained in:
@@ -2,12 +2,21 @@
|
||||
name = "sdgb-cli"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
authors = ["mokurin000"]
|
||||
description = "CLI tool for SDGB protocol"
|
||||
|
||||
[dependencies]
|
||||
snafu = { workspace = true }
|
||||
sdgb-api = { workspace = true }
|
||||
|
||||
nyquest-preset = { version = "0.2.0", features = ["async"] }
|
||||
compio = { version = "0.15.0", default-features = false, features = [
|
||||
"runtime",
|
||||
"macros",
|
||||
] }
|
||||
|
||||
palc = { version = "0.0.1", features = ["derive"] }
|
||||
spdlog-rs = { version = "0.4.3", default-features = false, features = [
|
||||
"level-info",
|
||||
"release-level-info",
|
||||
] }
|
||||
|
||||
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