- clean up dead code - fix lints - move Session type to legacy module - refactor service names into constants - refactor build_url to be less restrictive for service names - refactor most commands into their own modules
55 lines
1.3 KiB
Rust
55 lines
1.3 KiB
Rust
use std::sync::{Arc, Mutex};
|
|
|
|
use log::*;
|
|
use qrcode::QrCode;
|
|
use secrecy::ExposeSecret;
|
|
|
|
use crate::AccountManager;
|
|
|
|
use super::*;
|
|
|
|
#[derive(Debug, Clone, Parser)]
|
|
#[clap(about = "Generate QR codes. This *will* print sensitive data to stdout.")]
|
|
pub struct QrCommand {
|
|
#[clap(
|
|
long,
|
|
help = "Force using ASCII chars to generate QR codes. Useful for terminals that don't support unicode."
|
|
)]
|
|
pub ascii: bool,
|
|
}
|
|
|
|
impl AccountCommand for QrCommand {
|
|
fn execute(
|
|
&self,
|
|
_manager: &mut AccountManager,
|
|
accounts: Vec<Arc<Mutex<SteamGuardAccount>>>,
|
|
) -> anyhow::Result<()> {
|
|
use anyhow::Context;
|
|
|
|
info!("Generating QR codes for {} accounts", accounts.len());
|
|
|
|
for account in accounts {
|
|
let account = account.lock().unwrap();
|
|
let qr = QrCode::new(account.uri.expose_secret())
|
|
.context(format!("generating qr code for {}", account.account_name))?;
|
|
|
|
info!("Printing QR code for {}", account.account_name);
|
|
let qr_string = if self.ascii {
|
|
qr.render()
|
|
.light_color(' ')
|
|
.dark_color('#')
|
|
.module_dimensions(2, 1)
|
|
.build()
|
|
} else {
|
|
use qrcode::render::unicode;
|
|
qr.render::<unicode::Dense1x2>()
|
|
.dark_color(unicode::Dense1x2::Light)
|
|
.light_color(unicode::Dense1x2::Dark)
|
|
.build()
|
|
};
|
|
|
|
println!("{}", qr_string);
|
|
}
|
|
Ok(())
|
|
}
|
|
}
|