Skip to content

Commit

Permalink
feat: optimize incase of large inputs
Browse files Browse the repository at this point in the history
Also changes --summarise flag to --summary. --summarise was recent and
unreleased.
  • Loading branch information
Shivix committed Jul 21, 2024
1 parent 083ec6b commit a300526
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 82 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,6 @@ target/
# These are backup files generated by rustfmt
**/*.rs.bk

notes.md
notes.md
test.txt
large_test.txt
9 changes: 8 additions & 1 deletion Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "prefix"
version = "1.0.4"
version = "1.1.0"
authors = ["Shivix"]
edition = "2021"
description = "A customizable pretty printer for FIX messages"
Expand All @@ -27,6 +27,7 @@ categories = [
[dependencies]
regex = "1.10.5"
clap = "4.5.9"
once_cell = "1.19.0"

[build-dependencies]
clap = "4.5.9"
Expand Down
34 changes: 22 additions & 12 deletions completion/_prefix
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,23 @@ _prefix() {
fi

local context curcontext="$curcontext" state line
_arguments "${_arguments_options[@]}" \
'-d+[Set delimiter string to print after each FIX field.]: : ' \
'--delimiter=[Set delimiter string to print after each FIX field.]: : ' \
'-h[Print help information]' \
'--help[Print help information]' \
'-V[Print version information]' \
'--version[Print version information]' \
'-v[Translate the values of some tags. (for Side: 1 -> Buy)]' \
'--value[Translate the values of some tags. (for Side: 1 -> Buy)]' \
'-s[Strip the whitespace around the = in each field. Less human readable but closer to real FIX.]' \
'--strip[Strip the whitespace around the = in each field. Less human readable but closer to real FIX.]' \
_arguments "${_arguments_options[@]}" : \
'-c+[Adds colour to the delimiter and = in for FIX fields, auto will colour only when printing directly into a tty]:when:(always auto never)' \
'--color=[Adds colour to the delimiter and = in for FIX fields, auto will colour only when printing directly into a tty]:when:(always auto never)' \
'-d+[Set delimiter string to print after each FIX field]:delimiter: ' \
'--delimiter=[Set delimiter string to print after each FIX field]:delimiter: ' \
'-z+[Summarise each fix message based on an optional template]' \
'--summary=[Summarise each fix message based on an optional template]' \
'-s[Strip the whitespace around the = in each field]' \
'--strip[Strip the whitespace around the = in each field]' \
'-t[Translate all numbers to tag names whether part of a message or not]' \
'--tag[Translate all numbers to tag names whether part of a message or not]' \
'-v[Translate the values of some tags (for Side\: 1 -> Buy)]' \
'--value[Translate the values of some tags (for Side\: 1 -> Buy)]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'*::message -- FIX message to be parsed, if not provided will look for a message piped through stdin:' \
&& ret=0
}
Expand All @@ -35,4 +41,8 @@ _prefix_commands() {
_describe -t commands 'prefix commands' commands "$@"
}

_prefix "$@"
if [ "$funcstack[1]" = "_prefix" ]; then
_prefix "$@"
else
compdef _prefix prefix
fi
26 changes: 16 additions & 10 deletions completion/_prefix.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,22 @@ Register-ArgumentCompleter -Native -CommandName 'prefix' -ScriptBlock {

$completions = @(switch ($command) {
'prefix' {
[CompletionResult]::new('-d', 'd', [CompletionResultType]::ParameterName, 'Set delimiter string to print after each FIX field.')
[CompletionResult]::new('--delimiter', 'delimiter', [CompletionResultType]::ParameterName, 'Set delimiter string to print after each FIX field.')
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help information')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help information')
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version information')
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version information')
[CompletionResult]::new('-v', 'v', [CompletionResultType]::ParameterName, 'Translate the values of some tags. (for Side: 1 -> Buy)')
[CompletionResult]::new('--value', 'value', [CompletionResultType]::ParameterName, 'Translate the values of some tags. (for Side: 1 -> Buy)')
[CompletionResult]::new('-s', 's', [CompletionResultType]::ParameterName, 'Strip the whitespace around the = in each field. Less human readable but closer to real FIX.')
[CompletionResult]::new('--strip', 'strip', [CompletionResultType]::ParameterName, 'Strip the whitespace around the = in each field. Less human readable but closer to real FIX.')
[CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'Adds colour to the delimiter and = in for FIX fields, auto will colour only when printing directly into a tty')
[CompletionResult]::new('--color', 'color', [CompletionResultType]::ParameterName, 'Adds colour to the delimiter and = in for FIX fields, auto will colour only when printing directly into a tty')
[CompletionResult]::new('-d', 'd', [CompletionResultType]::ParameterName, 'Set delimiter string to print after each FIX field')
[CompletionResult]::new('--delimiter', 'delimiter', [CompletionResultType]::ParameterName, 'Set delimiter string to print after each FIX field')
[CompletionResult]::new('-z', 'z', [CompletionResultType]::ParameterName, 'Summarise each fix message based on an optional template')
[CompletionResult]::new('--summary', 'summary', [CompletionResultType]::ParameterName, 'Summarise each fix message based on an optional template')
[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 all numbers to tag names whether part of a message or not')
[CompletionResult]::new('--tag', 'tag', [CompletionResultType]::ParameterName, 'Translate all numbers to tag names whether part of a message or not')
[CompletionResult]::new('-v', 'v', [CompletionResultType]::ParameterName, 'Translate the values of some tags (for Side: 1 -> Buy)')
[CompletionResult]::new('--value', 'value', [CompletionResultType]::ParameterName, 'Translate the values of some tags (for Side: 1 -> Buy)')
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
break
}
})
Expand Down
30 changes: 25 additions & 5 deletions completion/prefix.bash
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
_prefix() {
local i cur prev opts cmds
local i cur prev opts cmd
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
Expand All @@ -8,8 +8,8 @@ _prefix() {

for i in ${COMP_WORDS[@]}
do
case "${i}" in
"$1")
case "${cmd},${i}" in
",$1")
cmd="prefix"
;;
*)
Expand All @@ -19,12 +19,20 @@ _prefix() {

case "${cmd}" in
prefix)
opts="-h -V -d -v -s --help --version --delimiter --value --strip <message>..."
opts="-c -d -s -z -t -v -h -V --color --delimiter --strip --summary --tag --value --help --version [message]..."
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
fi
case "${prev}" in
--color)
COMPREPLY=($(compgen -W "always auto never" -- "${cur}"))
return 0
;;
-c)
COMPREPLY=($(compgen -W "always auto never" -- "${cur}"))
return 0
;;
--delimiter)
COMPREPLY=($(compgen -f "${cur}"))
return 0
Expand All @@ -33,6 +41,14 @@ _prefix() {
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
--summary)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
-z)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
*)
COMPREPLY=()
;;
Expand All @@ -43,4 +59,8 @@ _prefix() {
esac
}

complete -F _prefix -o bashdefault -o default prefix
if [[ "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 || "${BASH_VERSINFO[0]}" -gt 4 ]]; then
complete -F _prefix -o nosort -o bashdefault -o default prefix
else
complete -F _prefix -o bashdefault -o default prefix
fi
13 changes: 8 additions & 5 deletions completion/prefix.fish
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
complete -c prefix -s d -l delimiter -d 'Set delimiter string to print after each FIX field.' -r
complete -c prefix -s h -l help -d 'Print help information'
complete -c prefix -s V -l version -d 'Print version information'
complete -c prefix -s v -l value -d 'Translate the values of some tags. (for Side: 1 -> Buy)'
complete -c prefix -s s -l strip -d 'Strip the whitespace around the = in each field. Less human readable but closer to real FIX.'
complete -c prefix -s c -l color -d 'Adds colour to the delimiter and = in for FIX fields, auto will colour only when printing directly into a tty' -r -f -a "{always\t'',auto\t'',never\t''}"
complete -c prefix -s d -l delimiter -d 'Set delimiter string to print after each FIX field' -r
complete -c prefix -s z -l summary -d 'Summarise each fix message based on an optional template' -r
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 all numbers to tag names whether part of a message or not'
complete -c prefix -s v -l value -d 'Translate the values of some tags (for Side: 1 -> Buy)'
complete -c prefix -s h -l help -d 'Print help'
complete -c prefix -s V -l version -d 'Print version'
38 changes: 25 additions & 13 deletions man/prefix.1
Original file line number Diff line number Diff line change
@@ -1,31 +1,43 @@
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.TH prefix 1 "prefix 1.0.4"
.TH prefix 1 "prefix 1.1.0"
.SH NAME
prefix \- A customizable pretty printer for FIX messages
.SH SYNOPSIS
\fBprefix\fR [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] [\fB\-d\fR|\fB\-\-delimiter\fR] [\fB\-v\fR|\fB\-\-value\fR] [\fB\-s\fR|\fB\-\-strip\fR] [\fImessage\fR]
\fBprefix\fR [\fB\-c\fR|\fB\-\-color\fR] [\fB\-d\fR|\fB\-\-delimiter\fR] [\fB\-s\fR|\fB\-\-strip\fR] [\fB\-z\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
.TP
\fB\-h\fR, \fB\-\-help\fR
Print help information
\fB\-c\fR, \fB\-\-color\fR=\fIwhen\fR [default: auto]
Adds colour to the delimiter and = in for FIX fields, auto will colour only when printing directly into a tty
.br

.br
[\fIpossible values: \fRalways, auto, never]
.TP
\fB\-V\fR, \fB\-\-version\fR
Print version information
\fB\-d\fR, \fB\-\-delimiter\fR=\fIdelimiter\fR [default: \\n]
Set delimiter string to print after each FIX field
.TP
\fB\-s\fR, \fB\-\-strip\fR
Strip the whitespace around the = in each field
.TP
\fB\-z\fR, \fB\-\-summary\fR=\fItemplate\fR
Summarise each fix message based on an optional template
.TP
\fB\-d\fR, \fB\-\-delimiter\fR [default:
]
Set delimiter string to print after each FIX field.
\fB\-t\fR, \fB\-\-tag\fR
Translate all numbers to tag names whether part of a message or not
.TP
\fB\-v\fR, \fB\-\-value\fR
Translate the values of some tags. (for Side: 1 \-> Buy)
Translate the values of some tags (for Side: 1 \-> Buy)
.TP
\fB\-s\fR, \fB\-\-strip\fR
Strip the whitespace around the = in each field. Less human readable but closer to real FIX.
\fB\-h\fR, \fB\-\-help\fR
Print help
.TP
\fB\-V\fR, \fB\-\-version\fR
Print version
.TP
[\fImessage\fR]
FIX message to be parsed, if not provided will look for a message piped through stdin
.SH VERSION
v1.0.4
v1.1.0
2 changes: 1 addition & 1 deletion src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn make_command() -> Command {
.action(ArgAction::SetTrue)
)
.arg(
arg!(-z --summarise [template] "Summarise each fix message based on an optional template")
arg!(-z --summary [template] "Summarise each fix message based on an optional template")
.default_missing_value("")
)
.arg(
Expand Down
Loading

0 comments on commit a300526

Please sign in to comment.