From 254b9115b2e7eaa75b977b3989652aa865777f63 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Fri, 2 Jun 2023 16:30:01 +0200 Subject: [PATCH] feat: add `lock --check` Signed-off-by: Roman Volosatovs --- src/bin/wit-deps/main.rs | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/bin/wit-deps/main.rs b/src/bin/wit-deps/main.rs index e16ca15..405646d 100644 --- a/src/bin/wit-deps/main.rs +++ b/src/bin/wit-deps/main.rs @@ -1,6 +1,7 @@ #![warn(clippy::pedantic)] use std::path::PathBuf; +use std::process::ExitCode; use anyhow::Context; use clap::{Parser, Subcommand}; @@ -32,7 +33,11 @@ struct Cli { #[derive(Debug, Subcommand)] enum Command { /// Lock dependencies - Lock, + Lock { + /// Exit with an error code if dependencies were not already in-sync + #[arg(long, short, action)] + check: bool, + }, /// Update dependencies Update, /// Write a deterministic tar containing the `wit` subdirectory for a package to stdout @@ -47,7 +52,7 @@ enum Command { } #[tokio::main] -async fn main() -> anyhow::Result<()> { +async fn main() -> anyhow::Result { tracing_subscriber::registry() .with( tracing_subscriber::fmt::layer() @@ -72,12 +77,21 @@ async fn main() -> anyhow::Result<()> { } = Cli::parse(); match command { - None | Some(Command::Lock) => wit_deps::lock_path(manifest_path, lock_path, deps_path) + None => wit_deps::lock_path(manifest_path, lock_path, deps_path) + .await + .map(|_| ExitCode::SUCCESS), + Some(Command::Lock { check }) => wit_deps::lock_path(manifest_path, lock_path, deps_path) .await - .map(|_| ()), + .map(|updated| { + if check && updated { + ExitCode::FAILURE + } else { + ExitCode::SUCCESS + } + }), Some(Command::Update) => wit_deps::update_path(manifest_path, lock_path, deps_path) .await - .map(|_| ()), + .map(|_| ExitCode::SUCCESS), Some(Command::Tar { package, output }) => { wit_deps::lock_path(manifest_path, lock_path, &deps_path) .await @@ -91,7 +105,7 @@ async fn main() -> anyhow::Result<()> { } else { wit_deps::tar(package, io::stdout().compat_write()).await?; } - Ok(()) + Ok(ExitCode::SUCCESS) } } }