mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 16:21:33 +11:00
Allow dry run of publish
This commit is contained in:
parent
375c878849
commit
4277f07ec0
|
@ -6,11 +6,11 @@ fn main() {
|
||||||
let matches = Command::new("Agb tools")
|
let matches = Command::new("Agb tools")
|
||||||
.subcommand_required(true)
|
.subcommand_required(true)
|
||||||
.arg_required_else_help(true)
|
.arg_required_else_help(true)
|
||||||
.subcommand(clap::Command::new("publish").about("Publishes agb and all subcrates"))
|
.subcommand(publish::command())
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
let result = match matches.subcommand() {
|
let result = match matches.subcommand() {
|
||||||
Some(("publish", _)) => publish::publish(),
|
Some(("publish", arg_matches)) => publish::publish(arg_matches),
|
||||||
_ => unreachable!("Exhausted list of subcommands and subcommand_required prevents `None`"),
|
_ => unreachable!("Exhausted list of subcommands and subcommand_required prevents `None`"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use clap::{Arg, ArgAction, ArgMatches};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
@ -21,19 +22,40 @@ pub enum Error {
|
||||||
CrateVersion,
|
CrateVersion,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn publish() -> Result<(), Error> {
|
pub fn command() -> clap::Command<'static> {
|
||||||
|
clap::Command::new("publish")
|
||||||
|
.about("Publishes agb and all subcrates")
|
||||||
|
.arg(
|
||||||
|
Arg::new("Dry run")
|
||||||
|
.long("dry-run")
|
||||||
|
.help("Don't actually publish")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn publish(matches: &ArgMatches) -> Result<(), Error> {
|
||||||
|
let dry_run = matches.get_one::<bool>("Dry run").expect("defined by clap");
|
||||||
|
|
||||||
let root_directory = find_agb_root_directory()?;
|
let root_directory = find_agb_root_directory()?;
|
||||||
|
|
||||||
for crate_to_publish in CRATES_TO_PUBLISH.iter() {
|
for crate_to_publish in CRATES_TO_PUBLISH.iter() {
|
||||||
let crate_dir = root_directory.join(crate_to_publish);
|
let crate_dir = root_directory.join(crate_to_publish);
|
||||||
let publish_result = Command::new("cargo")
|
|
||||||
.arg("publish")
|
|
||||||
.current_dir(&crate_dir)
|
|
||||||
.spawn();
|
|
||||||
|
|
||||||
if let Err(err) = publish_result {
|
if *dry_run {
|
||||||
println!("Error while publishing crate {crate_to_publish}: {err}");
|
println!(
|
||||||
return Err(Error::PublishCrate);
|
"Would run `cargo publish` in {}",
|
||||||
|
crate_dir.to_string_lossy()
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
let publish_result = Command::new("cargo")
|
||||||
|
.arg("publish")
|
||||||
|
.current_dir(&crate_dir)
|
||||||
|
.spawn();
|
||||||
|
|
||||||
|
if let Err(err) = publish_result {
|
||||||
|
println!("Error while publishing crate {crate_to_publish}: {err}");
|
||||||
|
return Err(Error::PublishCrate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let expected_version = read_cargo_toml_version(&crate_dir)?;
|
let expected_version = read_cargo_toml_version(&crate_dir)?;
|
||||||
|
|
Loading…
Reference in a new issue