Struct clog::Clog [] [src]

pub struct Clog {
    pub grep: String,
    pub format: String,
    pub repo: String,
    pub link_style: LinkStyle,
    pub version: String,
    pub patch_ver: bool,
    pub subtitle: String,
    pub from: String,
    pub to: String,
    pub changelog: String,
    pub section_map: HashMap<String, Vec<String>>,
    pub git_dir: Option<PathBuf>,
    pub git_work_tree: Option<PathBuf>,
}

The base struct used to set options and interact with the library.

Fields

grep

The grep search pattern used to find commits we are interested in (Defaults to: "ft|feat|fx|fix|unk|BREAKING\'")

format

The format of the commit output from git log (Defaults to: "%H%n%s%n%b%n==END==")

repo

The repository used for the base of hyper-links

The link style to used for commit and issue hyper-links

version

The version tag for the release (Defaults to the short hash of the latest commit)

patch_ver

Whether or not this is a patch version update or not. Patch versions use a lower markdown header (### instead of ## for major and minor releases)

subtitle

The subtitle for the release

from

Where to start looking for commits using a hash (or short hash)

to

Where to stop looking for commits using a hash (or short hash). (Defaults to HEAD)

changelog

The file to use as the changelog. (Defaults to changelog.md)

section_map

Maps out the sections and aliases used to trigger those sections. The keys are the section name, and the values are an array of aliases.

git_dir

The git dir with all the meta-data (Typically the .git sub-directory of the project)

git_work_tree

The working directory of the git project (typically the project directory, or parent of the .git directory)

Methods

impl Clog

fn new() -> ClogResult

Creates a default Clog struct using the current working directory and searches for the default .clog.toml configuration file.

Example

let clog = Clog::new().unwrap_or_else(|e| {
    println!("Error initializing: {}", e);
    std::process::exit(1);
});

fn with_all<P: AsRef<Path>>(git_dir: P, work_tree: P, cfg_file: P) -> ClogResult

Creates a Clog struct using a specific git working directory and project directory as well as a custom named TOML configuration file.

Example

let clog = Clog::with_all("/myproject/.git",
                          "/myproject",
                          "/myproject/clog_conf.toml").unwrap_or_else(|e| {
    println!("Error initializing: {}", e);
    std::process::exit(1);
});

fn with_dir_and_file<P: AsRef<Path>>(dir: P, cfg_file: P) -> ClogResult

Creates a Clog struct using a specific git working directory OR project directory as well as a custom named TOML configuration file.

NOTE: If you specify a .git folder the parent will be used as the working tree, and vice versa.

Example

let clog = Clog::with_dir_and_file("/myproject",
                          "/myproject/clog_conf.toml").unwrap_or_else(|e| {
    println!("Error initializing: {}", e);
    std::process::exit(1);
});

fn with_dir<P: AsRef<Path>>(dir: P) -> ClogResult

Creates a Clog struct using a specific git working directory OR project directory. Searches for the default configuration TOML file .clog.toml

NOTE: If you specify a .git folder the parent will be used as the working tree, and vice versa.

Example

let clog = Clog::with_dir("/myproject").unwrap_or_else(|e| {
    println!("Error initializing: {}", e);
    std::process::exit(1);
});

fn with_dirs<P: AsRef<Path>>(git_dir: P, work_tree: P) -> ClogResult

Creates a Clog struct using a specific git working directory AND a project directory. Searches for the default configuration TOML file .clog.toml

NOTE: If you specify a .git folder the parent will be used as the working tree, and vice versa.

Example

let clog = Clog::with_dirs("/myproject", "/myproject/.git").unwrap_or_else(|e| {
    println!("Error initializing: {}", e);
    std::process::exit(1);
});

fn from_file<P: AsRef<Path>>(file: P) -> ClogResult

Creates a Clog struct a custom named TOML configuration file. Sets the parent directory of the configuration file to the working tree and sibling .git directory as the git directory.

NOTE: If you specify a .git folder the parent will be used as the working tree, and vice versa.

Example

let clog = Clog::from_file("/myproject/clog_conf.toml").unwrap_or_else(|e| {
    println!("Error initializing: {}", e);
    std::process::exit(1);
});

fn from_matches(matches: &ArgMatches) -> ClogResult

Creates a Clog struct from command line clap::ArgMatches

Example


let matches = // clap settings...

let clog = Clog::from_matches(matches).unwrap_or_else(|e| {
    println!("Error initializing: {}", e);
    std::process::exit(1);
});

fn grep<S: Into<String>>(&mut self, g: S) -> &mut Clog

Sets the grep search pattern for finding commits.

Example

let mut clog = Clog::new().unwrap_or_else(|e| {
    println!("Error initializing: {}", e);
    std::process::exit(1);
});
 
clog.grep("BREAKS");

fn format<S: Into<String>>(&mut self, f: S) -> &mut Clog

Sets the format for git log output

Example

let mut clog = Clog::new().unwrap_or_else(|e| {
    println!("Error initializing: {}", e);
    std::process::exit(1);
});
 
clog.format("%H%n%n==END==");

fn repository<S: Into<String>>(&mut self, r: S) -> &mut Clog

Sets the repository used for the base of hyper-links

NOTE: Leave off the trailing .git

NOTE: Anything set here will override anything in a configuration TOML file

Example

let mut clog = Clog::new().unwrap_or_else(|e| {
    println!("Error initializing: {}", e);
    std::process::exit(1);
});
 
clog.repository("https://github.com/thoughtram/clog");

Sets the link style to use for hyper-links

NOTE: Anything set here will override anything in a configuration TOML file

Example

let mut clog = Clog::new().unwrap_or_else(|e| {
    println!("Error initializing: {}", e);
    std::process::exit(1);
});
 
clog.link_style(LinkStyle::Stash);

fn version<S: Into<String>>(&mut self, v: S) -> &mut Clog

Sets the version for the release

NOTE: Anything set here will override anything in a configuration TOML file

Example

let mut clog = Clog::new().unwrap_or_else(|e| {
    println!("Error initializing: {}", e);
    std::process::exit(1);
});
 
clog.version("v0.2.1-beta3");

fn subtitle<S: Into<String>>(&mut self, s: S) -> &mut Clog

Sets the subtitle for the release

Example

let mut clog = Clog::new().unwrap_or_else(|e| {
    println!("Error initializing: {}", e);
    std::process::exit(1);
});
 
clog.subtitle("My Awesome Release Title");

fn from<S: Into<String>>(&mut self, f: S) -> &mut Clog

Sets how far back to begin searching commits using a short hash or full hash

NOTE: Anything set here will override anything in a configuration TOML file

Example

let mut clog = Clog::new().unwrap_or_else(|e| {
    println!("Error initializing: {}", e);
    std::process::exit(1);
});
 
clog.from("6d8183f");

fn to<S: Into<String>>(&mut self, t: S) -> &mut Clog

Sets what point to stop searching for commits using a short hash or full hash (Defaults to HEAD)

Example

let mut clog = Clog::new().unwrap_or_else(|e| {
    println!("Error initializing: {}", e);
    std::process::exit(1);
});
 
clog.to("123abc4d");

fn changelog<S: Into<String>>(&mut self, c: S) -> &mut Clog

Sets the changelog file to output or prepend to (Defaults to changelog.md)

NOTE: Anything set here will override anything in a configuration TOML file

Example

let mut clog = Clog::new().unwrap_or_else(|e| {
    println!("Error initializing: {}", e);
    std::process::exit(1);
});
 
clog.changelog("/myproject/my_changelog.md");

fn git_dir<P: AsRef<Path>>(&mut self, d: P) -> &mut Clog

Sets the git metadata directory (typically .git child of your project working tree)

Example

let mut clog = Clog::new().unwrap_or_else(|e| {
    println!("Error initializing: {}", e);
    std::process::exit(1);
});
 
clog.git_dir("/myproject/.git");

fn git_work_tree<P: AsRef<Path>>(&mut self, d: P) -> &mut Clog

Sets the git working tree directory (typically your project directory)

Example

let mut clog = Clog::new().unwrap_or_else(|e| {
    println!("Error initializing: {}", e);
    std::process::exit(1);
});
 
clog.git_work_tree("/myproject");

fn patch_ver(&mut self, p: bool) -> &mut Clog

Sets whether or not this is a patch release (defaults to false)

NOTE: Setting this to true will cause the release subtitle to use a smaller markdown heading

Example

let mut clog = Clog::new().unwrap_or_else(|e| {
    println!("Error initializing: {}", e);
    std::process::exit(1);
});
 
clog.patch_ver(true);

fn get_commits(&self) -> Commits

Retrieves a Vec<Commit> of only commits we care about.

Example

let mut clog = Clog::new().unwrap_or_else(|e| {
    println!("Error initializing: {}", e);
    std::process::exit(1);
});
 
let commits = clog.get_commits();

fn get_latest_tag(&self) -> String

Retrieves the latest tag from the git directory

Example

let mut clog = Clog::new().unwrap_or_else(|e| {
    println!("Error initializing: {}", e);
    std::process::exit(1);
});
 
let tag = clog.get_latest_tag();

fn get_latest_tag_ver(&self) -> String

Retrieves the latest tag version from the git directory

Example

let mut clog = Clog::new().unwrap_or_else(|e| {
    println!("Error initializing: {}", e);
    std::process::exit(1);
});
 
let tag_ver = clog.get_latest_tag_ver();

fn get_last_commit(&self) -> String

Retrieves the hash of the most recent commit from the git directory (i.e. HEAD)

Example

let mut clog = Clog::new().unwrap_or_else(|e| {
    println!("Error initializing: {}", e);
    std::process::exit(1);
});
 
let head_hash = clog.get_last_commit();

fn section_for(&self, alias: &str) -> &String

Retrieves the section title for a given alias

Example

let mut clog = Clog::new().unwrap_or_else(|e| {
    println!("Error initializing: {}", e);
    std::process::exit(1);
});
 
let section = clog.section_for("feat");
assert_eq!("Features", section);

fn write_changelog_to<P: AsRef<Path>>(&self, cl: P)

Writes the changelog to a specified file, and prepends new commits if file exists, or creates the file if it doesn't

Example

let mut clog = Clog::new().unwrap_or_else(|e| {
    println!("Error initializing: {}", e);
    std::process::exit(1);
});
 
clog.write_changelog_to("/myproject/new_changelog.md");

fn write_changelog(&self)

Writes the changelog to the default location and file or wherever was specified by the TOML or configuration options. Clog prepends new commits if file exists, or creates the file if it doesn't.

Example

let mut clog = Clog::new().unwrap_or_else(|e| {
    println!("Error initializing: {}", e);
    std::process::exit(1);
});
 
clog.write_changelog();

Trait Implementations

impl Debug for Clog

fn fmt(&self, f: &mut Formatter) -> Result