Struct bkt::CommandDesc[][src]

pub struct CommandDesc { /* fields omitted */ }
Expand description

Describes a command to be executed and cached. This struct also serves as the cache key. It consists of a command line invocation and, optionally, a working directory to execute in and environment variables to set. When set these fields contribute to the cache key, therefore two invocations with different working directories set will be cached separately.

let cmd = bkt::CommandDesc::new(&["echo", "Hello World!"]);
let with_cwd = bkt::CommandDesc::new(&["ls"]).with_working_dir("/tmp");
let with_env = bkt::CommandDesc::new(&["date"]).with_env_value("TZ", "America/New_York");

Implementations

Constructs a CommandDesc instance for the given command line.

let cmd = bkt::CommandDesc::new(&["echo", "Hello World!"]);

Sets the working directory the command should be run from, and causes the working directory to be included in the cache key. If unset the working directory will be inherited from the current process’ and will not be used to differentiate invocations in separate working directories.

let cmd = bkt::CommandDesc::new(&["pwd"]).with_working_dir("/tmp");

Sets the working directory to the current process’ working directory. This has no effect on the subprocess that will be executed (assuming the current process’ working directory remains unchanged) but does cause the working directory to be included in the cache key. Commands that depend on the working directory should call this in order to cache executions in different working directories separately.

Errors

This delegates to std::env::current_dir() and will fail if it does.

Examples

let cmd = bkt::CommandDesc::new(&["pwd"]).with_cwd()?;

Adds the given key/value pair to the environment the command should be run from, and causes this pair to be included in the cache key.

let cmd = bkt::CommandDesc::new(&["pwd"]).with_env_value("FOO", "bar");

Looks up the given environment variable in the current process’ environment and, if set, adds that key/value pair to the environment the command should be run from, and causes this pair to be included in the cache key. This has no effect on the subprocess that will be executed (assuming the current process’ environment remains unchanged).

If the given variable name is not found in the current process’ environment this call is a no-op, and the cache key will remain unchanged.

let cmd = bkt::CommandDesc::new(&["date"]).with_env("TZ");

Adds the given key/value pairs to the environment the command should be run from, and causes these pair to be included in the cache key.

use std::env;
use std::collections::HashMap;

let important_envs : HashMap<String, String> =
    env::vars().filter(|&(ref k, _)|
        k == "TERM" || k == "TZ" || k == "LANG" || k == "PATH"
    ).collect();
let cmd = bkt::CommandDesc::new(&["..."]).with_envs(&important_envs);

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

Performs the conversion.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.