From b25b389ae66b38c00f013353a5a0ca97ee08d499 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Wed, 11 Mar 2020 22:44:14 -0700 Subject: [PATCH] Rename `Target` to `OutputTarget` Making it specific to output allows us to be more specific in the display message, and possibly add output-specific code in the future. type: reform --- Cargo.lock | 118 +++++++++++++--------------- Cargo.toml | 2 + src/common.rs | 8 +- src/main.rs | 2 +- src/{target.rs => output_target.rs} | 29 ++++--- src/subcommand/torrent/create.rs | 10 +-- 6 files changed, 81 insertions(+), 88 deletions(-) rename src/{target.rs => output_target.rs} (58%) diff --git a/Cargo.lock b/Cargo.lock index 28af9fa..3b9cfca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,9 +2,9 @@ # It is not intended for manual editing. [[package]] name = "aho-corasick" -version = "0.7.8" +version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "743ad5a418686aad3b87fd14c43badd828cf26e214a00f92a384291cf22e1811" +checksum = "8716408b8bc624ed7f65d223ddb9ac2d044c0547b6fa4b0d554f3a9540496ada" dependencies = [ "memchr", ] @@ -55,9 +55,9 @@ checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" [[package]] name = "backtrace" -version = "0.3.44" +version = "0.3.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4036b9bf40f3cf16aba72a3d65e8a520fc4bafcdc7079aea8f848c58c5b5536" +checksum = "ad235dabf00f36301792cfe82499880ba54c6486be094d1047b02bacb67c14e8" dependencies = [ "backtrace-sys", "cfg-if", @@ -67,9 +67,9 @@ dependencies = [ [[package]] name = "backtrace-sys" -version = "0.1.32" +version = "0.1.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d6575f128516de27e3ce99689419835fce9643a9b215a14d2b5b685be018491" +checksum = "ca797db0057bae1a7aa2eef3283a874695455cecf08a43bfb8507ee0ebc1ed69" dependencies = [ "cc", "libc", @@ -100,15 +100,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "c2-chacha" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "214238caa1bf3a496ec3392968969cab8549f96ff30652c9e56885329315f6bb" -dependencies = [ - "ppv-lite86", -] - [[package]] name = "cc" version = "1.0.50" @@ -123,9 +114,9 @@ checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" [[package]] name = "chrono" -version = "0.4.10" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31850b4a4d6bae316f7a09e691c944c28299298837edc0a03f755618c23cbc01" +checksum = "80094f509cf8b5ae86a4966a39b3ff66cd7e2a3e594accec3743ff3fabeab5b2" dependencies = [ "num-integer", "num-traits", @@ -162,9 +153,9 @@ dependencies = [ [[package]] name = "console" -version = "0.9.2" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45e0f3986890b3acbc782009e2629dfe2baa430ac091519ce3be26164a2ae6c0" +checksum = "6728a28023f207181b193262711102bfbaf47cc9d13bc71d0736607ef8efe88c" dependencies = [ "clicolors-control", "encode_unicode", @@ -178,9 +169,9 @@ dependencies = [ [[package]] name = "ctor" -version = "0.1.12" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd8ce37ad4184ab2ce004c33bf6379185d3b1c95801cab51026bd271bf68eedc" +checksum = "47c5e5ac752e18207b12e16b10631ae5f7f68f8805f335f9b817ead83d9ffce1" dependencies = [ "quote", "syn", @@ -194,9 +185,9 @@ checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" [[package]] name = "doc-comment" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "923dea538cea0aa3025e8685b20d6ee21ef99c4f77e954a30febbaac5ec73a97" +checksum = "807e5847c39ad6a11eac66de492ed1406f76a260eb8656e8740cad9eabc69c27" [[package]] name = "encode_unicode" @@ -219,9 +210,9 @@ dependencies = [ [[package]] name = "failure" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8273f13c977665c5db7eb2b99ae520952fe5ac831ae4cd09d80c4c7042b5ed9" +checksum = "b8529c2421efa3066a5cbd8063d2244603824daccb6936b079010bb2aa89464b" dependencies = [ "backtrace", "failure_derive", @@ -229,9 +220,9 @@ dependencies = [ [[package]] name = "failure_derive" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bc225b78e0391e4b8683440bf2e63c2deeeb2ce5189eab46e2b68c6d3725d08" +checksum = "030a733c8287d6213886dd487564ff5c8f6aae10278b3588ed177f9d18f8d231" dependencies = [ "proc-macro2", "quote", @@ -286,9 +277,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.6" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eff2656d88f158ce120947499e971d743c05dbcbed62e5bd2f38f1698bbc3772" +checksum = "1010591b26bbfe835e9faeabeb11866061cc7dcebffd56ad7d0942d0e61aefd8" dependencies = [ "libc", ] @@ -321,8 +312,10 @@ dependencies = [ "atty", "bendy", "chrono", + "console", "globset", "indicatif", + "lazy_static", "libc", "md5", "pretty_assertions", @@ -374,9 +367,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.66" +version = "0.2.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558" +checksum = "eb147597cdf94ed43ab7a9038716637d2d1bf2bc571da995d0028dec06bd3018" [[package]] name = "log" @@ -407,9 +400,9 @@ checksum = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771" [[package]] name = "memchr" -version = "2.3.2" +version = "2.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53445de381a1f436797497c61d851644d0e8e88e6140f22872ad33a704933978" +checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" [[package]] name = "nodrop" @@ -487,35 +480,35 @@ dependencies = [ [[package]] name = "proc-macro-error" -version = "0.4.9" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "052b3c9af39c7e5e94245f820530487d19eb285faedcb40e0c3275132293f242" +checksum = "e7959c6467d962050d639361f7703b2051c43036d03493c36f01d440fdd3138a" dependencies = [ "proc-macro-error-attr", "proc-macro2", "quote", - "rustversion", "syn", + "version_check", ] [[package]] name = "proc-macro-error-attr" -version = "0.4.9" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d175bef481c7902e63e3165627123fff3502f06ac043d3ef42d08c1246da9253" +checksum = "e4002d9f55991d5e019fb940a90e1a95eb80c24e77cb2462dd4dc869604d543a" dependencies = [ "proc-macro2", "quote", - "rustversion", "syn", "syn-mid", + "version_check", ] [[package]] name = "proc-macro2" -version = "1.0.8" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acb317c6ff86a4e579dfa00fc5e6cca91ecbb4e7eb2df0468805b674eb88548" +checksum = "6c09721c6781493a2a492a96b5a5bf19b65917fe6728884e7c44dd0c60ca3435" dependencies = [ "unicode-xid", ] @@ -528,9 +521,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quote" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" +checksum = "2bdc6c187c65bca4260c9011c9e3132efe4909da44726bad24cf7572ae338d7f" dependencies = [ "proc-macro2", ] @@ -550,11 +543,11 @@ dependencies = [ [[package]] name = "rand_chacha" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" dependencies = [ - "c2-chacha", + "ppv-lite86", "rand_core", ] @@ -596,9 +589,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.14" +version = "0.6.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b28dfe3fe9badec5dbf0a79a9cccad2cfc2ab5484bdb3e44cbd1ae8b3ba2be06" +checksum = "1132f845907680735a84409c3bebc64d1364a5683ffbce899550cd09d5eaefc1" [[package]] name = "remove_dir_all" @@ -615,17 +608,6 @@ version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" -[[package]] -name = "rustversion" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3bba175698996010c4f6dce5e7f173b6eb781fce25d2cfc45e27091ce0b79f6" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "same-file" version = "1.0.6" @@ -752,9 +734,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "structopt" -version = "0.3.9" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1bcbed7d48956fcbb5d80c6b95aedb553513de0a1b451ea92679d999c010e98" +checksum = "3fe43617218c0805c6eb37160119dc3c548110a67786da7218d1c6555212f073" dependencies = [ "clap", "lazy_static", @@ -763,9 +745,9 @@ dependencies = [ [[package]] name = "structopt-derive" -version = "0.4.2" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "095064aa1f5b94d14e635d0a5684cf140c43ae40a0fd990708d38f5d669e5f64" +checksum = "c6e79c80e0f4efd86ca960218d4e056249be189ff1c42824dcd9a7f51a56f0bd" dependencies = [ "heck", "proc-macro-error", @@ -776,9 +758,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.14" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af6f3550d8dff9ef7dc34d384ac6f107e5d31c8f57d9f28e0081503f547ac8f5" +checksum = "123bd9499cfb380418d509322d7a6d52e5315f064fe4b3ad18a53d6b92c07859" dependencies = [ "proc-macro2", "quote", @@ -952,6 +934,12 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" +[[package]] +name = "version_check" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "078775d0255232fb988e6fccf26ddc9d1ac274299aaedcedce21c6f72cc533ce" + [[package]] name = "walkdir" version = "2.3.1" diff --git a/Cargo.toml b/Cargo.toml index 4bf02ca..d1c3b90 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ default-run = "imdl" ansi_term = "0.12.0" atty = "0.2.0" chrono = "0.4.1" +console = "0.10.0" globset = "0.4.0" indicatif = "0.14.0" libc = "0.2.0" @@ -34,6 +35,7 @@ tempfile = "3.0.0" unicode-width = "0.1.0" url = "2.0.0" walkdir = "2.1.0" +lazy_static = "1.4.0" [dependencies.bendy] version = "0.2.2" diff --git a/src/common.rs b/src/common.rs index 686a3c3..d95e97e 100644 --- a/src/common.rs +++ b/src/common.rs @@ -55,10 +55,10 @@ pub(crate) use crate::{ arguments::Arguments, bytes::Bytes, env::Env, error::Error, file_info::FileInfo, file_path::FilePath, file_status::FileStatus, files::Files, hasher::Hasher, info::Info, lint::Lint, linter::Linter, md5_digest::Md5Digest, metainfo::Metainfo, mode::Mode, node::Node, - options::Options, piece_length_picker::PieceLengthPicker, piece_list::PieceList, - platform::Platform, sha1_digest::Sha1Digest, status::Status, style::Style, - subcommand::Subcommand, table::Table, target::Target, torrent_summary::TorrentSummary, - use_color::UseColor, verifier::Verifier, walker::Walker, + options::Options, output_target::OutputTarget, piece_length_picker::PieceLengthPicker, + piece_list::PieceList, platform::Platform, sha1_digest::Sha1Digest, status::Status, style::Style, + subcommand::Subcommand, table::Table, torrent_summary::TorrentSummary, use_color::UseColor, + verifier::Verifier, walker::Walker, }; // type aliases diff --git a/src/main.rs b/src/main.rs index b4434c0..bcbde6c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -73,6 +73,7 @@ mod metainfo; mod mode; mod node; mod options; +mod output_target; mod path_ext; mod piece_length_picker; mod piece_list; @@ -84,7 +85,6 @@ mod status; mod style; mod subcommand; mod table; -mod target; mod torrent_summary; mod use_color; mod verifier; diff --git a/src/target.rs b/src/output_target.rs similarity index 58% rename from src/target.rs rename to src/output_target.rs index fe0e2f4..c9a7ec8 100644 --- a/src/target.rs +++ b/src/output_target.rs @@ -1,34 +1,34 @@ use crate::common::*; #[derive(PartialEq, Debug)] -pub(crate) enum Target { +pub(crate) enum OutputTarget { File(PathBuf), - Stdio, + Stdout, } -impl Target { +impl OutputTarget { pub(crate) fn resolve(&self, env: &Env) -> Self { match self { Self::File(path) => Self::File(env.resolve(path)), - Self::Stdio => Self::Stdio, + Self::Stdout => Self::Stdout, } } } -impl From<&OsStr> for Target { +impl From<&OsStr> for OutputTarget { fn from(text: &OsStr) -> Self { if text == OsStr::new("-") { - Self::Stdio + Self::Stdout } else { Self::File(text.into()) } } } -impl Display for Target { +impl Display for OutputTarget { fn fmt(&self, f: &mut Formatter) -> fmt::Result { match self { - Self::Stdio => write!(f, "standard I/O"), + Self::Stdout => write!(f, "standard output"), Self::File(path) => write!(f, "`{}`", path.display()), } } @@ -40,26 +40,29 @@ mod tests { #[test] fn file() { - assert_eq!(Target::from(OsStr::new("foo")), Target::File("foo".into())); + assert_eq!( + OutputTarget::from(OsStr::new("foo")), + OutputTarget::File("foo".into()) + ); } #[test] fn stdio() { - assert_eq!(Target::from(OsStr::new("-")), Target::Stdio); + assert_eq!(OutputTarget::from(OsStr::new("-")), OutputTarget::Stdout); } #[test] fn display_file() { let path = PathBuf::from("./path"); - let have = Target::File(path).to_string(); + let have = OutputTarget::File(path).to_string(); let want = "`./path`"; assert_eq!(have, want); } #[test] fn display_stdio() { - let have = Target::Stdio.to_string(); - let want = "standard I/O"; + let have = OutputTarget::Stdout.to_string(); + let want = "standard output"; assert_eq!(have, want); } } diff --git a/src/subcommand/torrent/create.rs b/src/subcommand/torrent/create.rs index 56dab69..ad22e12 100644 --- a/src/subcommand/torrent/create.rs +++ b/src/subcommand/torrent/create.rs @@ -148,7 +148,7 @@ pub(crate) struct Create { Defaults to `$INPUT.torrent`.", parse(from_os_str) )] - output: Option, + output: Option, #[structopt( long = "piece-length", short = "p", @@ -260,7 +260,7 @@ impl Create { let mut torrent_name = name.to_owned(); torrent_name.push_str(".torrent"); - Target::File(input.parent().unwrap().join(torrent_name)) + OutputTarget::File(input.parent().unwrap().join(torrent_name)) }); let private = if self.private { Some(true) } else { None }; @@ -332,7 +332,7 @@ impl Create { let bytes = metainfo.serialize()?; match &output { - Target::File(path) => { + OutputTarget::File(path) => { let mut open_options = fs::OpenOptions::new(); if self.force { @@ -346,7 +346,7 @@ impl Create { .and_then(|mut file| file.write_all(&bytes)) .context(error::Filesystem { path })?; } - Target::Stdio => env.out.write_all(&bytes).context(error::Stdout)?, + OutputTarget::Stdout => env.out.write_all(&bytes).context(error::Stdout)?, } #[cfg(test)] @@ -368,7 +368,7 @@ impl Create { TorrentSummary::from_metainfo(metainfo)?.write(env)?; } - if let Target::File(path) = output { + if let OutputTarget::File(path) = output { if self.open { Platform::open(&path)?; }