forked from DGNum/colmena
Fix panic with hive path parsing and use value parser
This commit is contained in:
parent
ce0782ccac
commit
1ad9301c62
5 changed files with 24 additions and 42 deletions
13
src/cli.rs
13
src/cli.rs
|
@ -10,7 +10,7 @@ use clap_complete::Shell;
|
||||||
use const_format::{concatcp, formatcp};
|
use const_format::{concatcp, formatcp};
|
||||||
use env_logger::fmt::WriteStyle;
|
use env_logger::fmt::WriteStyle;
|
||||||
|
|
||||||
use crate::command;
|
use crate::{command, nix::HivePath};
|
||||||
|
|
||||||
/// Base URL of the manual, without the trailing slash.
|
/// Base URL of the manual, without the trailing slash.
|
||||||
const MANUAL_URL_BASE: &str = "https://colmena.cli.rs";
|
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")
|
.help("Path to a Hive expression, a flake.nix, or a Nix Flake URI")
|
||||||
.long_help(Some(CONFIG_HELP))
|
.long_help(Some(CONFIG_HELP))
|
||||||
.display_order(HELP_ORDER_FIRST)
|
.display_order(HELP_ORDER_FIRST)
|
||||||
|
.global(true)
|
||||||
// The default value is a lie (sort of)!
|
.value_parser(value_parser!(HivePath)))
|
||||||
//
|
|
||||||
// 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))
|
|
||||||
.arg(Arg::new("show-trace")
|
.arg(Arg::new("show-trace")
|
||||||
.long("show-trace")
|
.long("show-trace")
|
||||||
.help("Show debug information for Nix commands")
|
.help("Show debug information for Nix commands")
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use clap::{ArgMatches, Args, FromArgMatches, Command};
|
use clap::{ArgMatches, Args, Command, FromArgMatches};
|
||||||
|
|
||||||
use crate::error::ColmenaError;
|
use crate::error::ColmenaError;
|
||||||
use crate::nix::evaluator::nix_eval_jobs::get_pinned_nix_eval_jobs;
|
use crate::nix::evaluator::nix_eval_jobs::get_pinned_nix_eval_jobs;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use clap::{Args, Command as ClapCommand};
|
use clap::{Args, Command as ClapCommand};
|
||||||
|
|
||||||
use crate::{nix::Goal, util};
|
use crate::nix::Goal;
|
||||||
|
|
||||||
pub use super::apply::run;
|
pub use super::apply::run;
|
||||||
use super::apply::DeployOpts;
|
use super::apply::DeployOpts;
|
||||||
|
|
|
@ -122,20 +122,27 @@ impl FromStr for HivePath {
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
// TODO: check for escaped colon maybe?
|
// 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()
|
let handle = tokio::runtime::Handle::try_current()
|
||||||
.expect("We should always be executed after we have a runtime");
|
.expect("We should always be executed after we have a runtime");
|
||||||
|
std::thread::spawn(move || handle.block_on(fut))
|
||||||
if !path.exists() && s.contains(':') {
|
.join()
|
||||||
// Treat as flake URI
|
.expect("Failed to join future")
|
||||||
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))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
18
src/util.rs
18
src/util.rs
|
@ -4,7 +4,6 @@ use std::error::Error;
|
||||||
use std::process::Stdio;
|
use std::process::Stdio;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use clap::{Arg, Command as ClapCommand};
|
|
||||||
use futures::future::join3;
|
use futures::future::join3;
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
use tokio::io::{AsyncBufReadExt, AsyncRead, BufReader};
|
use tokio::io::{AsyncBufReadExt, AsyncRead, BufReader};
|
||||||
|
@ -207,23 +206,6 @@ where
|
||||||
Ok((s[..pos].parse()?, s[pos + 1..].parse()?))
|
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<R>(
|
pub async fn capture_stream<R>(
|
||||||
mut stream: BufReader<R>,
|
mut stream: BufReader<R>,
|
||||||
job: Option<JobHandle>,
|
job: Option<JobHandle>,
|
||||||
|
|
Loading…
Reference in a new issue