Rename: Environment -> Env
type: reform
This commit is contained in:
parent
7420c91553
commit
fd06943726
|
@ -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
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
use crate::common::*;
|
||||
|
||||
pub(crate) struct Environment {
|
||||
pub(crate) struct Env {
|
||||
args: Vec<String>,
|
||||
dir: Box<dyn AsRef<Path>>,
|
||||
pub(crate) err: Box<dyn Write>,
|
||||
}
|
||||
|
||||
impl Environment {
|
||||
impl Env {
|
||||
pub(crate) fn main() -> Self {
|
||||
let dir = match env::current_dir() {
|
||||
Ok(dir) => dir,
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@ use crate::common::*;
|
|||
|
||||
use std::{io::Cursor, iter};
|
||||
|
||||
pub(crate) fn environment(iter: impl IntoIterator<Item = impl Into<String>>) -> Environment {
|
||||
Environment::new(
|
||||
pub(crate) fn env(iter: impl IntoIterator<Item = impl Into<String>>) -> Env {
|
||||
Env::new(
|
||||
tempfile::tempdir().unwrap(),
|
||||
Cursor::new(Vec::new()),
|
||||
iter::once(String::from("imdl")).chain(iter.into_iter().map(|item| item.into())),
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue
Block a user