diff options
author | Sascha Grunert <Sascha.Grunert@rohde-schwarz.com> | 2016-10-10 13:22:26 +0200 |
---|---|---|
committer | Sascha Grunert <Sascha.Grunert@rohde-schwarz.com> | 2016-10-10 13:22:26 +0200 |
commit | 8b33c1e3f4aecb85ac6a0b2ba196fddcd2c6f8f4 (patch) | |
tree | 748f8e22c7399fea9516a5e9ba147b4e6bb7167b | |
parent | 5c79184236d23ffbc4b4f9769398402b8b433ecf (diff) |
Added "category_delimiters" configuration option
which is per default `["[", "]"]`
- Changed summary parsing to remove dot at the end
of the line if existing
-rw-r--r-- | .gitjournal.toml | 1 | ||||
-rw-r--r-- | src/config.rs | 6 | ||||
-rw-r--r-- | src/lib.rs | 9 | ||||
-rw-r--r-- | src/parser.rs | 29 | ||||
m--------- | tests/test_repo | 0 | ||||
m--------- | tests/test_repo2 | 0 |
6 files changed, 30 insertions, 15 deletions
diff --git a/.gitjournal.toml b/.gitjournal.toml index 13008af..0f34c51 100644 --- a/.gitjournal.toml +++ b/.gitjournal.toml @@ -1,4 +1,5 @@ categories = ["Added", "Changed", "Fixed", "Improved", "Removed"] +category_delimiters = ["[", "]"] colored_output = true enable_debug = true enable_footers = false diff --git a/src/config.rs b/src/config.rs index a52f967..fbb39b9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -44,11 +44,14 @@ impl fmt::Display for Error { } /// The configuration structure for git-journal. -#[derive(Default, Debug, PartialEq, RustcEncodable, RustcDecodable)] +#[derive(Default, Debug, Clone, PartialEq, RustcEncodable, RustcDecodable)] pub struct Config { /// Specifies the available categories for the commit message pub categories: Vec<String>, + /// Set the characters where the categories are wrapped in + pub category_delimiters: (String, String), + /// Set to false if the output should not be colored pub colored_output: bool, @@ -90,6 +93,7 @@ impl Config { pub fn new() -> Self { Config { categories: Self::get_default_categories(), + category_delimiters: ("[".to_owned(), "]".to_owned()), colored_output: true, default_template: None, enable_debug: true, @@ -186,7 +186,7 @@ impl GitJournal { // Create a new parser with empty results let new_parser = Parser { - categories: new_config.categories.clone(), + config: new_config.clone(), result: vec![], }; @@ -217,6 +217,9 @@ impl GitJournal { /// # Specifies the available categories for the commit message, allowd regular expressions. /// categories = ["Added", "Changed", "Fixed", "Improved", "Removed"] /// + /// Set the characters where the categories are wrapped in + /// category_delimiters: ["[", "]"], + /// /// # Set to false if the output should not be colored /// colored_output = true /// @@ -696,7 +699,7 @@ impl GitJournal { }; // Print the log - let output_vec = try!(self.parser.print(&self.config, &compact, used_template)); + let output_vec = try!(self.parser.print(&compact, used_template)); // Print the log to the file if necessary if let Some(output) = output { @@ -826,7 +829,7 @@ mod tests { assert_eq!(journal.config.excluded_commit_tags.len(), 0); assert!(journal.parse_log("HEAD", "rc", &0, &true, &false).is_ok()); assert_eq!(journal.parser.result.len(), journal.tags.len() + 1); - assert_eq!(journal.parser.result[0].commits.len(), 14); + assert_eq!(journal.parser.result[0].commits.len(), 15); assert_eq!(journal.parser.result[1].commits.len(), 1); assert_eq!(journal.parser.result[2].commits.len(), 2); assert!(journal.print_log(false, None, Some("CHANGELOG.md")).is_ok()); diff --git a/src/parser.rs b/src/parser.rs index 1bfa8fe..68fb7d6 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -529,7 +529,9 @@ impl Print for SummaryElement { if config.colored_output { try!(c1(t)); } - tryw!(t, "[{}] ", self.category); + tryw!(t, "{}", config.category_delimiters.0); + tryw!(t, "{}", self.category); + tryw!(t, "{} ", config.category_delimiters.1); if config.colored_output { try!(c2(t)); } @@ -665,7 +667,9 @@ impl Print for ListElement { if config.colored_output { try!(c1(t)); } - tryw!(t, "[{}] ", self.category); + tryw!(t, "{}", config.category_delimiters.0); + tryw!(t, "{}", self.category); + tryw!(t, "{} ", config.category_delimiters.1); if config.colored_output { try!(c2(t)); } @@ -776,19 +780,19 @@ lazy_static! { #[derive(Clone)] pub struct Parser { - pub categories: Vec<String>, + pub config: Config, pub result: Vec<ParsedTag>, } impl Parser { method!(parse_category<Self, &[u8], &str>, self, chain!( - tag!("[")? ~ + tag!(self.config.category_delimiters.0.as_str())? ~ p_category: map_res!( - re_bytes_find!(&self.categories.join("|")), + re_bytes_find!(&self.config.categories.join("|")), str::from_utf8 ) ~ - tag!("]")? , + tag!(self.config.category_delimiters.1.as_str())? , || p_category )); @@ -844,7 +848,11 @@ impl Parser { }) .collect::<Vec<String>>()); } - (tags, RE_TAGS.replace_all(string, "")) + let mut text = RE_TAGS.replace_all(string, ""); + if let Some('.') = text.chars().rev().nth(0) { + text.pop(); + } + (tags, text) } /// Parses a single commit message and returns a changelog ready form @@ -909,13 +917,13 @@ impl Parser { } /// Prints the commits without any template - pub fn print(&self, config: &Config, compact: &bool, template: Option<&str>) -> Result<Vec<u8>, Error> { + pub fn print(&self, compact: &bool, template: Option<&str>) -> Result<Vec<u8>, Error> { let mut term = try!(term::stdout().ok_or(Error::Terminal)); let mut vec = vec![]; // Print every tag for (index, tag) in self.result.iter().enumerate() { - try!(tag.print_to_term_and_write_to_vector(&mut term, &mut vec, compact, config, + try!(tag.print_to_term_and_write_to_vector(&mut term, &mut vec, compact, &self.config, template, (index, self.result.len()))); } @@ -952,9 +960,8 @@ mod tests { use config::Config; fn get_parser() -> Parser { - let config = Config::new(); Parser { - categories: config.categories, + config: Config::new(), result: vec![], } } diff --git a/tests/test_repo b/tests/test_repo -Subproject d8ce784dbee39b9f7d01e44f4d422e782f7af75 +Subproject 47ac43d65258cd4805d28d71ed7e2f48b5cfe31 diff --git a/tests/test_repo2 b/tests/test_repo2 -Subproject a827c05feee91c9f1f566419aef1fcf9fe5a6c0 +Subproject c1cbc43fc48870c71535ffb6808ccf8b26ef9a2 |