mod config_path;
mod generate_completions;
mod init;
pub(crate) mod manifest_command;
mod release;
mod release_pr;
pub(crate) mod repo_command;
mod set_version;
mod update;
use anyhow::bail;
use cargo_metadata::camino::{Utf8Path, Utf8PathBuf};
use cargo_utils::CARGO_TOML;
use clap::{
ValueEnum,
builder::{Styles, styling::AnsiColor},
};
use init::Init;
use release_plz_core::fs_utils::current_directory;
use set_version::SetVersion;
use tracing::level_filters::LevelFilter;
use self::{
generate_completions::GenerateCompletions, release::Release, release_pr::ReleasePr,
update::Update,
};
const MAIN_COLOR: AnsiColor = AnsiColor::Red;
const SECONDARY_COLOR: AnsiColor = AnsiColor::Yellow;
const HELP_STYLES: Styles = Styles::styled()
.header(MAIN_COLOR.on_default().bold())
.usage(MAIN_COLOR.on_default().bold())
.placeholder(SECONDARY_COLOR.on_default())
.literal(SECONDARY_COLOR.on_default());
#[derive(clap::Parser, Debug)]
#[command(version, author, styles = HELP_STYLES)]
pub struct CliArgs {
#[command(subcommand)]
pub command: Command,
#[arg(
short,
long,
global = true,
action = clap::ArgAction::Count,
)]
verbose: u8,
}
impl CliArgs {
pub fn verbosity(&self) -> anyhow::Result<Option<LevelFilter>> {
let level = match self.verbose {
0 => None,
1 => Some(LevelFilter::INFO),
2 => Some(LevelFilter::DEBUG),
3 => Some(LevelFilter::TRACE),
_ => bail!("invalid verbosity level. Use -v, -vv, or -vvv."),
};
Ok(level)
}
}
#[derive(clap::Subcommand, Debug)]
pub enum Command {
Update(Update),
ReleasePr(ReleasePr),
Release(Release),
GenerateCompletions(GenerateCompletions),
CheckUpdates,
GenerateSchema,
Init(Init),
SetVersion(SetVersion),
}
#[derive(ValueEnum, Clone, Copy, Debug, Eq, PartialEq)]
pub enum OutputType {
Json,
}
fn local_manifest(manifest_path: Option<&Utf8Path>) -> Utf8PathBuf {
match manifest_path {
Some(manifest) => manifest.to_path_buf(),
None => current_directory().unwrap().join(CARGO_TOML),
}
}