-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Provide an API to extract fields from Command builder #44434
Copy link
Copy link
Closed
Labels
C-feature-acceptedCategory: A feature request that has been accepted pending implementation.Category: A feature request that has been accepted pending implementation.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Metadata
Metadata
Assignees
Labels
C-feature-acceptedCategory: A feature request that has been accepted pending implementation.Category: A feature request that has been accepted pending implementation.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
This is now implemented on nightly via #77029.
Summary
The following accessors are available on
Commandbehind the#![feature(command_access)]gate:Command::get_programCommand::get_argsCommand::get_envsCommand::get_current_dirUnresolved issues
Some concerns I had with the implementation, but probably not important:
"<string-with-nul>". I don't think it is practical to avoid this, since otherwise a whole separate copy of all the values would need to be kept inCommand.arg0on Unix. This can be awkward to support inget_argsand is rarely used. I figure if someone really wants it, it can be added toCommandExtas a separate method.env_clear. I'm uncertain if it would be useful for anyone.get_env). I figure this can be added later if anyone really wants it. I think the motivation for this is weak, though. Also, the API could be a little awkward (return aOption<Option<&OsStr>>?).get_envscould skip "cleared" entries and just return&OsStrvalues instead ofOption<&OsStr>. I'm on the fence here. My use case is to display a shell command, and I only intend it to be roughly equivalent to the actual execution, and I probably won't displayNoneentries. I erred on the side of providing extra information, but I suspect many situations will just filter out theNones.DoubleEndedIterator).Original issue below
The the
std::process::Commandbuilder is useful for building up a Command in a cross-platform way. I've found that it would be useful to extract the name, args, environment, etc. of aCommandthey have been set.There are at least two places in the Rust compiler that would benefit from such an API. Instead, the authors have had to resort to wrappers instead of using
Commanddirectly.https://github.com/rust-lang/rust/blob/master/src/tools/compiletest/src/runtest.rs#L1527
https://github.com/rust-lang/rust/blob/master/src/librustc_trans/back/command.rs