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