From fd06943726cbc864b32401213d6958c7164b7851 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Tue, 7 Jan 2020 18:05:48 -0800 Subject: [PATCH] Rename: Environment -> Env type: reform --- src/common.rs | 4 ++-- src/{environment.rs => env.rs} | 4 ++-- src/main.rs | 4 ++-- src/opt.rs | 2 +- src/subcommand.rs | 2 +- src/testing.rs | 4 ++-- src/torrent.rs | 2 +- src/torrent/create.rs | 6 +++--- src/torrent/stats.rs | 2 +- 9 files changed, 15 insertions(+), 15 deletions(-) rename src/{environment.rs => env.rs} (95%) diff --git a/src/common.rs b/src/common.rs index d120871..44588e2 100644 --- a/src/common.rs +++ b/src/common.rs @@ -37,8 +37,8 @@ pub(crate) use crate::{ // structs and enums pub(crate) use crate::{ - environment::Environment, error::Error, file_info::FileInfo, hasher::Hasher, info::Info, - metainfo::Metainfo, mode::Mode, opt::Opt, subcommand::Subcommand, torrent::Torrent, + env::Env, error::Error, file_info::FileInfo, hasher::Hasher, info::Info, metainfo::Metainfo, + mode::Mode, opt::Opt, subcommand::Subcommand, torrent::Torrent, }; // test modules diff --git a/src/environment.rs b/src/env.rs similarity index 95% rename from src/environment.rs rename to src/env.rs index bf5935b..e2a0e26 100644 --- a/src/environment.rs +++ b/src/env.rs @@ -1,12 +1,12 @@ use crate::common::*; -pub(crate) struct Environment { +pub(crate) struct Env { args: Vec, dir: Box>, pub(crate) err: Box, } -impl Environment { +impl Env { pub(crate) fn main() -> Self { let dir = match env::current_dir() { Ok(dir) => dir, diff --git a/src/main.rs b/src/main.rs index 1c62eef..1b16b39 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,7 +30,7 @@ mod testing; mod bencode; mod common; mod consts; -mod environment; +mod env; mod error; mod file_info; mod hasher; @@ -46,7 +46,7 @@ mod subcommand; mod torrent; fn main() { - if let Err(code) = Environment::main().status() { + if let Err(code) = Env::main().status() { process::exit(code); } } diff --git a/src/opt.rs b/src/opt.rs index 60a6b7c..98a1938 100644 --- a/src/opt.rs +++ b/src/opt.rs @@ -9,7 +9,7 @@ pub(crate) struct Opt { } impl Opt { - pub(crate) fn run(self, env: &mut Environment) -> Result<(), Error> { + pub(crate) fn run(self, env: &mut Env) -> Result<(), Error> { self.subcommand.run(env, self.unstable) } } diff --git a/src/subcommand.rs b/src/subcommand.rs index 62cb32a..3b52b8d 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -6,7 +6,7 @@ pub(crate) enum Subcommand { } impl Subcommand { - pub(crate) fn run(self, env: &mut Environment, unstable: bool) -> Result<(), Error> { + pub(crate) fn run(self, env: &mut Env, unstable: bool) -> Result<(), Error> { match self { Self::Torrent(torrent) => torrent.run(env, unstable), } diff --git a/src/testing.rs b/src/testing.rs index d12429d..dee91f2 100644 --- a/src/testing.rs +++ b/src/testing.rs @@ -2,8 +2,8 @@ use crate::common::*; use std::{io::Cursor, iter}; -pub(crate) fn environment(iter: impl IntoIterator>) -> Environment { - Environment::new( +pub(crate) fn env(iter: impl IntoIterator>) -> Env { + Env::new( tempfile::tempdir().unwrap(), Cursor::new(Vec::new()), iter::once(String::from("imdl")).chain(iter.into_iter().map(|item| item.into())), diff --git a/src/torrent.rs b/src/torrent.rs index ad05fbd..63f0c59 100644 --- a/src/torrent.rs +++ b/src/torrent.rs @@ -10,7 +10,7 @@ pub(crate) enum Torrent { } impl Torrent { - pub(crate) fn run(self, env: &mut Environment, unstable: bool) -> Result<(), Error> { + pub(crate) fn run(self, env: &mut Env, unstable: bool) -> Result<(), Error> { match self { Self::Create(create) => create.run(env), Self::Stats(stats) => stats.run(env, unstable), diff --git a/src/torrent/create.rs b/src/torrent/create.rs index 3a9477a..b7b6df7 100644 --- a/src/torrent/create.rs +++ b/src/torrent/create.rs @@ -25,7 +25,7 @@ pub(crate) struct Create { } impl Create { - pub(crate) fn run(self, env: &Environment) -> Result<(), Error> { + pub(crate) fn run(self, env: &Env) -> Result<(), Error> { let input = env.resolve(&self.input); let mut announce_list = Vec::new(); @@ -125,8 +125,8 @@ impl Create { mod tests { use super::*; - fn environment(args: &[&str]) -> Environment { - testing::environment(["torrent", "create"].iter().chain(args).cloned()) + fn environment(args: &[&str]) -> Env { + testing::env(["torrent", "create"].iter().chain(args).cloned()) } #[test] diff --git a/src/torrent/stats.rs b/src/torrent/stats.rs index 411011c..3b7ebc0 100644 --- a/src/torrent/stats.rs +++ b/src/torrent/stats.rs @@ -11,7 +11,7 @@ pub(crate) struct Stats { } impl Stats { - pub(crate) fn run(self, env: &mut Environment, unstable: bool) -> Result<(), Error> { + pub(crate) fn run(self, env: &mut Env, unstable: bool) -> Result<(), Error> { if !unstable { return Err(Error::Unstable { feature: "torrent stats subcommand",