Skip to content

Commit

Permalink
new: added option to enable or disable quotes (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
pamburus authored Mar 21, 2024
1 parent 8c515e9 commit 8459f09
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ categories = ["command-line-utilities"]
description = "Utility for viewing json-formatted log files."
keywords = ["cli", "human", "log"]
name = "hl"
version = "0.27.0-beta.4.3"
version = "0.27.0-beta.4.4"
edition = "2021"
build = "build.rs"

Expand Down
1 change: 1 addition & 0 deletions etc/defaults/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ fields:

# Formatting settings.
formatting:
add-quotes: false
punctuation:
logger-name-separator: ':'
field-key-value-separator: '='
Expand Down
9 changes: 9 additions & 0 deletions src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,15 @@ impl<'a> FieldFormatter<'a> {
ValueKind::String(_) => {
s.element(Element::String, |s| {
s.batch(|buf| {
if self.rf.cfg.add_quotes {
buf.extend_from_slice(self.rf.cfg.punctuation.string_opening_quote.as_bytes())
}

value.format_as_str(buf);

if self.rf.cfg.add_quotes {
buf.extend_from_slice(self.rf.cfg.punctuation.string_closing_quote.as_bytes())
}
})
});
}
Expand Down Expand Up @@ -437,6 +445,7 @@ mod tests {
false,
Arc::new(IncludeExcludeKeyFilter::default()),
Formatting {
add_quotes: false,
punctuation: Punctuation::test_default(),
},
);
Expand Down
2 changes: 2 additions & 0 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,10 @@ pub struct Field {
// ---

#[derive(Clone, Debug, Default, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct Formatting {
pub punctuation: Punctuation,
pub add_quotes: bool,
}

// ---
Expand Down

0 comments on commit 8459f09

Please sign in to comment.