Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow extra command line arguments #297

Open
FlashSheridan opened this issue May 24, 2023 · 1 comment
Open

Allow extra command line arguments #297

FlashSheridan opened this issue May 24, 2023 · 1 comment

Comments

@FlashSheridan
Copy link
Contributor

Rust newbies (trust me) sometimes need to see what gets passed in as command-line arguments, via env::args or more complicated techniques. Currently std::env::args() just has something like Args { inner: ["~/.cargo/bin/evcxr"] }, even if --opt 2 was passed, and extra arguments stop evcxr from launching. Currently I need to pass in and inspect a bunch of arguments escaped in different ways, so I’d like evcxr just to accept them and put them in std::env::args(), perhaps after an --extra-args argument.

@davidlattimore
Copy link
Collaborator

Evcxr has two processes, both of which are the evcxr binary. The parent process is the one that you run. It's what displays the prompt, parses what you type, writes source files to disk, runs cargo etc. Then there's a subprocess, which is where your code get executed. When you run std::env::args, it's looking at the arguments passed to this subprocess.

So I think it would be possible to pass extra arguments to this subprocess, which would, by default, ignore them. If you clone the evcxr repository, then edit evcxr/src/child_process.rs and make a change like the following:

diff --git a/evcxr/src/child_process.rs b/evcxr/src/child_process.rs
index ef15635..1bdaf90 100644
--- a/evcxr/src/child_process.rs
+++ b/evcxr/src/child_process.rs
@@ -37,6 +37,7 @@ impl ChildProcess {
             bail!("Our current binary doesn't call runtime_hook()");
         }
         command
+            .arg("--foo")
             .env(runtime::EVCXR_IS_RUNTIME_VAR, "1")
             .env("RUST_BACKTRACE", "1")
             .stdin(std::process::Stdio::piped())

If you then run cargo run -p evcxr_repl and in the resulting shell do std::env::args(), you get:

Args { inner: ["/home/david/work/evcxr/target/debug/evcxr", "--foo"] }

Hopefully that helps

FlashSheridan added a commit to FlashSheridan/evcxr that referenced this issue May 25, 2023
“Allow extra command line arguments” evcxr#297
davidlattimore added a commit that referenced this issue May 26, 2023
This now works similarly to how it works with the python REPL. All
arguments after -- get passed to the subprocess. #297
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants