Only show torrent summary on create with --show
The torrent summary is large, and makes it easy to miss the create progress bar and messages. Only show summary if the user passes `--show` / `-S` to `imdl torrent create`. type: changed
This commit is contained in:
parent
06947fd63e
commit
0de2b1719e
|
@ -166,6 +166,12 @@ pub(crate) struct Create {
|
|||
more information."
|
||||
)]
|
||||
private: bool,
|
||||
#[structopt(
|
||||
long = "show",
|
||||
short = "S",
|
||||
help = "Display information about created torrent file."
|
||||
)]
|
||||
show: bool,
|
||||
#[structopt(
|
||||
long = "source",
|
||||
short = "s",
|
||||
|
@ -339,16 +345,6 @@ impl Create {
|
|||
.open(path)
|
||||
.and_then(|mut file| file.write_all(&bytes))
|
||||
.context(error::Filesystem { path })?;
|
||||
|
||||
#[cfg(test)]
|
||||
TorrentSummary::from_metainfo(metainfo.clone())?.write(env)?;
|
||||
|
||||
#[cfg(not(test))]
|
||||
TorrentSummary::from_metainfo(metainfo)?.write(env)?;
|
||||
|
||||
if self.open {
|
||||
Platform::open(&path)?;
|
||||
}
|
||||
}
|
||||
Target::Stdio => env.out.write_all(&bytes).context(error::Stdout)?,
|
||||
}
|
||||
|
@ -368,6 +364,16 @@ impl Create {
|
|||
|
||||
errln!(env, "\u{2728}\u{2728} Done! \u{2728}\u{2728}");
|
||||
|
||||
if self.show {
|
||||
TorrentSummary::from_metainfo(metainfo)?.write(env)?;
|
||||
}
|
||||
|
||||
if let Target::File(path) = output {
|
||||
if self.open {
|
||||
Platform::open(&path)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -1461,6 +1467,32 @@ mod tests {
|
|||
.out_is_term()
|
||||
.build();
|
||||
|
||||
let dir = env.resolve("foo");
|
||||
fs::create_dir(&dir).unwrap();
|
||||
fs::write(dir.join("a"), "abc").unwrap();
|
||||
fs::write(dir.join("x"), "xyz").unwrap();
|
||||
fs::write(dir.join("h"), "hij").unwrap();
|
||||
env.run().unwrap();
|
||||
assert_eq!(env.out(), "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn show() {
|
||||
let mut env = TestEnvBuilder::new()
|
||||
.arg_slice(&[
|
||||
"imdl",
|
||||
"torrent",
|
||||
"create",
|
||||
"--input",
|
||||
"foo",
|
||||
"--announce",
|
||||
"http://bar",
|
||||
"--no-creation-date",
|
||||
"--show",
|
||||
])
|
||||
.out_is_term()
|
||||
.build();
|
||||
|
||||
let dir = env.resolve("foo");
|
||||
fs::create_dir(&dir).unwrap();
|
||||
fs::write(dir.join("a"), "abc").unwrap();
|
||||
|
|
Loading…
Reference in New Issue
Block a user