Skip to content

Commit c528452

Browse files
committed
Simplify process access to argument iterator
1 parent 6d43761 commit c528452

File tree

5 files changed

+21
-75
lines changed

5 files changed

+21
-75
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
process, terminalsource,
2120
varsource::VarSource,

src/cli/proxy_mode.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
cli::{common::set_globals, job, self_update},
88
command::run_command_for_dir,
99
config::Cfg,
10-
currentprocess::{argsource::ArgSource, process},
10+
currentprocess::process,
1111
toolchain::names::{LocalToolchainName, ResolvableLocalToolchainName},
1212
utils::utils,
1313
};
@@ -18,7 +18,8 @@ pub async fn main(arg0: &str) -> Result<ExitStatus> {
1818

1919
let _setup = job::setup();
2020

21-
let mut args = process().args_os().skip(1);
21+
let process = process();
22+
let mut args = process.args_os().skip(1);
2223

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

src/cli/rustup_mode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use crate::{
2424
command,
2525
config::{new_toolchain_with_reason, ActiveReason, Cfg},
2626
currentprocess::{
27-
argsource::ArgSource,
2827
filesource::{StderrSource, StdoutSource},
2928
process,
3029
terminalsource::{self, ColorableTerminal},
@@ -1513,7 +1512,8 @@ async fn man(
15131512

15141513
fn set_auto_self_update(cfg: &mut Cfg, auto_self_update_mode: &str) -> Result<utils::ExitCode> {
15151514
if self_update::NEVER_SELF_UPDATE {
1516-
let mut args = process().args_os();
1515+
let process = process();
1516+
let mut args = process.args_os();
15171517
let arg0 = args.next().map(PathBuf::from);
15181518
let arg0 = arg0
15191519
.as_ref()

src/currentprocess.rs

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

23-
pub mod argsource;
2423
pub mod cwdsource;
2524
pub mod filesource;
2625
mod homethunk;
2726
pub mod terminalsource;
2827
pub mod varsource;
2928

30-
use argsource::*;
3129
use cwdsource::*;
3230
use filesource::*;
3331
use varsource::*;
@@ -69,7 +67,6 @@ use varsource::*;
6967
#[enum_dispatch]
7068
pub trait CurrentProcess:
7169
home::Env
72-
+ ArgSource
7370
+ CurrentDirSource
7471
+ VarSource
7572
+ StdoutSource
@@ -84,7 +81,6 @@ pub trait CurrentProcess:
8481
#[derive(Clone, Debug)]
8582
#[enum_dispatch(
8683
CurrentProcess,
87-
ArgSource,
8884
CurrentDirSource,
8985
VarSource,
9086
StdoutSource,
@@ -111,6 +107,22 @@ impl Process {
111107
.and_then(std::ffi::OsStr::to_str)
112108
.map(String::from)
113109
}
110+
111+
pub(crate) fn args(&self) -> Box<dyn Iterator<Item = String> + '_> {
112+
match self {
113+
Process::OSProcess(_) => Box::new(env::args()),
114+
#[cfg(feature = "test")]
115+
Process::TestProcess(p) => Box::new(p.args.iter().cloned()),
116+
}
117+
}
118+
119+
pub(crate) fn args_os(&self) -> Box<dyn Iterator<Item = OsString> + '_> {
120+
match self {
121+
Process::OSProcess(_) => Box::new(env::args_os()),
122+
#[cfg(feature = "test")]
123+
Process::TestProcess(p) => Box::new(p.args.iter().map(OsString::from)),
124+
}
125+
}
114126
}
115127

116128
/// 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)