Fix help strings

Fix inconsistent argument value names in help strings.

type: fixed
This commit is contained in:
Casey Rodarmor 2020-04-22 00:28:07 -07:00
parent ebec2d591a
commit cecd2f66a5
No known key found for this signature in database
GPG Key ID: 556186B153EC6FE0
5 changed files with 126 additions and 17 deletions

View File

@ -4,7 +4,8 @@ Changelog
UNRELEASED - 2020-04-22 UNRELEASED - 2020-04-22
----------------------- -----------------------
- :zap: [`xxxxxxxxxxxx`](https://github.com/casey/intermodal/commits/master) Allow positional shell to `imdl completions` - Fixes [#375](https://github.com/casey/intermodal/issues/375) - _Casey Rodarmor <casey@rodarmor.com>_ - :bug: [`xxxxxxxxxxxx`](https://github.com/casey/intermodal/commits/master) Fix help strings - _Casey Rodarmor <casey@rodarmor.com>_
- :zap: [`ebec2d591a7a`](https://github.com/casey/intermodal/commit/ebec2d591a7a0e2a2c4cd55217db4ba46b5dd9ed) Allow positional shell to `imdl completions` - Fixes [#375](https://github.com/casey/intermodal/issues/375) - _Casey Rodarmor <casey@rodarmor.com>_
- :art: [`134c241ae7f8`](https://github.com/casey/intermodal/commit/134c241ae7f8e374d8a9266e7eb0c4a9c3844c30) Use `lexiclean` crate for lexical path cleaning - _Casey Rodarmor <casey@rodarmor.com>_ - :art: [`134c241ae7f8`](https://github.com/casey/intermodal/commit/134c241ae7f8e374d8a9266e7eb0c4a9c3844c30) Use `lexiclean` crate for lexical path cleaning - _Casey Rodarmor <casey@rodarmor.com>_
- :zap: [`323434d0aa21`](https://github.com/casey/intermodal/commit/323434d0aa21ebfda5be85ecd4a38a55ed3fec0a) Allow positional input to `imdl torrent verify` - Fixes [#375](https://github.com/casey/intermodal/issues/375) - _Casey Rodarmor <casey@rodarmor.com>_ - :zap: [`323434d0aa21`](https://github.com/casey/intermodal/commit/323434d0aa21ebfda5be85ecd4a38a55ed3fec0a) Allow positional input to `imdl torrent verify` - Fixes [#375](https://github.com/casey/intermodal/issues/375) - _Casey Rodarmor <casey@rodarmor.com>_
- :zap: [`5ba885dbc4f2`](https://github.com/casey/intermodal/commit/5ba885dbc4f24781d6a3240ddfc0c03177b12f1e) Take input to `imdl torrent create` as positional - Fixes [#375](https://github.com/casey/intermodal/issues/375) - _Casey Rodarmor <casey@rodarmor.com>_ - :zap: [`5ba885dbc4f2`](https://github.com/casey/intermodal/commit/5ba885dbc4f24781d6a3240ddfc0c03177b12f1e) Take input to `imdl torrent create` as positional - Fixes [#375](https://github.com/casey/intermodal/issues/375) - _Casey Rodarmor <casey@rodarmor.com>_

View File

@ -5,9 +5,9 @@ use create_step::CreateStep;
mod create_content; mod create_content;
mod create_step; mod create_step;
const INPUT_HELP: &str = "Read torrent contents from `PATH`. If `PATH` is a file, torrent will be \ const INPUT_HELP: &str = "Read torrent contents from `INPUT`. If `INPUT` is a file, torrent will \
a single-file torrent. If `PATH` is a directory, torrent will be a \ be a single-file torrent. If `INPUT` is a directory, torrent will be a \
multi-file torrent. If `PATH` is `-`, read from standard input. Piece \ multi-file torrent. If `INPUT` is `-`, read from standard input. Piece \
length defaults to 256KiB when reading from standard input if \ length defaults to 256KiB when reading from standard input if \
`--piece-length` is not given."; `--piece-length` is not given.";
@ -138,7 +138,7 @@ Examples:
name = INPUT_FLAG, name = INPUT_FLAG,
long = "input", long = "input",
short = "i", short = "i",
value_name = "PATH", value_name = "INPUT",
empty_values = false, empty_values = false,
parse(try_from_os_str = InputTarget::try_from_os_str), parse(try_from_os_str = InputTarget::try_from_os_str),
help = INPUT_HELP, help = INPUT_HELP,

View File

@ -1,5 +1,12 @@
use crate::common::*; use crate::common::*;
const INPUT_HELP: &str = "Generate magnet link from metainfo at `INPUT`. If `INPUT` is `-`, read \
metainfo from standard input.";
const INPUT_FLAG: &str = "input-flag";
const INPUT_POSITIONAL: &str = "<INPUT>";
#[derive(StructOpt)] #[derive(StructOpt)]
#[structopt( #[structopt(
help_message(consts::HELP_MESSAGE), help_message(consts::HELP_MESSAGE),
@ -8,15 +15,25 @@ use crate::common::*;
)] )]
pub(crate) struct Link { pub(crate) struct Link {
#[structopt( #[structopt(
name = INPUT_FLAG,
long = "input", long = "input",
short = "i", short = "i",
value_name = "METAINFO", value_name = "INPUT",
empty_values(false), empty_values(false),
parse(try_from_os_str = InputTarget::try_from_os_str), parse(try_from_os_str = InputTarget::try_from_os_str),
help = "Generate magnet link from metainfo at `PATH`. If `PATH` is `-`, read metainfo from \ help = INPUT_HELP,
standard input.",
)] )]
input: InputTarget, input_flag: Option<InputTarget>,
#[structopt(
name = INPUT_POSITIONAL,
value_name = "INPUT",
empty_values(false),
parse(try_from_os_str = InputTarget::try_from_os_str),
required_unless = INPUT_FLAG,
conflicts_with = INPUT_FLAG,
help = INPUT_HELP,
)]
input_positional: Option<InputTarget>,
#[structopt( #[structopt(
long = "open", long = "open",
short = "O", short = "O",
@ -44,7 +61,14 @@ pub(crate) struct Link {
impl Link { impl Link {
pub(crate) fn run(self, env: &mut Env) -> Result<(), Error> { pub(crate) fn run(self, env: &mut Env) -> Result<(), Error> {
let input = env.read(self.input.clone())?; let input = xor_args(
"input_flag",
&self.input_flag,
"input_positional",
&self.input_positional,
)?;
let input = env.read(input.clone())?;
let infohash = Infohash::from_input(&input)?; let infohash = Infohash::from_input(&input)?;
let metainfo = Metainfo::from_input(&input)?; let metainfo = Metainfo::from_input(&input)?;
@ -84,7 +108,56 @@ mod tests {
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;
#[test] #[test]
fn no_announce() { fn input_required() {
test_env! {
args: [
"torrent",
"link",
],
tree: {
},
matches: Err(Error::Clap { .. }),
};
test_env! {
args: [
"torrent",
"link",
"--input",
"foo",
],
tree: {
},
matches: Err(Error::Filesystem { .. }),
};
test_env! {
args: [
"torrent",
"link",
"foo",
],
tree: {
},
matches: Err(Error::Filesystem { .. }),
};
test_env! {
args: [
"torrent",
"link",
"--input",
"foo",
"foo",
],
tree: {
},
matches: Err(Error::Clap { .. }),
};
}
#[test]
fn no_announce_flag() {
let mut env = test_env! { let mut env = test_env! {
args: [ args: [
"torrent", "torrent",
@ -109,6 +182,31 @@ mod tests {
); );
} }
#[test]
fn no_announce_positional() {
let mut env = test_env! {
args: [
"torrent",
"link",
"foo.torrent",
],
tree: {
"foo.torrent": "d4:infod6:lengthi0e4:name3:foo12:piece lengthi1e6:pieces0:ee",
}
};
env.assert_ok();
const INFO: &str = "d6:lengthi0e4:name3:foo12:piece lengthi1e6:pieces0:e";
let infohash = Sha1Digest::from_data(INFO.as_bytes());
assert_eq!(
env.out(),
format!("magnet:?xt=urn:btih:{}&dn=foo\n", infohash),
);
}
#[test] #[test]
fn with_announce() { fn with_announce() {
let mut env = test_env! { let mut env = test_env! {

View File

@ -3,8 +3,8 @@ use verify_step::VerifyStep;
mod verify_step; mod verify_step;
const METAINFO_HELP: &str = "Verify torrent contents against torrent metainfo in `METAINFO`. If \ const METAINFO_HELP: &str = "Verify torrent contents against torrent metainfo in `INPUT`. If \
`METAINFO` is `-`, read metainfo from standard input."; `INPUT` is `-`, read metainfo from standard input.";
const INPUT_POSITIONAL: &str = "<INPUT>"; const INPUT_POSITIONAL: &str = "<INPUT>";
@ -41,7 +41,7 @@ pub(crate) struct Verify {
name = INPUT_FLAG, name = INPUT_FLAG,
long = "input", long = "input",
short = "i", short = "i",
value_name = "METAINFO", value_name = "INPUT",
empty_values = false, empty_values = false,
parse(try_from_os_str = InputTarget::try_from_os_str), parse(try_from_os_str = InputTarget::try_from_os_str),
help = METAINFO_HELP, help = METAINFO_HELP,

View File

@ -8,19 +8,29 @@ macro_rules! test_env {
$(err_style: $err_style:expr,)? $(err_style: $err_style:expr,)?
tree: { tree: {
$($tree:tt)* $($tree:tt)*
} $(,)? }
$(, matches: $result:pat)?
$(,)?
} => { } => {
{ {
let tempdir = temptree! { $($tree)* }; let tempdir = temptree! { $($tree)* };
TestEnvBuilder::new() let env = TestEnvBuilder::new()
$(.current_dir(tempdir.path().join($cwd)))? $(.current_dir(tempdir.path().join($cwd)))?
$(.err_style($err_style))? $(.err_style($err_style))?
$(.input($input))? $(.input($input))?
.tempdir(tempdir) .tempdir(tempdir)
.arg("imdl") .arg("imdl")
$(.arg($arg))* $(.arg($arg))*
.build() .build();
$(
let mut env = env;
assert_matches!(env.run(), $result);
)?
env
} }
} }
} }