Skip to content

Commit

Permalink
Merge branch 'release-1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
sean0x42 committed Apr 24, 2020
2 parents 95d6ef2 + 55b7716 commit 401d385
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 17 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Patch notes are automatically extracted from this changelog whenever a tag is
pushed to the GitHub repository. The tag name must match a heading exactly.

## v1.1.0

- Exit with code 1 if no matches are found (#3, thanks @brennerm)
- Publish `markdown-extract` as a Docker image (#2, thanks @brennerm)

## v1.0.0

Expand All @@ -13,12 +17,10 @@ The first proper release of `markdown-extract`! :tada:
- Add `--first` flag, which only prints the first matching section.
- Fix an issue where extra newlines where inserted into the final output.


## v0.1.1

- Publish as a binary instead of a library


## v0.1.0-alpha

This version is the initial release of `markdown_extract`! It features the
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "markdown-extract"
description = "Extract sections of a markdown file."
version = "1.0.0"
version = "1.1.0"
authors = ["Sean Bailey <hello@seanbailey.dev>"]
license = "MIT"
repository = "https://github.com/sean0x42/markdown-extract"
Expand Down
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM rust:1.43 as builder
WORKDIR /usr/src/markdown-extract
COPY . .
RUN cargo install --path .

FROM debian:buster-slim
COPY --from=builder /usr/local/cargo/bin/markdown-extract /usr/local/bin/markdown-extract
ENTRYPOINT ["markdown-extract"]
30 changes: 23 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,37 @@ Extract sections of a markdown file. This project mostly exists to help me learn
Rust, and to fill a niche requirement for extracting patch notes from
a `CHANGELOG.md`.

## Installation

## Usage
If you've got Rust installed on your system, you can simple install
`markdown-extract` with Cargo.

Start by installing `markdown-extract`. Requires Cargo.
```console
$ cargo install markdown-extract
```

### Docker

A Docker container is also available, and can be installed with the following
command:

```console
$ docker pull sean0x42/markdown-extract
```
cargo install markdown-extract

You can then run the container with the following command:

```console
$ docker run -it sean0x42/markdown-extract --help
```

## Usage

View the help guide if you like.

```console
$ markdown-extract -h
markdown-extract 1.0.0
$ markdown-extract --help
markdown-extract 1.1.0
Extract sections of a markdown file

USAGE:
Expand All @@ -40,12 +57,11 @@ Then extract matching sections in a markdown file.

```console
$ markdown-extract --fr "^v1" CHANGELOG.md
## v1.0.0
## v1.1.0

...
```


## Use Cases

There aren't many. I created this tool to extract patch notes from a
Expand Down
10 changes: 3 additions & 7 deletions src/bin.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
pub mod document;
mod error;
mod matchers;
mod parser;

use document::{Document, Section};
use error::NoMatchesError;
use matchers::{Matcher, RegexMatcher, SimpleMatcher};
use parser::Parser;
use std::convert::TryInto;
Expand Down Expand Up @@ -61,7 +63,6 @@ fn print_section(document: &Document, section: &Section, ignore_first_heading: b
}

fn run() -> Result<(), Box<dyn Error>> {
// Get opts
let opts = Opts::from_args();

// Create parser and get file
Expand All @@ -76,20 +77,15 @@ fn run() -> Result<(), Box<dyn Error>> {
SimpleMatcher::get_matches(&document, &opts)
};

// Handle no matches
if matches.is_empty() {
println!("No matches.");
return Ok(());
return Err(Box::new(NoMatchesError::new()));
}

// Only print the first match
if opts.first {
// It's okay to use `[0]` here since we check if the doc is empty above
print_section(&document, &matches[0], opts.ignore_first_heading);
return Ok(());
}

// Print matching sections
for section in matches {
print_section(&document, &section, opts.ignore_first_heading);
}
Expand Down
20 changes: 20 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use std::error::Error;
use std::fmt;

#[derive(Debug)]
pub struct NoMatchesError;

impl NoMatchesError {
/// Constructs a new `NoMatchesError`
pub fn new() -> NoMatchesError {
NoMatchesError {}
}
}

impl fmt::Display for NoMatchesError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "No matches.")
}
}

impl Error for NoMatchesError {}

0 comments on commit 401d385

Please sign in to comment.