diff --git a/src/cli.rs b/src/cli.rs index e424d93..a5d9b83 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -10,7 +10,7 @@ use clap_complete::Shell; use const_format::{concatcp, formatcp}; use env_logger::fmt::WriteStyle; -use crate::command; +use crate::{command, nix::HivePath}; /// Base URL of the manual, without the trailing slash. const MANUAL_URL_BASE: &str = "https://colmena.cli.rs"; @@ -132,15 +132,8 @@ pub fn build_cli(include_internal: bool) -> ClapCommand { .help("Path to a Hive expression, a flake.nix, or a Nix Flake URI") .long_help(Some(CONFIG_HELP)) .display_order(HELP_ORDER_FIRST) - - // The default value is a lie (sort of)! - // - // The default behavior is to search upwards from the - // current working directory for a file named "flake.nix" - // or "hive.nix". This behavior is disabled if --config/-f - // is explicitly supplied by the user (occurrences_of > 0). - .default_value("hive.nix") - .global(true)) + .global(true) + .value_parser(value_parser!(HivePath))) .arg(Arg::new("show-trace") .long("show-trace") .help("Show debug information for Nix commands") diff --git a/src/command/nix_info.rs b/src/command/nix_info.rs index 8857d5b..5a54fb8 100644 --- a/src/command/nix_info.rs +++ b/src/command/nix_info.rs @@ -1,4 +1,4 @@ -use clap::{ArgMatches, Args, FromArgMatches, Command}; +use clap::{ArgMatches, Args, Command, FromArgMatches}; use crate::error::ColmenaError; use crate::nix::evaluator::nix_eval_jobs::get_pinned_nix_eval_jobs; diff --git a/src/command/upload_keys.rs b/src/command/upload_keys.rs index 2ce213f..43f42b9 100644 --- a/src/command/upload_keys.rs +++ b/src/command/upload_keys.rs @@ -1,6 +1,6 @@ use clap::{Args, Command as ClapCommand}; -use crate::{nix::Goal, util}; +use crate::nix::Goal; pub use super::apply::run; use super::apply::DeployOpts; diff --git a/src/nix/hive/mod.rs b/src/nix/hive/mod.rs index d8a897b..2989806 100644 --- a/src/nix/hive/mod.rs +++ b/src/nix/hive/mod.rs @@ -122,20 +122,27 @@ impl FromStr for HivePath { fn from_str(s: &str) -> Result { // TODO: check for escaped colon maybe? - let path = std::path::Path::new(s); + let s = s.to_owned(); + let path = std::path::PathBuf::from(&s); + + let fut = async move { + if !path.exists() && s.contains(':') { + // Treat as flake URI + let flake = Flake::from_uri(s).await?; + + log::info!("Using flake: {}", flake.uri()); + + Ok(Self::Flake(flake)) + } else { + HivePath::from_path(path).await + } + }; + let handle = tokio::runtime::Handle::try_current() .expect("We should always be executed after we have a runtime"); - - if !path.exists() && s.contains(':') { - // Treat as flake URI - let flake = handle.block_on(Flake::from_uri(s))?; - - log::info!("Using flake: {}", flake.uri()); - - Ok(Self::Flake(flake)) - } else { - handle.block_on(HivePath::from_path(path)) - } + std::thread::spawn(move || handle.block_on(fut)) + .join() + .expect("Failed to join future") } } diff --git a/src/util.rs b/src/util.rs index 93fee77..1a07f9a 100644 --- a/src/util.rs +++ b/src/util.rs @@ -4,7 +4,6 @@ use std::error::Error; use std::process::Stdio; use async_trait::async_trait; -use clap::{Arg, Command as ClapCommand}; use futures::future::join3; use serde::de::DeserializeOwned; use tokio::io::{AsyncBufReadExt, AsyncRead, BufReader}; @@ -207,23 +206,6 @@ where Ok((s[..pos].parse()?, s[pos + 1..].parse()?)) } -pub fn register_selector_args(command: ClapCommand) -> ClapCommand { - command - .arg(Arg::new("on") - .long("on") - .value_name("NODES") - .help("Node selector") - .long_help(r#"Select a list of nodes to deploy to. - -The list is comma-separated and globs are supported. To match tags, prepend the filter by @. Valid examples: - -- host1,host2,host3 -- edge-* -- edge-*,core-* -- @a-tag,@tags-can-have-*"#) - .num_args(1)) -} - pub async fn capture_stream( mut stream: BufReader, job: Option,