From 765a5d2ef34abf771d41b5166dc6a25db80cf93c Mon Sep 17 00:00:00 2001 From: i1i1 Date: Thu, 10 Aug 2023 18:06:08 +0300 Subject: [PATCH] Fix build and upload-keys --- src/cli.rs | 42 +++++++++++++++++++++++++++++++++----- src/command/apply.rs | 6 +++--- src/command/build.rs | 21 ------------------- src/command/mod.rs | 2 -- src/command/upload_keys.rs | 21 ------------------- src/nix/node_filter.rs | 2 +- 6 files changed, 41 insertions(+), 53 deletions(-) delete mode 100644 src/command/build.rs delete mode 100644 src/command/upload_keys.rs diff --git a/src/cli.rs b/src/cli.rs index 4e83b18..0d5b15c 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -8,7 +8,7 @@ use const_format::{concatcp, formatcp}; use env_logger::fmt::WriteStyle; use crate::{ - command, + command::{self, apply::DeployOpts}, error::ColmenaResult, nix::{Hive, HivePath}, }; @@ -160,9 +160,27 @@ enum Command { Apply(command::apply::Opts), #[cfg(target_os = "linux")] ApplyLocal(command::apply_local::Opts), - Build(command::build::Opts), + #[command( + about = "Build configurations but not push to remote machines", + long_about = r#"Build configurations but not push to remote machines + +This subcommand behaves as if you invoked `apply` with the `build` goal."# + )] + Build { + #[command(flatten)] + deploy: DeployOpts, + }, Eval(command::eval::Opts), - UploadKeys(command::upload_keys::Opts), + #[command( + about = "Upload keys to remote hosts", + long_about = r#"Upload keys to remote hosts + +This subcommand behaves as if you invoked `apply` with the pseudo `keys` goal."# + )] + UploadKeys { + #[command(flatten)] + deploy: DeployOpts, + }, Exec(command::exec::Opts), Repl(command::repl::Opts), NixInfo(command::nix_info::Opts), @@ -261,8 +279,22 @@ pub async fn run() { Command::NixInfo(args) => r(command::nix_info::run(args)).await, Command::Repl(args) => r(command::repl::run(hive, args)).await, Command::TestProgress => r(command::test_progress::run()).await, - Command::Build(_args) => todo!("This is an alias for `colmena apply build`"), - Command::UploadKeys(_opts) => todo!("This is an alias for `colmena apply upload-keys`"), + Command::Build { deploy } => { + let args = command::apply::Opts { + deploy, + goal: crate::nix::Goal::Build, + node_filter: Default::default(), + }; + r(command::apply::run(hive, args)).await + }, + Command::UploadKeys { deploy } => { + let args = command::apply::Opts { + deploy, + goal: crate::nix::Goal::UploadKeys, + node_filter: Default::default(), + }; + r(command::apply::run(hive, args)).await + }, Command::GenCompletions { shell } => print_completions(shell, &mut Opts::command()), } } diff --git a/src/command/apply.rs b/src/command/apply.rs index 54fa256..823d3a6 100644 --- a/src/command/apply.rs +++ b/src/command/apply.rs @@ -132,11 +132,11 @@ Same as the targets for switch-to-configuration, with the following extra pseudo "#, default_value_if("reboot", ArgPredicate::IsPresent, Some("boot")) )] - goal: Goal, + pub goal: Goal, #[command(flatten)] - deploy: DeployOpts, + pub deploy: DeployOpts, #[command(flatten)] - node_filter: NodeFilterOpts, + pub node_filter: NodeFilterOpts, } pub async fn run(hive: Hive, opts: Opts) -> Result<(), ColmenaError> { diff --git a/src/command/build.rs b/src/command/build.rs deleted file mode 100644 index d8682a2..0000000 --- a/src/command/build.rs +++ /dev/null @@ -1,21 +0,0 @@ -use clap::Args; - -use crate::nix::Goal; - -pub use super::apply::run; -use super::apply::DeployOpts; - -#[derive(Debug, Args)] -#[command( - name = "build", - about = "Build configurations but not push to remote machines", - long_about = r#"Build configurations but not push to remote machines - -This subcommand behaves as if you invoked `apply` with the `build` goal."# -)] -pub struct Opts { - #[command(flatten)] - deploy: DeployOpts, - #[arg(hide = true, default_value_t = Goal::Build)] - goal: Goal, -} diff --git a/src/command/mod.rs b/src/command/mod.rs index d982081..cc6c8cb 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -1,10 +1,8 @@ pub mod apply; -pub mod build; pub mod eval; pub mod exec; pub mod nix_info; pub mod repl; -pub mod upload_keys; #[cfg(target_os = "linux")] pub mod apply_local; diff --git a/src/command/upload_keys.rs b/src/command/upload_keys.rs deleted file mode 100644 index 9cc6e3e..0000000 --- a/src/command/upload_keys.rs +++ /dev/null @@ -1,21 +0,0 @@ -use clap::Args; - -use crate::nix::Goal; - -pub use super::apply::run; -use super::apply::DeployOpts; - -#[derive(Debug, Args)] -#[command( - name = "upload-keys", - about = "Upload keys to remote hosts", - long_about = r#"Upload keys to remote hosts - -This subcommand behaves as if you invoked `apply` with the pseudo `keys` goal."# -)] -pub struct Opts { - #[command(flatten)] - deploy: DeployOpts, - #[arg(hide = true, default_value_t = Goal::Build)] - goal: Goal, -} diff --git a/src/nix/node_filter.rs b/src/nix/node_filter.rs index f018cd8..0e99801 100644 --- a/src/nix/node_filter.rs +++ b/src/nix/node_filter.rs @@ -10,7 +10,7 @@ use glob::Pattern as GlobPattern; use super::{ColmenaError, ColmenaResult, NodeConfig, NodeName}; -#[derive(Debug, Args)] +#[derive(Debug, Default, Args)] pub struct NodeFilterOpts { #[arg( long,