NamedCommand

Struct NamedCommand 

Source
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<'_>

Source§

fn name(&mut self) -> String

Returns the desired display name of the command
Source§

fn mut_cmd(&mut self) -> &mut Command

Returns a reference to &mut Command Read more
Source§

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>

Rename a command via a given function Read more
Source§

fn named_output(&mut self) -> Result<NamedOutput, CmdError>

Runs the command without streaming Read more
Source§

fn stream_output<OW, EW>( &mut self, stdout_write: OW, stderr_write: EW, ) -> Result<NamedOutput, CmdError>
where OW: Write + Send, EW: Write + Send,

Runs the command and streams to the given writers Read more
Source§

impl CommandWithName for NamedCommand<'_>

Source§

fn name(&mut self) -> String

Returns the desired display name of the command
Source§

fn mut_cmd(&mut self) -> &mut Command

Returns a reference to &mut Command Read more
Source§

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>

Rename a command via a given function Read more
Source§

fn named_output(&mut self) -> Result<NamedOutput, CmdError>

Runs the command without streaming Read more
Source§

fn stream_output<OW, EW>( &mut self, stdout_write: OW, stderr_write: EW, ) -> Result<NamedOutput, CmdError>
where OW: Write + Send, EW: Write + Send,

Runs the command and streams to the given writers Read more
Source§

impl<'a> From<&'a mut Command> for NamedCommand<'a>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.