1mod cargo_command;
2mod config;
3mod publish;
4mod update;
5mod versioning;
6
7use std::{
8 path::{Path, PathBuf},
9 process::{Command, Stdio},
10};
11
12use anyhow::Result;
13use bpaf::Bpaf;
14
15pub use self::{publish::Publish, update::Update};
16
17#[derive(Debug, Clone, Bpaf)]
18pub struct Options {
19 pub release: Vec<String>,
21
22 #[bpaf(switch, fallback(false))]
24 pub dry_run: bool,
25
26 #[bpaf(positional("PATH"), fallback_with(crate::current_dir))]
28 pub path: PathBuf,
29}
30
31#[derive(Debug, Clone, Bpaf)]
32#[bpaf(options("release-oxc"))]
33pub enum ReleaseCommand {
34 #[bpaf(command)]
36 Update(#[bpaf(external(options))] Options),
37
38 #[bpaf(command)]
40 Changelog(#[bpaf(external(options))] Options),
41
42 #[bpaf(command)]
44 RegenerateChangelogs(#[bpaf(external(options))] Options),
45
46 #[bpaf(command)]
48 Publish(#[bpaf(external(options))] Options),
49}
50
51fn current_dir() -> Result<PathBuf, String> {
52 std::env::current_dir().map_err(|err| format!("{err:?}"))
53}
54
55pub fn check_git_clean(path: &Path) -> Result<()> {
56 let git_status = Command::new("git")
57 .current_dir(path)
58 .stdout(Stdio::null())
59 .args(["diff", "--exit-code"])
60 .status();
61 if !git_status.is_ok_and(|s| s.success()) {
62 anyhow::bail!("Uncommitted changes found, please check `git status`.")
63 }
64 Ok(())
65}