28 lines
685 B
Rust
28 lines
685 B
Rust
use argh::FromArgs;
|
|
|
|
use crate::Error;
|
|
use crate::action::ActionExec;
|
|
use crate::config::Config;
|
|
use crate::utils::{magnet_name, torrent_name};
|
|
|
|
#[derive(FromArgs, PartialEq, Debug)]
|
|
#[argh(subcommand, name = "name")]
|
|
/// get name from magnet/torrent
|
|
pub struct NameAction {
|
|
#[argh(positional)]
|
|
/// the magnet link or torrent file to parse
|
|
torrent: String,
|
|
}
|
|
|
|
impl ActionExec for NameAction {
|
|
fn exec(&self, _config: &Config) -> Result<(), Error> {
|
|
let name = if self.torrent.starts_with("magnet:") {
|
|
magnet_name(&self.torrent)
|
|
} else {
|
|
torrent_name(&self.torrent)
|
|
};
|
|
println!("{}", name);
|
|
Ok(())
|
|
}
|
|
}
|