mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-24 00:31:34 +11:00
Finish the argument parsing
This commit is contained in:
parent
57772af416
commit
d8ca41ec3d
|
@ -4,6 +4,12 @@ use clap::Command;
|
||||||
mod publish;
|
mod publish;
|
||||||
mod release;
|
mod release;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum Error {
|
||||||
|
PublishError(publish::Error),
|
||||||
|
ReleaseError(release::Error),
|
||||||
|
}
|
||||||
|
|
||||||
fn cli() -> Command {
|
fn cli() -> Command {
|
||||||
Command::new("Agb tools")
|
Command::new("Agb tools")
|
||||||
.subcommand_required(true)
|
.subcommand_required(true)
|
||||||
|
@ -16,8 +22,14 @@ fn main() {
|
||||||
let matches = cli().get_matches();
|
let matches = cli().get_matches();
|
||||||
|
|
||||||
let result = match matches.subcommand() {
|
let result = match matches.subcommand() {
|
||||||
Some(("publish", arg_matches)) => publish::publish(arg_matches),
|
Some(("publish", arg_matches)) => {
|
||||||
Some(("release", arg_matches)) => todo!(),
|
publish::publish(arg_matches).map_err(Error::PublishError)
|
||||||
|
}
|
||||||
|
|
||||||
|
Some(("release", arg_matches)) => {
|
||||||
|
release::release(arg_matches).map_err(Error::ReleaseError)
|
||||||
|
}
|
||||||
|
|
||||||
_ => unreachable!("Exhausted list of subcommands and subcommand_required prevents `None`"),
|
_ => unreachable!("Exhausted list of subcommands and subcommand_required prevents `None`"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,31 @@ pub fn command() -> clap::Command {
|
||||||
.about("Prepares and commits the changes required to release agb")
|
.about("Prepares and commits the changes required to release agb")
|
||||||
.arg(
|
.arg(
|
||||||
clap::Arg::new("version")
|
clap::Arg::new("version")
|
||||||
|
.required(true)
|
||||||
.help("New version to release")
|
.help("New version to release")
|
||||||
.value_parser(version_parser),
|
.value_parser(version_parser),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
clap::Arg::new("Dry run")
|
||||||
|
.long("dry-run")
|
||||||
|
.help("Don't do anything with git (but does everything else)")
|
||||||
|
.action(clap::ArgAction::SetTrue),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn release(matches: &clap::ArgMatches) -> Result<(), Error> {
|
||||||
|
let dry_run = matches.get_one::<bool>("Dry run").expect("defined by clap");
|
||||||
|
let version = matches
|
||||||
|
.get_one::<Version>("version")
|
||||||
|
.expect("defined by clap");
|
||||||
|
|
||||||
|
println!("dry run: {}, version: {:?}", dry_run, version);
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum Error {}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
struct Version {
|
struct Version {
|
||||||
major: u32,
|
major: u32,
|
||||||
|
@ -52,7 +72,9 @@ impl std::str::FromStr for Version {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn version_parser(maybe_version: &str) -> Result<Version, &'static str> {
|
fn version_parser(maybe_version: &str) -> Result<Version, &'static str> {
|
||||||
maybe_version.parse().map_err(|_| "Failed to parse version")
|
maybe_version
|
||||||
|
.parse()
|
||||||
|
.map_err(|_| "Failed to parse version, must be of the format x.y.z")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
Loading…
Reference in a new issue