diff --git a/README.md b/README.md index 2514cd2..bdd98d0 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,6 @@ blzrd switch --flake - `switch`: Activate the new configuration and make it the boot default. - `boot`: Set the new configuration as the boot default without activating. -- `list`: List nodes declared in the flake without deploying anything. ### Options @@ -47,12 +46,6 @@ Deploy specific nodes (positional): blzrd switch --flake github:alyraffauf/infra server,workstation ``` -List what's in a flake without deploying: - -``` -blzrd list --flake github:alyraffauf/infra -``` - ### Sample `blzrd.nodes` blzrd is configured with a Flake output containing an attrset that defines a set of deployment jobs. Outputs can be declared in the same Flake or in an upstream Flake. diff --git a/src/cli.rs b/src/cli.rs index e2f24a6..4b5c981 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -44,18 +44,14 @@ pub enum Command { Switch(CommonArgs), /// Set the new configuration as the boot default without activating it. Boot(CommonArgs), - /// List nodes declared in the flake without deploying anything. - List, } impl Command { /// Map a deployment command into its logical `Operation` and shared args. - /// Returns `None` for non-deployment commands like `List`. - pub fn into_deploy(self) -> Option<(Operation, CommonArgs)> { + pub fn into_deploy(self) -> (Operation, CommonArgs) { match self { - Command::Switch(a) => Some((Operation::Switch, a)), - Command::Boot(a) => Some((Operation::Boot, a)), - Command::List => None, + Command::Switch(args) => (Operation::Switch, args), + Command::Boot(args) => (Operation::Boot, args), } } } diff --git a/src/main.rs b/src/main.rs index af753f3..b9b03c8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,6 @@ mod ssh; mod ui; mod workflow; -use crate::cli::Command; use crate::nix::EvaluationProgress; use crate::ui::Ui; @@ -47,16 +46,8 @@ async fn main() -> anyhow::Result<()> { } }; - match args.command { - Command::List => { - Ui::print_nodes(&jobs); - return Ok(()); - } - cmd @ (Command::Switch(_) | Command::Boot(_)) => { - let (op, common) = cmd.into_deploy().expect("deploy command"); - workflow::run_deploy(op, common, jobs, &ui).await?; - } - } + let (op, common) = args.command.into_deploy(); + workflow::run_deploy(op, common, jobs, &ui).await?; Ok(()) } diff --git a/src/ui.rs b/src/ui.rs index af80402..895b17f 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -7,8 +7,6 @@ use std::time::Duration; use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; use owo_colors::{OwoColorize, Stream}; -use crate::models::JobSpec; - pub struct Ui { progress: MultiProgress, is_interactive: bool, @@ -32,15 +30,6 @@ impl Ui { } } - pub fn print_nodes(jobs: &HashMap) { - let mut nodes: Vec<_> = jobs.iter().collect(); - nodes.sort_by_key(|(name, _)| *name); - - for (name, spec) in nodes { - eprintln!("{name} · {} · {}", spec.system, spec.target()); - } - } - pub fn print_warning(message: impl Display) { eprintln!("{}", warning(format!("! {message}"))); } @@ -114,13 +103,9 @@ impl Ui { self.finish_section(section, false); } - pub fn print_completion(&self) { + pub fn print_summary(&self, message: &str) { self.add_section_separator(); - let message = format!( - "{} {}", - success_marker(), - phase_heading("Deployment complete") - ); + let message = format!("{} {}", success_marker(), phase_heading(message)); if self.is_interactive { let progress = self.progress.add(ProgressBar::new_spinner()); progress.set_style(completed_style()); diff --git a/src/workflow.rs b/src/workflow.rs index aa5f613..50d3de7 100644 --- a/src/workflow.rs +++ b/src/workflow.rs @@ -17,12 +17,7 @@ pub async fn run_deploy( jobs: HashMap, ui: &Ui, ) -> anyhow::Result<()> { - let (jobs, unknown_skips) = filter_jobs(jobs, &common)?; - for name in unknown_skips { - Ui::print_warning(format!("ignoring unknown node '{name}' in --skip")); - } - - op::validate(&jobs, operation)?; + let jobs = prepare_jobs(jobs, &common, operation)?; let host_key_policy = host_key_policy(&common); let closures = build_closures(&jobs, &common, host_key_policy, ui).await?; deploy_closures( @@ -36,6 +31,20 @@ pub async fn run_deploy( .await } +fn prepare_jobs( + jobs: HashMap, + common: &CommonArgs, + operation: Operation, +) -> anyhow::Result> { + let (jobs, unknown_skips) = filter_jobs(jobs, common)?; + for name in unknown_skips { + Ui::print_warning(format!("ignoring unknown node '{name}' in --skip")); + } + + op::validate(&jobs, operation)?; + Ok(jobs) +} + /// Apply the `--skip` and `nodes` filters to the evaluated job map. fn filter_jobs( mut jobs: HashMap, @@ -142,7 +151,7 @@ async fn deploy_closures( } ui.finish_section_success(progress); - ui.print_completion(); + ui.print_summary("Deployment complete"); Ok(()) }