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 infile: Option<String>, pub outfile: Option<String>, pub section_map: HashMap<String, Vec<String>>, pub git_dir: Option<PathBuf>, pub git_work_tree: Option<PathBuf>, pub regex: Regex, pub closes_regex: Regex, pub breaks_regex: Regex, pub breaking_regex: Regex, pub out_format: ChangelogFormat, }
The base struct used to set options and interact with the library.
Fields
grep: String
The grep search pattern used to find commits we are interested in (Defaults to: "ft|feat|fx|fix|perf|unk|BREAKING\'")
format: String
The format of the commit output from git log
(Defaults to: "%H%n%s%n%b%n==END==")
repo: String
The repository used for the base of hyper-links
link_style: LinkStyle
The link style to used for commit and issue hyper-links
version: String
The version tag for the release (Defaults to the short hash of the latest commit)
patch_ver: bool
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: String
The subtitle for the release
from: String
Where to start looking for commits using a hash (or short hash)
to: String
Where to stop looking for commits using a hash (or short hash). (Defaults to HEAD
)
infile: Option<String>
The file to use as the old changelog data to be appended to anything new found.
outfile: Option<String>
The file to use as the changelog output file (Defaults to stdout
)
section_map: HashMap<String, Vec<String>>
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: Option<PathBuf>
The git dir with all the meta-data (Typically the .git
sub-directory of the project)
git_work_tree: Option<PathBuf>
The working directory of the git project (typically the project directory, or parent of the
.git
directory)
regex: Regex
The regex used to get components, aliases, and messages
closes_regex: Regex
The regex used to get closes issue links
breaks_regex: Regex
The regex used to get closes issue links
breaking_regex: Regex
out_format: ChangelogFormat
The format to output the changelog in (Defaults to Markdown)
Methods
impl Clog
[src]
fn new() -> Result<Clog, Error>
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| { // Prints the error to stderr and exits e.exit(); });
fn with_all<P: AsRef<Path>>(
git_dir: P,
work_tree: P,
cfg_file: P
) -> Result<Clog, Error>
git_dir: P,
work_tree: P,
cfg_file: P
) -> Result<Clog, Error>
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| { e.exit(); });
fn with_dir_and_file<P: AsRef<Path>>(dir: P, cfg_file: P) -> Result<Clog, Error>
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| { e.exit(); });
fn with_dir<P: AsRef<Path>>(dir: P) -> Result<Clog, Error>
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| { e.exit(); });
fn with_dirs<P: AsRef<Path>>(git_dir: P, work_tree: P) -> Result<Clog, Error>
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| { e.exit(); });
fn from_file<P: AsRef<Path>>(file: P) -> Result<Clog, Error>
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| { e.exit(); });
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| { e.exit(); }); 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| { e.exit(); }); 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| { e.exit(); }); clog.repository("https://github.com/thoughtram/clog");
fn link_style(&mut self, l: LinkStyle) -> &mut 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| { e.exit(); }); 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| { e.exit(); }); 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| { e.exit(); }); 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| { e.exit(); }); 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| { e.exit(); }); clog.to("123abc4d");
fn changelog<S: Into<String> + Clone>(&mut self, c: S) -> &mut Clog
Sets the changelog file to output or prepend to (Defaults to stdout
if omitted)
NOTE: Anything set here will override anything in a configuration TOML file
Example
let mut clog = Clog::new().unwrap_or_else(|e| { e.exit(); }); clog.changelog("/myproject/my_changelog.md");
fn outfile<S: Into<String>>(&mut self, c: S) -> &mut Clog
Sets the changelog output file to output or prepend to (Defaults to stdout
if omitted),
this is useful inconjunction with Clog::infile()
because it allows to read previous
commits from one place and output to another.
NOTE: Anything set here will override anything in a configuration TOML file
NOTE: This should not be used in conjunction with Clog::changelog()
Example
let mut clog = Clog::new().unwrap_or_else(|e| { e.exit(); }); clog.outfile("/myproject/my_changelog.md");
fn infile<S: Into<String>>(&mut self, c: S) -> &mut Clog
Sets the changelog input file to read previous commits or changelog data from. This is
useful inconjunction with Clog::infile()
because it allows to read previous commits from
one place and output to another.
NOTE: Anything set here will override anything in a configuration TOML file
NOTE: This should not be used in conjunction with Clog::changelog()
Example
let mut clog = Clog::new().unwrap_or_else(|e| { e.exit(); }); clog.infile("/myproject/my_old_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| { e.exit(); }); 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| { e.exit(); }); 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| { e.exit(); }); clog.patch_ver(true);
fn output_format(&mut self, f: ChangelogFormat) -> &mut Clog
The format of output for the changelog (Defaults to Markdown)
Example
let mut clog = Clog::new().unwrap_or_else(|e| { e.exit(); }); clog.output_format(ChangelogFormat::Json);
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| { e.exit(); }); 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| { e.exit(); }); 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| { e.exit(); }); 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| { e.exit(); }); 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| { e.exit(); }); let section = clog.section_for("feat"); assert_eq!("Features", section);
fn write_changelog(&self) -> WriterResult
Writes the changelog using whatever options have been specified thus far.
Example
let mut clog = Clog::new().unwrap_or_else(|e| { e.exit(); }); clog.write_changelog();
fn write_changelog_to<P: AsRef<Path>>(&self, cl: P) -> WriterResult
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| e.exit()); clog.write_changelog_to("/myproject/new_changelog.md").unwrap_or_else(|e| { // Prints the error and exits appropriately e.exit(); });
fn write_changelog_from<P: AsRef<Path>>(&self, cl: P) -> WriterResult
Writes the changelog from a specified input file, and appends new commits
Example
let mut clog = Clog::new().unwrap_or_else(|e| e.exit()); clog.write_changelog_from("/myproject/new_old_changelog.md").unwrap_or_else(|e| { // Prints the error and exits appropriately e.exit(); });
fn write_changelog_with<W>(&self, writer: &mut W) -> WriterResult where
W: FormatWriter,
W: FormatWriter,
Writes a changelog with a specified FormatWriter
format
Examples
let clog = Clog::new().unwrap_or_else(|e| { e.exit(); }); // Write changelog to stdout in Markdown format let out = io::stdout(); let mut out_buf = io::BufWriter::new(out.lock()); let mut writer = MarkdownWriter::new(&mut out_buf); clog.write_changelog_with(&mut writer).unwrap_or_else(|e| { // Prints the error and exits appropriately e.exit(); });