use crate::prelude::internal::*;
#[derive(Args)]
pub struct GtVersionCommand {
#[command(subcommand)]
pub command: GtVersionSubcommand,
}
impl GtVersionCommand {
pub fn path(&self) -> &GtpCwdRelativeOrAbsoluteStringPath {
match &self.command {
GtVersionSubcommand::Set(args) => &args.path,
GtVersionSubcommand::Bump(args) => &args.path,
}
}
}
#[derive(Subcommand)]
pub enum GtVersionSubcommand {
Set(GtVersionSetCommand),
Bump(GtVersionBumpCommand),
}
#[derive(Args)]
pub struct GtVersionSetCommand {
pub version: Version,
#[arg(long)]
pub ts: Option<Version>,
#[arg(long)]
pub py: Option<Version>,
#[arg(long, alias = "rust")]
pub rs: Option<Version>,
#[arg(default_value = ".")]
pub path: GtpCwdRelativeOrAbsoluteStringPath,
}
#[derive(Args)]
pub struct GtVersionBumpCommand {
#[arg(value_enum, default_value = "minor")]
pub part: GtVersionBumpPart,
#[arg(default_value = ".")]
pub path: GtpCwdRelativeOrAbsoluteStringPath,
}
#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum GtVersionBumpPart {
Major,
Minor,
Patch,
}
pub fn version_command(args: &GtVersionCommand) -> Result<()> {
let path = args.path();
let backend = GtbSystem::new(path).wrap_err("Failed to create system backend")?;
let mut project =
block_on(backend.create_project(None)).wrap_err("Failed to create project")?;
match &args.command {
GtVersionSubcommand::Set(args) => {
project
.config_mut()
.set_manifest_version(GtpConfigSetVersionProps {
version: args.version.clone(),
ts: args.ts.clone(),
py: args.py.clone(),
rs: args.rs.clone(),
})?
}
GtVersionSubcommand::Bump(args) => {
project
.config_mut()
.bump_manifest_version(match args.part {
GtVersionBumpPart::Major => GtpConfigVersionPart::Major,
GtVersionBumpPart::Minor => GtpConfigVersionPart::Minor,
GtVersionBumpPart::Patch => GtpConfigVersionPart::Patch,
})?
}
}
block_on(backend.save_config(&project.paths().config_file, project.config()))
}