pub struct NamedCommand<'a> { /* private fields */ }Expand description
It’s a command, with a name
This struct allows us to re-name an existing Command via the CommandWithName trait associated
functions. When one of those functions such as CommandWithName::named_fn or CommandWithName::named
are called, Rust needs somewhere for the new name string to live, so we move it over into this struct
which also implements CommandWithName. You can gain access to the original Command reference
via CommandWithName::mut_cmd
Trait Implementations§
Source§impl CommandWithName for &mut NamedCommand<'_>
impl CommandWithName for &mut NamedCommand<'_>
Source§fn named(&mut self, s: impl AsRef<str>) -> NamedCommand<'_>
fn named(&mut self, s: impl AsRef<str>) -> NamedCommand<'_>
Rename a command via a given string Read more
Source§fn named_fn<'a>(
&'a mut self,
f: impl FnOnce(&mut Command) -> String,
) -> NamedCommand<'a>
fn named_fn<'a>( &'a mut self, f: impl FnOnce(&mut Command) -> String, ) -> NamedCommand<'a>
Rename a command via a given function Read more
Source§fn named_output(&mut self) -> Result<NamedOutput, CmdError>
fn named_output(&mut self) -> Result<NamedOutput, CmdError>
Runs the command without streaming Read more
Source§impl CommandWithName for NamedCommand<'_>
impl CommandWithName for NamedCommand<'_>
Source§fn named(&mut self, s: impl AsRef<str>) -> NamedCommand<'_>
fn named(&mut self, s: impl AsRef<str>) -> NamedCommand<'_>
Rename a command via a given string Read more
Source§fn named_fn<'a>(
&'a mut self,
f: impl FnOnce(&mut Command) -> String,
) -> NamedCommand<'a>
fn named_fn<'a>( &'a mut self, f: impl FnOnce(&mut Command) -> String, ) -> NamedCommand<'a>
Rename a command via a given function Read more
Source§fn named_output(&mut self) -> Result<NamedOutput, CmdError>
fn named_output(&mut self) -> Result<NamedOutput, CmdError>
Runs the command without streaming Read more
Source§impl<'a> From<&'a mut Command> for NamedCommand<'a>
impl<'a> From<&'a mut Command> for NamedCommand<'a>
Source§fn from(command: &'a mut Command) -> Self
fn from(command: &'a mut Command) -> Self
Convert a Command reference into a NamedCommand
Useful to “shorten” a command (to hide additional/unexpected flags).
use fun_run::{NamedCommand, CommandWithName};
let mut command = std::process::Command::new("go");
let mut short: NamedCommand = command
.args(["list", "-tags", "heroku"])
.into();
short
.mut_cmd()
.args([
"-f",
"{{ if eq .Name \"main\" }}{{ .ImportPath }}{{ end }}",
"./...",
]);
// Short name
assert_eq!("go list -tags heroku", &short.name());
// Full args
assert_eq!("go", short.mut_cmd().get_program().to_str().unwrap());
assert_eq!(
"list -tags heroku -f {{ if eq .Name \"main\" }}{{ .ImportPath }}{{ end }} ./...",
short
.mut_cmd()
.get_args()
.map(|arg| arg.to_str().unwrap())
.collect::<Vec<&str>>()
.join(" ")
);Auto Trait Implementations§
impl<'a> Freeze for NamedCommand<'a>
impl<'a> !RefUnwindSafe for NamedCommand<'a>
impl<'a> Send for NamedCommand<'a>
impl<'a> Sync for NamedCommand<'a>
impl<'a> Unpin for NamedCommand<'a>
impl<'a> !UnwindSafe for NamedCommand<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more