forked from DGNum/colmena
introspect: Support actually instantiating the expression
This commit is contained in:
parent
fac91c524b
commit
765f42fa24
2 changed files with 22 additions and 6 deletions
|
@ -25,6 +25,10 @@ For example, to retrieve the configuration of one node, you may write something
|
|||
.value_name("EXPRESSION")
|
||||
.help("The Nix expression")
|
||||
.takes_value(true))
|
||||
.arg(Arg::with_name("instantiate")
|
||||
.long("instantiate")
|
||||
.help("Actually instantiate the expression")
|
||||
.takes_value(false))
|
||||
}
|
||||
|
||||
pub async fn run(_global_args: &ArgMatches<'_>, local_args: &ArgMatches<'_>) {
|
||||
|
@ -42,6 +46,12 @@ pub async fn run(_global_args: &ArgMatches<'_>, local_args: &ArgMatches<'_>) {
|
|||
format!("import {}", path.canonicalize().expect("Could not generate absolute path to expression file.").to_str().unwrap())
|
||||
};
|
||||
|
||||
let result = hive.introspect(expression).await.unwrap();
|
||||
let instantiate = local_args.is_present("instantiate");
|
||||
let result = hive.introspect(expression, instantiate).await.unwrap();
|
||||
|
||||
if instantiate {
|
||||
print!("{}", result);
|
||||
} else {
|
||||
println!("{}", result);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -185,11 +185,17 @@ impl Hive {
|
|||
}
|
||||
|
||||
/// Evaluates an expression using values from the configuration
|
||||
pub async fn introspect(&self, expression: String) -> NixResult<String> {
|
||||
pub async fn introspect(&self, expression: String, instantiate: bool) -> NixResult<String> {
|
||||
if instantiate {
|
||||
let expression = format!("hive.introspect ({})", expression);
|
||||
self.nix_instantiate(&expression).instantiate_with_builders().await?
|
||||
.capture_output().await
|
||||
} else {
|
||||
let expression = format!("toJSON (hive.introspect ({}))", expression);
|
||||
self.nix_instantiate(&expression).eval_with_builders().await?
|
||||
.capture_json().await
|
||||
}
|
||||
}
|
||||
|
||||
/// Retrieve machinesFile setting for the hive.
|
||||
async fn machines_file(&self) -> NixResult<Option<String>> {
|
||||
|
|
Loading…
Reference in a new issue