Skip to content

Commit d63ef9f

Browse files
committed
Simplify process access to argument iterator
1 parent fc0385e commit d63ef9f

File tree

6 files changed

+22
-79
lines changed

6 files changed

+22
-79
lines changed

src/cli/common.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use once_cell::sync::Lazy;
1515
use super::self_update;
1616
use crate::cli::download_tracker::DownloadTracker;
1717
use crate::currentprocess::{
18-
argsource::ArgSource,
1918
filesource::{StdinSource, StdoutSource},
2019
terminalsource,
2120
varsource::VarSource,

src/cli/proxy_mode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use anyhow::Result;
55
use crate::{
66
cli::{common::set_globals, job, self_update},
77
command::run_command_for_dir,
8-
currentprocess::argsource::ArgSource,
98
toolchain::names::{LocalToolchainName, ResolvableLocalToolchainName},
109
utils::utils::{self, ExitCode},
1110
Cfg,
@@ -18,7 +17,8 @@ pub fn main(arg0: &str) -> Result<ExitCode> {
1817
let ExitCode(c) = {
1918
let _setup = job::setup();
2019

21-
let mut args = crate::process().args_os().skip(1);
20+
let process = crate::process();
21+
let mut args = process.args_os().skip(1);
2222

2323
// Check for a + toolchain specifier
2424
let arg1 = args.next();

src/cli/rustup_mode.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ use crate::{
2020
topical_doc,
2121
},
2222
command,
23-
currentprocess::{
24-
argsource::ArgSource,
25-
filesource::{StderrSource, StdoutSource},
26-
},
23+
currentprocess::filesource::{StderrSource, StdoutSource},
2724
dist::{
2825
dist::{PartialToolchainDesc, Profile, TargetTriple},
2926
manifest::{Component, ComponentStatus},
@@ -1667,7 +1664,8 @@ fn set_profile(cfg: &mut Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {
16671664

16681665
fn set_auto_self_update(cfg: &mut Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {
16691666
if self_update::NEVER_SELF_UPDATE {
1670-
let mut args = crate::process().args_os();
1667+
let process = crate::process();
1668+
let mut args = process.args_os();
16711669
let arg0 = args.next().map(PathBuf::from);
16721670
let arg0 = arg0
16731671
.as_ref()

src/cli/setup_mode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
common,
77
self_update::{self, InstallOpts},
88
},
9-
currentprocess::{argsource::ArgSource, filesource::StdoutSource},
9+
currentprocess::filesource::StdoutSource,
1010
dist::dist::Profile,
1111
process,
1212
toolchain::names::MaybeOfficialToolchainName,

src/currentprocess.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@ use home::env as home;
1919
#[cfg(feature = "test")]
2020
use rand::{thread_rng, Rng};
2121

22-
pub mod argsource;
2322
pub mod cwdsource;
2423
pub mod filesource;
2524
mod homethunk;
2625
pub mod terminalsource;
2726
pub mod varsource;
2827

29-
use argsource::*;
3028
use cwdsource::*;
3129
use filesource::*;
3230
use varsource::*;
@@ -68,7 +66,6 @@ use varsource::*;
6866
#[enum_dispatch]
6967
pub trait CurrentProcess:
7068
home::Env
71-
+ ArgSource
7269
+ CurrentDirSource
7370
+ VarSource
7471
+ StdoutSource
@@ -83,7 +80,6 @@ pub trait CurrentProcess:
8380
#[derive(Clone, Debug)]
8481
#[enum_dispatch(
8582
CurrentProcess,
86-
ArgSource,
8783
CurrentDirSource,
8884
VarSource,
8985
StdoutSource,
@@ -110,6 +106,22 @@ impl Process {
110106
.and_then(std::ffi::OsStr::to_str)
111107
.map(String::from)
112108
}
109+
110+
pub(crate) fn args(&self) -> Box<dyn Iterator<Item = String> + '_> {
111+
match self {
112+
Process::OSProcess(_) => Box::new(env::args()),
113+
#[cfg(feature = "test")]
114+
Process::TestProcess(p) => Box::new(p.args.iter().cloned()),
115+
}
116+
}
117+
118+
pub(crate) fn args_os(&self) -> Box<dyn Iterator<Item = OsString> + '_> {
119+
match self {
120+
Process::OSProcess(_) => Box::new(env::args_os()),
121+
#[cfg(feature = "test")]
122+
Process::TestProcess(p) => Box::new(p.args.iter().map(OsString::from)),
123+
}
124+
}
113125
}
114126

115127
/// Obtain the current instance of CurrentProcess

src/currentprocess/argsource.rs

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)