Skip torrent file creation with imdl torrent create --dry-run
Torrent files will not be written to disk with `--dry-run`: imdl torrrent create --input foo --dry-run type: added
This commit is contained in:
parent
7e3a53ce52
commit
1c84172ad4
|
@ -59,7 +59,6 @@ pub(crate) struct Create {
|
||||||
comment: Option<String>,
|
comment: Option<String>,
|
||||||
#[structopt(
|
#[structopt(
|
||||||
long = "node",
|
long = "node",
|
||||||
short = "n",
|
|
||||||
value_name = "NODE",
|
value_name = "NODE",
|
||||||
help = "Add DHT bootstrap node `NODE` to torrent. `NODE` should be in the form `HOST:PORT`, \
|
help = "Add DHT bootstrap node `NODE` to torrent. `NODE` should be in the form `HOST:PORT`, \
|
||||||
where `HOST` is a domain name, an IPv4 address, or an IPv6 address surrounded by \
|
where `HOST` is a domain name, an IPv4 address, or an IPv6 address surrounded by \
|
||||||
|
@ -69,6 +68,12 @@ pub(crate) struct Create {
|
||||||
`--node [2001:db8:4275:7920:6269:7463:6f69:6e21]:8832`"
|
`--node [2001:db8:4275:7920:6269:7463:6f69:6e21]:8832`"
|
||||||
)]
|
)]
|
||||||
dht_nodes: Vec<HostPort>,
|
dht_nodes: Vec<HostPort>,
|
||||||
|
#[structopt(
|
||||||
|
long = "dry-run",
|
||||||
|
short = "n",
|
||||||
|
help = "Skip writing `.torrent` file to disk."
|
||||||
|
)]
|
||||||
|
dry_run: bool,
|
||||||
#[structopt(
|
#[structopt(
|
||||||
long = "follow-symlinks",
|
long = "follow-symlinks",
|
||||||
short = "F",
|
short = "F",
|
||||||
|
@ -369,6 +374,7 @@ impl Create {
|
||||||
|
|
||||||
let bytes = metainfo.serialize()?;
|
let bytes = metainfo.serialize()?;
|
||||||
|
|
||||||
|
if !self.dry_run {
|
||||||
match &output {
|
match &output {
|
||||||
OutputTarget::File(path) => {
|
OutputTarget::File(path) => {
|
||||||
let mut open_options = fs::OpenOptions::new();
|
let mut open_options = fs::OpenOptions::new();
|
||||||
|
@ -386,6 +392,7 @@ impl Create {
|
||||||
}
|
}
|
||||||
OutputTarget::Stdout => env.out_mut().write_all(&bytes).context(error::Stdout)?,
|
OutputTarget::Stdout => env.out_mut().write_all(&bytes).context(error::Stdout)?,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
{
|
{
|
||||||
|
@ -2420,4 +2427,24 @@ Content Size 9 bytes
|
||||||
666\n"
|
666\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn dry_run_skips_torrent_file_creation() {
|
||||||
|
let mut env = test_env! {
|
||||||
|
args: [
|
||||||
|
"torrent",
|
||||||
|
"create",
|
||||||
|
"--input",
|
||||||
|
"foo",
|
||||||
|
"--dry-run",
|
||||||
|
],
|
||||||
|
tree: {
|
||||||
|
foo: "",
|
||||||
|
}
|
||||||
|
};
|
||||||
|
assert_matches!(env.run(), Ok(()));
|
||||||
|
let torrent = env.resolve("foo.torrent");
|
||||||
|
let err = fs::read(torrent).unwrap_err();
|
||||||
|
assert_eq!(err.kind(), io::ErrorKind::NotFound);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user