Skip to content

Commit 4fa441c

Browse files
committed
Fix getting wrong exe path on some platforms
1 parent 63cc7bd commit 4fa441c

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/main.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mod github;
77
mod paths;
88
mod tool_cache;
99

10-
use std::{env, error::Error, io, path::Path};
10+
use std::{env, error::Error, io};
1111

1212
use structopt::StructOpt;
1313

@@ -20,19 +20,16 @@ struct ToolInvocation {
2020
}
2121

2222
impl ToolInvocation {
23-
fn from_args() -> Option<Self> {
24-
let mut all_args = env::args();
25-
26-
let app_path = all_args.next()?;
27-
let as_path = Path::new(&app_path);
28-
let name = as_path.file_stem()?.to_str()?.to_owned();
23+
fn from_env() -> Option<Self> {
24+
let app_path = env::current_exe().unwrap();
25+
let name = app_path.file_stem()?.to_str()?.to_owned();
2926

3027
// That's us!
3128
if name == "foreman" {
3229
return None;
3330
}
3431

35-
let args = all_args.collect();
32+
let args = env::args().skip(1).collect();
3633

3734
Some(Self { name, args })
3835
}
@@ -48,7 +45,7 @@ fn main() -> Result<(), Box<dyn Error>> {
4845

4946
paths::create()?;
5047

51-
if let Some(invocation) = ToolInvocation::from_args() {
48+
if let Some(invocation) = ToolInvocation::from_env() {
5249
let config = ConfigFile::aggregate()?;
5350

5451
if let Some(tool_spec) = config.tools.get(&invocation.name) {

0 commit comments

Comments
 (0)