I was looking at issue #11 which was attempted to be fixed with #20. The change wasn't landed because of the difference in launching PowerShell file and a script block. My particular use case is mainly around files with parameters, so I'm looking at how this would work.
What do you think about a builder approach where you need to specify script or file, which can then allow for args only when you're going to run a file?
If this seems acceptable, I'd be happy to work on a PR
Something like
fn main() {
let ps = PsScriptBuilder::new()
.no_profile(true)
.non_interactive(true)
.hidden(false)
.print_commands(false)
.file("path/to/file.ps1")
.arguments.add("argument")
.build();
// below fails
let output = ps.run(r#"echo "hello world""#).unwrap();
// below works
let output = ps.run().unwrap();
}
likewise
fn main() {
let ps = PsScriptBuilder::new()
.no_profile(true)
.non_interactive(true)
.hidden(false)
.print_commands(false)
.build();
// below works
let output = ps.run(r#"echo "hello world""#).unwrap();
// below fails
let output = ps.run().unwrap();
}
I think it would be better to have both approaches specify the payload (file or script) in the builder methods, but that would conflict with how it works currently.