Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Commit

Permalink
Add initial command line interface
Browse files Browse the repository at this point in the history
Users can now use the --against argument to specify against which
commit/tag/branch the current api must be compared against.
  • Loading branch information
Sasha Pourcelot committed Jun 9, 2021
1 parent d721d00 commit 1547dc0
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 4 deletions.
94 changes: 94 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ anyhow = "1.0"
git2 = "0.13"
cargo_toml = "0.9"
semver = "1.0"
clap = "2.33"
26 changes: 26 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use clap::{crate_authors, crate_description, crate_name, crate_version, App, Arg};

pub(crate) struct ProgramConfig {
pub comparaison_ref: String,
}

impl ProgramConfig {
pub(crate) fn parse() -> ProgramConfig {
let matches = App::new(crate_name!())
.version(crate_version!())
.author(crate_authors!())
.about(crate_description!())
.arg(
Arg::with_name("against")
.short("a")
.help("Sets the git reference to compare the API against. Can be a tag, a branch name or a commit.")
.takes_value(true)
.required(false)
.default_value("main")
).get_matches();

let comparaison_ref = matches.value_of("against").unwrap().to_owned();

ProgramConfig { comparaison_ref }
}
}
2 changes: 0 additions & 2 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use anyhow::{Context, Result as AnyResult};

use git2::{Repository, StashFlags, StatusOptions};

pub(crate) static DEFAULT_BRANCH_NAME: &str = "main";

pub(crate) trait GitBackend: Sized {
fn switch_to(&mut self, id: &str) -> AnyResult<()> {
if self.needs_stash() {
Expand Down
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod ast;
mod cli;
mod comparator;
mod git;
mod glue;
Expand All @@ -14,13 +15,15 @@ use crate::{
};

pub fn run() -> AnyResult<()> {
let config = cli::ProgramConfig::parse();

let mut repo = CrateRepo::current().context("Failed to fetch repository data")?;

let current_api = glue::extract_api().context("Failed to get crate API")?;
let version = manifest::get_crate_version().context("Failed to get crate version")?;

repo.switch_to(git::DEFAULT_BRANCH_NAME)
.with_context(|| format!("Failed to checkout to `{}`", git::DEFAULT_BRANCH_NAME))?;
repo.switch_to(config.comparaison_ref.as_str())
.with_context(|| format!("Failed to checkout to `{}`", config.comparaison_ref))?;

let previous_api = glue::extract_api().context("Failed to get crate API")?;

Expand Down

0 comments on commit 1547dc0

Please sign in to comment.