command: Rename introspect to eval

This commit is contained in:
Zhaofeng Li 2021-10-28 17:27:30 -07:00
parent f7eb121260
commit 86eeeece3c
4 changed files with 24 additions and 8 deletions

View file

@ -170,7 +170,7 @@ Here is a short example:
The full set of options can be found at `src/nix/eval.nix`.
Run `colmena build` in the same directory to build the configuration, or do `colmena apply` to build and deploy it to all nodes.
## `colmena introspect`
## `colmena eval`
Sometimes you may want to extract values from your Hive configuration for consumption in another program (e.g., [OctoDNS](https://github.com/octodns/octodns)).
To do that, create a `.nix` file with a lambda:
@ -184,7 +184,7 @@ lib.attrsets.mapAttrs (k: v: v.config.deployment.targetHost) nodes
Then you can evaluate with:
```
colmena introspect your-lambda.nix
colmena eval your-lambda.nix
```
## `colmena apply-local`

View file

@ -65,12 +65,15 @@ For a sample configuration, see <https://github.com/zhaofengli/colmena>.
.index(1)
.required(true)
.takes_value(true)));
// deprecated alias
app = app.subcommand(command::eval::deprecated_alias());
}
register_command!(apply, app);
register_command!(apply_local, app);
register_command!(build, app);
register_command!(introspect, app);
register_command!(eval, app);
register_command!(upload_keys, app);
register_command!(exec, app);
register_command!(nix_info, app);
@ -85,11 +88,14 @@ pub async fn run() {
handle_command!(apply, matches);
handle_command!("apply-local", apply_local, matches);
handle_command!(build, matches);
handle_command!(introspect, matches);
handle_command!(eval, matches);
handle_command!("upload-keys", upload_keys, matches);
handle_command!(exec, matches);
handle_command!("nix-info", nix_info, matches);
// deprecated alias
handle_command!("introspect", eval, matches);
if let Some(args) = matches.subcommand_matches("gen-completions") {
return gen_completions(args);
}

View file

@ -1,11 +1,11 @@
use std::path::PathBuf;
use clap::{Arg, App, SubCommand, ArgMatches};
use clap::{Arg, App, AppSettings, SubCommand, ArgMatches};
use crate::util;
pub fn subcommand() -> App<'static, 'static> {
SubCommand::with_name("introspect")
SubCommand::with_name("eval")
.about("Evaluate expressions using the complete configuration")
.long_about(r#"Evaluate expressions using the complete configuration
@ -31,7 +31,17 @@ For example, to retrieve the configuration of one node, you may write something
.takes_value(false))
}
pub async fn run(_global_args: &ArgMatches<'_>, local_args: &ArgMatches<'_>) {
pub fn deprecated_alias() -> App<'static, 'static> {
subcommand()
.name("introspect")
.setting(AppSettings::Hidden)
}
pub async fn run(global_args: &ArgMatches<'_>, local_args: &ArgMatches<'_>) {
if let Some("introspect") = global_args.subcommand_name() {
log::warn!("`colmena introspect` has been renamed to `colmena eval`. Please update your scripts.");
}
let hive = util::hive_from_args(local_args).await.unwrap();
if !(local_args.is_present("expression") ^ local_args.is_present("expression_file")) {

View file

@ -1,6 +1,6 @@
pub mod build;
pub mod apply;
pub mod introspect;
pub mod eval;
pub mod apply_local;
pub mod upload_keys;
pub mod exec;