Skip to content

Commit

Permalink
Add short flags to imdl torrent {show,verify}
Browse files Browse the repository at this point in the history
type: added
  • Loading branch information
casey committed Apr 8, 2020
1 parent 027b229 commit 3276f2d
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/subcommand/torrent/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::common::*;
pub(crate) struct Show {
#[structopt(
long = "input",
short = "i",
value_name = "PATH",
help = "Show information about torrent at `PATH`.",
parse(from_os_str)
Expand Down
69 changes: 60 additions & 9 deletions src/subcommand/torrent/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,31 @@ use crate::common::*;
)]
pub(crate) struct Verify {
#[structopt(
long = "metainfo",
value_name = "FILE",
long = "input",
short = "i",
value_name = "METAINFO",
help = "Verify torrent contents against torrent metainfo in `FILE`.",
parse(from_os_str)
)]
metainfo: PathBuf,
#[structopt(
long = "input",
long = "content",
short = "c",
value_name = "PATH",
help = "Verify torrent contents at `PATH` against torrent metainfo. Defaults to `name` field \
help = "Verify torrent content at `PATH` against torrent metainfo. Defaults to `name` field \
of torrent info dictionary.",
parse(from_os_str)
)]
input: Option<PathBuf>,
content: Option<PathBuf>,
}

impl Verify {
pub(crate) fn run(self, env: &mut Env) -> Result<(), Error> {
let metainfo_path = env.resolve(&self.metainfo);
let metainfo = Metainfo::load(&metainfo_path)?;

let base = if let Some(input) = &self.input {
env.resolve(input)
let base = if let Some(content) = &self.content {
env.resolve(content)
} else {
metainfo_path.parent().unwrap().join(&metainfo.info.name)
};
Expand Down Expand Up @@ -87,7 +89,7 @@ mod tests {
args: [
"torrent",
"verify",
"--metainfo",
"--input",
torrent,
],
tree: {},
Expand Down Expand Up @@ -130,7 +132,7 @@ mod tests {
args: [
"torrent",
"verify",
"--metainfo",
"--input",
torrent,
],
tree: {},
Expand All @@ -142,4 +144,53 @@ mod tests {

Ok(())
}

#[test]
fn alternate_path() -> Result<()> {
let mut create_env = test_env! {
args: [
"torrent",
"create",
"--input",
"foo",
"--announce",
"https://bar",
],
tree: {
foo: {
a: "abc",
d: "efg",
h: "ijk",
},
},
};

create_env.run()?;

let torrent = create_env.resolve("foo.torrent");

let foo = create_env.resolve("foo");

let bar = create_env.resolve("bar");

fs::rename(&foo, &bar).unwrap();

let mut verify_env = test_env! {
args: [
"torrent",
"verify",
"--input",
torrent,
"--content",
bar,
],
tree: {},
};

assert_matches!(verify_env.run(), Ok(()));

assert_eq!(verify_env.err(), "Verification succeeded.\n");

Ok(())
}
}

0 comments on commit 3276f2d

Please sign in to comment.