Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add lock --check #31

Merged
merged 2 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wit-deps-cli"
version = "0.3.1"
version = "0.3.2"
description = "WIT dependency manager"

authors.workspace = true
Expand Down
26 changes: 20 additions & 6 deletions src/bin/wit-deps/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![warn(clippy::pedantic)]

use std::path::PathBuf;
use std::process::ExitCode;

use anyhow::Context;
use clap::{Parser, Subcommand};
Expand Down Expand Up @@ -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
Expand All @@ -47,7 +52,7 @@ enum Command {
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
async fn main() -> anyhow::Result<ExitCode> {
tracing_subscriber::registry()
.with(
tracing_subscriber::fmt::layer()
Expand All @@ -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
Expand All @@ -91,7 +105,7 @@ async fn main() -> anyhow::Result<()> {
} else {
wit_deps::tar(package, io::stdout().compat_write()).await?;
}
Ok(())
Ok(ExitCode::SUCCESS)
}
}
}