mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 16:21:33 +11:00
More functionality in release.rs
This commit is contained in:
parent
f2f0f771fb
commit
75cd2cd0e1
|
@ -1,3 +1,7 @@
|
||||||
|
use std::{io::Read, path::Path, process::Command};
|
||||||
|
|
||||||
|
use crate::utils::find_agb_root_directory;
|
||||||
|
|
||||||
pub fn command() -> clap::Command {
|
pub fn command() -> clap::Command {
|
||||||
clap::Command::new("release")
|
clap::Command::new("release")
|
||||||
.about("Prepares and commits the changes required to release agb")
|
.about("Prepares and commits the changes required to release agb")
|
||||||
|
@ -21,12 +25,46 @@ pub fn release(matches: &clap::ArgMatches) -> Result<(), Error> {
|
||||||
.get_one::<Version>("version")
|
.get_one::<Version>("version")
|
||||||
.expect("defined by clap");
|
.expect("defined by clap");
|
||||||
|
|
||||||
println!("dry run: {}, version: {:?}", dry_run, version);
|
let root_directory = find_agb_root_directory().map_err(|_| Error::FindRootDirectory)?;
|
||||||
|
|
||||||
|
// if not dry run, check that there are no out-standing changes in git
|
||||||
|
if !dry_run && !execute_git_command(&root_directory, &["status", "--porcelain"])?.is_empty() {
|
||||||
|
println!("Uncommitted changes, please commit first");
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that we are in the master branch
|
||||||
|
if !dry_run
|
||||||
|
&& execute_git_command(&root_directory, &["symbolic-ref", "--short", "HEAD"])? != "master"
|
||||||
|
{
|
||||||
|
println!("You must be on the master branch before releasing");
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn execute_git_command(root_directory: &Path, args: &[&str]) -> Result<String, Error> {
|
||||||
|
let git_cmd = Command::new("git")
|
||||||
|
.args(args)
|
||||||
|
.current_dir(root_directory)
|
||||||
|
.spawn()
|
||||||
|
.map_err(|_| Error::GitError)?;
|
||||||
|
let mut buf = Vec::new();
|
||||||
|
git_cmd
|
||||||
|
.stdout
|
||||||
|
.ok_or(Error::GitError)?
|
||||||
|
.read_to_end(&mut buf)
|
||||||
|
.map_err(|_| Error::GitError)?;
|
||||||
|
|
||||||
|
String::from_utf8(buf).map_err(|_| Error::GitError)
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error {}
|
pub enum Error {
|
||||||
|
FindRootDirectory,
|
||||||
|
GitError,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
struct Version {
|
struct Version {
|
||||||
|
@ -46,6 +84,12 @@ impl Version {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for Version {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "{}.{}.{}", self.major, self.minor, self.patch)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
struct ParseVersionError;
|
struct ParseVersionError;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue