Files
qbt-rs/src/action/magnet.rs
T
2022-10-20 01:28:11 +02:00

27 lines
667 B
Rust

use argh::FromArgs;
use crate::Error;
use crate::action::ActionExec;
use crate::config::Config;
use crate::utils::torrent_to_magnet;
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "magnet")]
/// produce magnet link from torrent file
pub struct MagnetAction {
#[argh(positional)]
/// the magnet torrent file to parse
torrent: String,
}
impl ActionExec for MagnetAction {
fn exec(&self, _config: &Config) -> Result<(), Error> {
if self.torrent.starts_with("magnet:") {
println!("{}", &self.torrent);
} else {
println!("{}", torrent_to_magnet(&self.torrent)?);
}
Ok(())
}
}