Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 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
@@ -1,6 +1,6 @@
[package]
name = "prefix"
version = "1.1.5"
version = "1.2.0"
authors = ["Shivix"]
edition = "2021"
description = "A customizable pretty printer for FIX messages"
Expand Down
7 changes: 2 additions & 5 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@ fn main() -> Result<(), Error> {

for shell in [Bash, Fish, PowerShell, Zsh] {
let completion_path = clap_complete::generate_to(shell, &mut cmd, "prefix", &out_dir)?;
println!(
"cargo:warning=completion file is generated: {:?}",
completion_path
);
println!("cargo:warning=completion file is generated: {completion_path:?}");
}

let man = clap_mangen::Man::new(cmd);
let man_path = Man::generate_to(&man, out_dir)?;
println!("cargo:warning=man file is generated: {:?}", man_path);
println!("cargo:warning=man file is generated: {man_path:?}");

Ok(())
}
5 changes: 3 additions & 2 deletions completion/_prefix
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ _prefix() {
'--summary=[Summarise each fix message based on an optional template]' \
'-o[Only print FIX messages]' \
'--only-fix[Only print FIX messages]' \
'-f[Only consider full FIX messages containing both BeginString and Checksum]' \
'--strict[Only consider full FIX messages containing both BeginString and Checksum]' \
'--porcelain[print FIX messages closer to standard format, same as --delimiter \\x01 --strip]' \
'-r[Combine any repeating groups into a single field with a comma delimited value]' \
'--repeating[Combine any repeating groups into a single field with a comma delimited value]' \
'-f[Only consider full FIX messages containing both BeginString and Checksum]' \
'--strict[Only consider full FIX messages containing both BeginString and Checksum]' \
'-s[Strip the whitespace around the = in each field]' \
'--strip[Strip the whitespace around the = in each field]' \
'-t[Translate tag numbers on non FIX message lines]' \
Expand Down
5 changes: 3 additions & 2 deletions completion/_prefix.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ Register-ArgumentCompleter -Native -CommandName 'prefix' -ScriptBlock {
[CompletionResult]::new('--summary', 'summary', [CompletionResultType]::ParameterName, 'Summarise each fix message based on an optional template')
[CompletionResult]::new('-o', 'o', [CompletionResultType]::ParameterName, 'Only print FIX messages')
[CompletionResult]::new('--only-fix', 'only-fix', [CompletionResultType]::ParameterName, 'Only print FIX messages')
[CompletionResult]::new('-f', 'f', [CompletionResultType]::ParameterName, 'Only consider full FIX messages containing both BeginString and Checksum')
[CompletionResult]::new('--strict', 'strict', [CompletionResultType]::ParameterName, 'Only consider full FIX messages containing both BeginString and Checksum')
[CompletionResult]::new('--porcelain', 'porcelain', [CompletionResultType]::ParameterName, 'print FIX messages closer to standard format, same as --delimiter \x01 --strip')
[CompletionResult]::new('-r', 'r', [CompletionResultType]::ParameterName, 'Combine any repeating groups into a single field with a comma delimited value')
[CompletionResult]::new('--repeating', 'repeating', [CompletionResultType]::ParameterName, 'Combine any repeating groups into a single field with a comma delimited value')
[CompletionResult]::new('-f', 'f', [CompletionResultType]::ParameterName, 'Only consider full FIX messages containing both BeginString and Checksum')
[CompletionResult]::new('--strict', 'strict', [CompletionResultType]::ParameterName, 'Only consider full FIX messages containing both BeginString and Checksum')
[CompletionResult]::new('-s', 's', [CompletionResultType]::ParameterName, 'Strip the whitespace around the = in each field')
[CompletionResult]::new('--strip', 'strip', [CompletionResultType]::ParameterName, 'Strip the whitespace around the = in each field')
[CompletionResult]::new('-t', 't', [CompletionResultType]::ParameterName, 'Translate tag numbers on non FIX message lines')
Expand Down
2 changes: 1 addition & 1 deletion completion/prefix.bash
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ _prefix() {

case "${cmd}" in
prefix)
opts="-c -d -o -f -r -s -S -t -v -h -V --color --delimiter --only-fix --strict --repeating --strip --summary --tag --value --help --version [message]..."
opts="-c -d -o -r -f -s -S -t -v -h -V --color --delimiter --only-fix --porcelain --repeating --strict --strip --summary --tag --value --help --version [message]..."
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down
3 changes: 2 additions & 1 deletion completion/prefix.fish
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ complete -c prefix -s c -l color -d 'Adds colour to the delimiter and = in for F
complete -c prefix -s d -l delimiter -d 'Set delimiter string to print after each FIX field' -r
complete -c prefix -s S -l summary -d 'Summarise each fix message based on an optional template' -r
complete -c prefix -s o -l only-fix -d 'Only print FIX messages'
complete -c prefix -s f -l strict -d 'Only consider full FIX messages containing both BeginString and Checksum'
complete -c prefix -l porcelain -d 'print FIX messages closer to standard format, same as --delimiter \\x01 --strip'
complete -c prefix -s r -l repeating -d 'Combine any repeating groups into a single field with a comma delimited value'
complete -c prefix -s f -l strict -d 'Only consider full FIX messages containing both BeginString and Checksum'
complete -c prefix -s s -l strip -d 'Strip the whitespace around the = in each field'
complete -c prefix -s t -l tag -d 'Translate tag numbers on non FIX message lines'
complete -c prefix -s v -l value -d 'Translate the values of some tags (for Side: 1 -> Buy)'
Expand Down
13 changes: 8 additions & 5 deletions man/prefix.1
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.TH prefix 1 "prefix 1.1.5"
.TH prefix 1 "prefix 1.2.0"
.SH NAME
prefix \- A customizable pretty printer for FIX messages
.SH SYNOPSIS
\fBprefix\fR [\fB\-c\fR|\fB\-\-color\fR] [\fB\-d\fR|\fB\-\-delimiter\fR] [\fB\-o\fR|\fB\-\-only\-fix\fR] [\fB\-f\fR|\fB\-\-strict\fR] [\fB\-r\fR|\fB\-\-repeating\fR] [\fB\-s\fR|\fB\-\-strip\fR] [\fB\-S\fR|\fB\-\-summary\fR] [\fB\-t\fR|\fB\-\-tag\fR] [\fB\-v\fR|\fB\-\-value\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] [\fImessage\fR]
\fBprefix\fR [\fB\-c\fR|\fB\-\-color\fR] [\fB\-d\fR|\fB\-\-delimiter\fR] [\fB\-o\fR|\fB\-\-only\-fix\fR] [\fB\-\-porcelain\fR] [\fB\-r\fR|\fB\-\-repeating\fR] [\fB\-f\fR|\fB\-\-strict\fR] [\fB\-s\fR|\fB\-\-strip\fR] [\fB\-S\fR|\fB\-\-summary\fR] [\fB\-t\fR|\fB\-\-tag\fR] [\fB\-v\fR|\fB\-\-value\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] [\fImessage\fR]
.SH DESCRIPTION
A customizable pretty printer for FIX messages
.SH OPTIONS
Expand All @@ -22,12 +22,15 @@ Set delimiter string to print after each FIX field
\fB\-o\fR, \fB\-\-only\-fix\fR
Only print FIX messages
.TP
\fB\-f\fR, \fB\-\-strict\fR
Only consider full FIX messages containing both BeginString and Checksum
\fB\-\-porcelain\fR
print FIX messages closer to standard format, same as \-\-delimiter \\x01 \-\-strip
.TP
\fB\-r\fR, \fB\-\-repeating\fR
Combine any repeating groups into a single field with a comma delimited value
.TP
\fB\-f\fR, \fB\-\-strict\fR
Only consider full FIX messages containing both BeginString and Checksum
.TP
\fB\-s\fR, \fB\-\-strip\fR
Strip the whitespace around the = in each field
.TP
Expand All @@ -49,4 +52,4 @@ Print version
[\fImessage\fR]
FIX message to be parsed, if not provided will look for a message piped through stdin
.SH VERSION
v1.1.5
v1.2.0
6 changes: 5 additions & 1 deletion src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ pub fn make_command() -> Command {
.action(ArgAction::SetTrue)
)
.arg(
arg!(-f --strict "Only consider full FIX messages containing both BeginString and Checksum")
arg!(--porcelain "print FIX messages closer to standard format, same as --delimiter \\x01 --strip")
.action(ArgAction::SetTrue)
)
.arg(
arg!(-r --repeating "Combine any repeating groups into a single field with a comma delimited value")
.action(ArgAction::SetTrue)
)
.arg(
arg!(-f --strict "Only consider full FIX messages containing both BeginString and Checksum")
.action(ArgAction::SetTrue)
)
.arg(
arg!(-s --strip "Strip the whitespace around the = in each field")
.action(ArgAction::SetTrue)
Expand Down
39 changes: 33 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,39 @@ use std::io;

fn main() {
let matches = command::make_command().get_matches();
let flags = prefix::matches_to_flags(&matches);

let fix_message: Vec<String> = match matches.get_many::<String>("message") {
Some(msg) => msg.map(|elem| elem.to_owned()).collect(),
None => io::stdin().lines().map(|line| line.unwrap()).collect(),
};
// Avoid compiling regexes multiple times.
let msg_regex = prefix::get_msg_regex();
let tag_regex = prefix::get_tag_regex();
let summary_regexes = prefix::get_summary_regexes(&flags);

let flags = prefix::matches_to_flags(&matches);
prefix::run(&fix_message, &flags);
if let Some(msgs) = matches.get_many::<String>("message") {
let n_msgs = msgs.len();
for (i, msg) in msgs.enumerate() {
let is_last_line = i + 1 == n_msgs;
prefix::run(
msg,
is_last_line,
&msg_regex,
&tag_regex,
&summary_regexes,
&flags,
);
}
} else {
let mut lines = io::stdin().lines().peekable();
while let Some(line) = lines.next() {
let line = line.unwrap();
let is_last_line = lines.peek().is_none();
prefix::run(
&line,
is_last_line,
&msg_regex,
&tag_regex,
&summary_regexes,
&flags,
);
}
}
}
Loading