Skip to content

Commit

Permalink
Fix --nix-option flag
Browse files Browse the repository at this point in the history
  • Loading branch information
i1i1 committed Aug 11, 2023
1 parent 5dfb581 commit 499469e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 20 deletions.
10 changes: 5 additions & 5 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,16 @@ struct Opts {
impure: bool,
#[arg(
long,
value_parser = crate::util::parse_key_val::<String, String>,
help = "Passes an arbitrary option to Nix commands",
long_help = r#"Passes arbitrary options to Nix commands
This only works when building locally.
"#,
global = true,
num_args = 2,
value_names = ["NAME, VALUE"],
value_names = ["NAME", "VALUE"],
)]
nix_option: Vec<(String, String)>,
nix_option: Vec<String>,
#[arg(
long,
value_name = "WHEN",
Expand Down Expand Up @@ -263,8 +262,9 @@ async fn get_hive(opts: &Opts) -> ColmenaResult<Hive> {
hive.set_impure(true);
}

for (name, value) in opts.nix_option.iter().cloned() {
hive.add_nix_option(name, value);
for chunks in opts.nix_option.chunks_exact(2) {
let [name, value] = chunks else { unreachable!() };
hive.add_nix_option(name.clone(), value.clone());
}

Ok(hive)
Expand Down
15 changes: 0 additions & 15 deletions src/util.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::convert::TryFrom;
use std::error::Error;

use std::process::Stdio;

Expand Down Expand Up @@ -192,20 +191,6 @@ impl CommandExt for CommandExecution {
}
}

/// Parse a single key-value pair
pub fn parse_key_val<T, U>(s: &str) -> Result<(T, U), Box<dyn Error + Send + Sync + 'static>>
where
T: std::str::FromStr,
T::Err: Error + Send + Sync + 'static,
U: std::str::FromStr,
U::Err: Error + Send + Sync + 'static,
{
let pos = s
.find('=')
.ok_or_else(|| format!("invalid KEY=value: no `=` found in `{s}`"))?;
Ok((s[..pos].parse()?, s[pos + 1..].parse()?))
}

pub async fn capture_stream<R>(
mut stream: BufReader<R>,
job: Option<JobHandle>,
Expand Down

0 comments on commit 499469e

Please sign in to comment.