Skip to content

Commit

Permalink
Rename OSProcess to OsProcess
Browse files Browse the repository at this point in the history
  • Loading branch information
djc authored and rami3l committed Jul 12, 2024
1 parent f256759 commit 52157df
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
34 changes: 17 additions & 17 deletions src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ pub mod terminalsource;
/// Allows concrete types for the process abstraction.
#[derive(Clone, Debug)]
pub enum Process {
OSProcess(OSProcess),
OsProcess(OsProcess),
#[cfg(feature = "test")]
TestProcess(TestContext),
}

impl Process {
pub fn os() -> Self {
Self::OSProcess(OSProcess::new())
Self::OsProcess(OsProcess::new())
}

pub fn name(&self) -> Option<String> {
Expand Down Expand Up @@ -61,7 +61,7 @@ impl Process {

pub fn var(&self, key: &str) -> Result<String, env::VarError> {
match self {
Process::OSProcess(_) => env::var(key),
Process::OsProcess(_) => env::var(key),
#[cfg(feature = "test")]
Process::TestProcess(p) => match p.vars.get(key) {
Some(val) => Ok(val.to_owned()),
Expand All @@ -72,55 +72,55 @@ impl Process {

pub(crate) fn var_os(&self, key: &str) -> Option<OsString> {
match self {
Process::OSProcess(_) => env::var_os(key),
Process::OsProcess(_) => env::var_os(key),
#[cfg(feature = "test")]
Process::TestProcess(p) => p.vars.get(key).map(OsString::from),
}
}

pub(crate) fn args(&self) -> Box<dyn Iterator<Item = String> + '_> {
match self {
Process::OSProcess(_) => Box::new(env::args()),
Process::OsProcess(_) => Box::new(env::args()),
#[cfg(feature = "test")]
Process::TestProcess(p) => Box::new(p.args.iter().cloned()),
}
}

pub(crate) fn args_os(&self) -> Box<dyn Iterator<Item = OsString> + '_> {
match self {
Process::OSProcess(_) => Box::new(env::args_os()),
Process::OsProcess(_) => Box::new(env::args_os()),
#[cfg(feature = "test")]
Process::TestProcess(p) => Box::new(p.args.iter().map(OsString::from)),
}
}

pub(crate) fn stdin(&self) -> Box<dyn filesource::Stdin> {
match self {
Process::OSProcess(_) => Box::new(io::stdin()),
Process::OsProcess(_) => Box::new(io::stdin()),
#[cfg(feature = "test")]
Process::TestProcess(p) => Box::new(filesource::TestStdin(p.stdin.clone())),
}
}

pub(crate) fn stdout(&self) -> Box<dyn filesource::Writer> {
match self {
Process::OSProcess(_) => Box::new(io::stdout()),
Process::OsProcess(_) => Box::new(io::stdout()),
#[cfg(feature = "test")]
Process::TestProcess(p) => Box::new(filesource::TestWriter(p.stdout.clone())),
}
}

pub(crate) fn stderr(&self) -> Box<dyn filesource::Writer> {
match self {
Process::OSProcess(_) => Box::new(io::stderr()),
Process::OsProcess(_) => Box::new(io::stderr()),
#[cfg(feature = "test")]
Process::TestProcess(p) => Box::new(filesource::TestWriter(p.stderr.clone())),
}
}

pub fn current_dir(&self) -> io::Result<PathBuf> {
match self {
Process::OSProcess(_) => env::current_dir(),
Process::OsProcess(_) => env::current_dir(),
#[cfg(feature = "test")]
Process::TestProcess(p) => Ok(p.cwd.clone()),
}
Expand All @@ -130,15 +130,15 @@ impl Process {
impl home::env::Env for Process {
fn home_dir(&self) -> Option<PathBuf> {
match self {
Process::OSProcess(_) => home::env::OS_ENV.home_dir(),
Process::OsProcess(_) => home::env::OS_ENV.home_dir(),
#[cfg(feature = "test")]
Process::TestProcess(_) => self.var("HOME").ok().map(|v| v.into()),
}
}

fn current_dir(&self) -> Result<PathBuf, io::Error> {
match self {
Process::OSProcess(_) => home::env::OS_ENV.current_dir(),
Process::OsProcess(_) => home::env::OS_ENV.current_dir(),
#[cfg(feature = "test")]
Process::TestProcess(_) => self.current_dir(),
}
Expand All @@ -152,23 +152,23 @@ impl home::env::Env for Process {
// ----------- real process -----------------

#[derive(Clone, Debug)]
pub struct OSProcess {
pub struct OsProcess {
pub(self) stderr_is_a_tty: bool,
pub(self) stdout_is_a_tty: bool,
}

impl OSProcess {
impl OsProcess {
pub fn new() -> Self {
OSProcess {
OsProcess {
stderr_is_a_tty: io::stderr().is_terminal(),
stdout_is_a_tty: io::stdout().is_terminal(),
}
}
}

impl Default for OSProcess {
impl Default for OsProcess {
fn default() -> Self {
OSProcess::new()
OsProcess::new()
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/process/filesource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl WriterLock for io::StdoutLock<'_> {}
impl Writer for io::Stdout {
fn is_a_tty(&self, process: &Process) -> bool {
match process {
crate::process::Process::OSProcess(p) => p.stdout_is_a_tty,
crate::process::Process::OsProcess(p) => p.stdout_is_a_tty,
#[cfg(feature = "test")]
crate::process::Process::TestProcess(_) => unreachable!(),
}
Expand All @@ -68,7 +68,7 @@ impl WriterLock for io::StderrLock<'_> {}
impl Writer for io::Stderr {
fn is_a_tty(&self, process: &Process) -> bool {
match process {
crate::process::Process::OSProcess(p) => p.stderr_is_a_tty,
crate::process::Process::OsProcess(p) => p.stderr_is_a_tty,
#[cfg(feature = "test")]
crate::process::Process::TestProcess(_) => unreachable!(),
}
Expand Down
4 changes: 2 additions & 2 deletions src/process/terminalsource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ impl StreamSelector {
fn is_a_tty(&self, process: &Process) -> bool {
match self {
StreamSelector::Stdout => match process {
Process::OSProcess(p) => p.stdout_is_a_tty,
Process::OsProcess(p) => p.stdout_is_a_tty,
#[cfg(feature = "test")]
Process::TestProcess(_) => unreachable!(),
},
StreamSelector::Stderr => match process {
Process::OSProcess(p) => p.stderr_is_a_tty,
Process::OsProcess(p) => p.stderr_is_a_tty,
#[cfg(feature = "test")]
Process::TestProcess(_) => unreachable!(),
},
Expand Down

0 comments on commit 52157df

Please sign in to comment.