You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.1 KiB
Rust

use clap::{App, Arg, SubCommand};
use std::fs::File;
use std::io::Read;
use std::path::Path;
use torment_core::metainfo::Torrent;
fn main() {
let matches = App::new("torment-cli")
.version(env!("CARGO_PKG_VERSION"))
.subcommand(
SubCommand::with_name("torrent")
.about("Shows details about torrent file")
.arg(Arg::with_name("file").required(true)),
)
.get_matches();
match matches.subcommand() {
("torrent", Some(subcmd)) => {
let file = subcmd.value_of("file").unwrap();
let mut bytes: Vec<u8> = vec![];
File::open(file).unwrap().read_to_end(&mut bytes).unwrap();
match Torrent::from_bytes(
&bytes,
Path::new(file)
.file_stem()
.and_then(|file_name| file_name.to_str())
.map(|str| str.to_string()),
) {
Ok(torrent) => {
println!("{:#?}", torrent);
}
Err(err) => println!("Error: {}", err),
}
}
_ => {}
}
}