Add short flags to imdl torrent {show,verify}
type: added
This commit is contained in:
parent
027b229df1
commit
3276f2d043
|
@ -9,6 +9,7 @@ use crate::common::*;
|
||||||
pub(crate) struct Show {
|
pub(crate) struct Show {
|
||||||
#[structopt(
|
#[structopt(
|
||||||
long = "input",
|
long = "input",
|
||||||
|
short = "i",
|
||||||
value_name = "PATH",
|
value_name = "PATH",
|
||||||
help = "Show information about torrent at `PATH`.",
|
help = "Show information about torrent at `PATH`.",
|
||||||
parse(from_os_str)
|
parse(from_os_str)
|
||||||
|
|
|
@ -8,20 +8,22 @@ use crate::common::*;
|
||||||
)]
|
)]
|
||||||
pub(crate) struct Verify {
|
pub(crate) struct Verify {
|
||||||
#[structopt(
|
#[structopt(
|
||||||
long = "metainfo",
|
long = "input",
|
||||||
value_name = "FILE",
|
short = "i",
|
||||||
|
value_name = "METAINFO",
|
||||||
help = "Verify torrent contents against torrent metainfo in `FILE`.",
|
help = "Verify torrent contents against torrent metainfo in `FILE`.",
|
||||||
parse(from_os_str)
|
parse(from_os_str)
|
||||||
)]
|
)]
|
||||||
metainfo: PathBuf,
|
metainfo: PathBuf,
|
||||||
#[structopt(
|
#[structopt(
|
||||||
long = "input",
|
long = "content",
|
||||||
|
short = "c",
|
||||||
value_name = "PATH",
|
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.",
|
of torrent info dictionary.",
|
||||||
parse(from_os_str)
|
parse(from_os_str)
|
||||||
)]
|
)]
|
||||||
input: Option<PathBuf>,
|
content: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Verify {
|
impl Verify {
|
||||||
|
@ -29,8 +31,8 @@ impl Verify {
|
||||||
let metainfo_path = env.resolve(&self.metainfo);
|
let metainfo_path = env.resolve(&self.metainfo);
|
||||||
let metainfo = Metainfo::load(&metainfo_path)?;
|
let metainfo = Metainfo::load(&metainfo_path)?;
|
||||||
|
|
||||||
let base = if let Some(input) = &self.input {
|
let base = if let Some(content) = &self.content {
|
||||||
env.resolve(input)
|
env.resolve(content)
|
||||||
} else {
|
} else {
|
||||||
metainfo_path.parent().unwrap().join(&metainfo.info.name)
|
metainfo_path.parent().unwrap().join(&metainfo.info.name)
|
||||||
};
|
};
|
||||||
|
@ -87,7 +89,7 @@ mod tests {
|
||||||
args: [
|
args: [
|
||||||
"torrent",
|
"torrent",
|
||||||
"verify",
|
"verify",
|
||||||
"--metainfo",
|
"--input",
|
||||||
torrent,
|
torrent,
|
||||||
],
|
],
|
||||||
tree: {},
|
tree: {},
|
||||||
|
@ -130,7 +132,7 @@ mod tests {
|
||||||
args: [
|
args: [
|
||||||
"torrent",
|
"torrent",
|
||||||
"verify",
|
"verify",
|
||||||
"--metainfo",
|
"--input",
|
||||||
torrent,
|
torrent,
|
||||||
],
|
],
|
||||||
tree: {},
|
tree: {},
|
||||||
|
@ -142,4 +144,53 @@ mod tests {
|
||||||
|
|
||||||
Ok(())
|
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(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user