Rename: Environment -> Env

type: reform
This commit is contained in:
Casey Rodarmor 2020-01-07 18:05:48 -08:00
parent 7420c91553
commit fd06943726
No known key found for this signature in database
GPG Key ID: 556186B153EC6FE0
9 changed files with 15 additions and 15 deletions

View File

@ -37,8 +37,8 @@ pub(crate) use crate::{
// structs and enums // structs and enums
pub(crate) use crate::{ pub(crate) use crate::{
environment::Environment, error::Error, file_info::FileInfo, hasher::Hasher, info::Info, env::Env, error::Error, file_info::FileInfo, hasher::Hasher, info::Info, metainfo::Metainfo,
metainfo::Metainfo, mode::Mode, opt::Opt, subcommand::Subcommand, torrent::Torrent, mode::Mode, opt::Opt, subcommand::Subcommand, torrent::Torrent,
}; };
// test modules // test modules

View File

@ -1,12 +1,12 @@
use crate::common::*; use crate::common::*;
pub(crate) struct Environment { pub(crate) struct Env {
args: Vec<String>, args: Vec<String>,
dir: Box<dyn AsRef<Path>>, dir: Box<dyn AsRef<Path>>,
pub(crate) err: Box<dyn Write>, pub(crate) err: Box<dyn Write>,
} }
impl Environment { impl Env {
pub(crate) fn main() -> Self { pub(crate) fn main() -> Self {
let dir = match env::current_dir() { let dir = match env::current_dir() {
Ok(dir) => dir, Ok(dir) => dir,

View File

@ -30,7 +30,7 @@ mod testing;
mod bencode; mod bencode;
mod common; mod common;
mod consts; mod consts;
mod environment; mod env;
mod error; mod error;
mod file_info; mod file_info;
mod hasher; mod hasher;
@ -46,7 +46,7 @@ mod subcommand;
mod torrent; mod torrent;
fn main() { fn main() {
if let Err(code) = Environment::main().status() { if let Err(code) = Env::main().status() {
process::exit(code); process::exit(code);
} }
} }

View File

@ -9,7 +9,7 @@ pub(crate) struct Opt {
} }
impl 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) self.subcommand.run(env, self.unstable)
} }
} }

View File

@ -6,7 +6,7 @@ pub(crate) enum Subcommand {
} }
impl 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 { match self {
Self::Torrent(torrent) => torrent.run(env, unstable), Self::Torrent(torrent) => torrent.run(env, unstable),
} }

View File

@ -2,8 +2,8 @@ use crate::common::*;
use std::{io::Cursor, iter}; use std::{io::Cursor, iter};
pub(crate) fn environment(iter: impl IntoIterator<Item = impl Into<String>>) -> Environment { pub(crate) fn env(iter: impl IntoIterator<Item = impl Into<String>>) -> Env {
Environment::new( Env::new(
tempfile::tempdir().unwrap(), tempfile::tempdir().unwrap(),
Cursor::new(Vec::new()), Cursor::new(Vec::new()),
iter::once(String::from("imdl")).chain(iter.into_iter().map(|item| item.into())), iter::once(String::from("imdl")).chain(iter.into_iter().map(|item| item.into())),

View File

@ -10,7 +10,7 @@ pub(crate) enum Torrent {
} }
impl 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 { match self {
Self::Create(create) => create.run(env), Self::Create(create) => create.run(env),
Self::Stats(stats) => stats.run(env, unstable), Self::Stats(stats) => stats.run(env, unstable),

View File

@ -25,7 +25,7 @@ pub(crate) struct Create {
} }
impl 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 input = env.resolve(&self.input);
let mut announce_list = Vec::new(); let mut announce_list = Vec::new();
@ -125,8 +125,8 @@ impl Create {
mod tests { mod tests {
use super::*; use super::*;
fn environment(args: &[&str]) -> Environment { fn environment(args: &[&str]) -> Env {
testing::environment(["torrent", "create"].iter().chain(args).cloned()) testing::env(["torrent", "create"].iter().chain(args).cloned())
} }
#[test] #[test]

View File

@ -11,7 +11,7 @@ pub(crate) struct Stats {
} }
impl 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 { if !unstable {
return Err(Error::Unstable { return Err(Error::Unstable {
feature: "torrent stats subcommand", feature: "torrent stats subcommand",