From 3276f2d043d93d4c478c3187cc2e179f781df049 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Sat, 7 Mar 2020 20:10:59 -0800 Subject: [PATCH] Add short flags to `imdl torrent {show,verify}` type: added --- src/subcommand/torrent/show.rs | 1 + src/subcommand/torrent/verify.rs | 69 +++++++++++++++++++++++++++----- 2 files changed, 61 insertions(+), 9 deletions(-) diff --git a/src/subcommand/torrent/show.rs b/src/subcommand/torrent/show.rs index 816e5b4..49c3059 100644 --- a/src/subcommand/torrent/show.rs +++ b/src/subcommand/torrent/show.rs @@ -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) diff --git a/src/subcommand/torrent/verify.rs b/src/subcommand/torrent/verify.rs index d9fa9fa..3748229 100644 --- a/src/subcommand/torrent/verify.rs +++ b/src/subcommand/torrent/verify.rs @@ -8,20 +8,22 @@ 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, + content: Option, } impl Verify { @@ -29,8 +31,8 @@ impl Verify { 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) }; @@ -87,7 +89,7 @@ mod tests { args: [ "torrent", "verify", - "--metainfo", + "--input", torrent, ], tree: {}, @@ -130,7 +132,7 @@ mod tests { args: [ "torrent", "verify", - "--metainfo", + "--input", torrent, ], tree: {}, @@ -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(()) + } }