facebook/zstd

zstdgrep parsing of grep options naively broken

オープン

#2,064 opened on 2020/04/03

 (6 件のコメント) (5 件のリアクション) (0 人の担当者)C (2,481 件のフォーク)batch import
bughelp wantedlong-term

Repository metrics

Stars
 (27,100 個のスター)
PR merge metrics
 (PR metrics pending)

説明

Describe the bug zstdgrep as a wrapper for zstdcat | grep should handle grep options properly. It doesn't in several cases. A few examples below.

To Reproduce

# The fact that the -e grep option can be specified multiple times
# for multiple pattern is not handled at all, nor is the use of equivalent
# long options with or without = between them and their arguments

$ echo start > /tmp/file
$ echo stop >> /tmp/file
$ grep -e start -e stop /tmp/file
start
stop
$ grep --regexp=start --regexp=stop /tmp/file
start
stop
$ grep --regexp start --regexp stop /tmp/file
start
stop
$ grep --regexp start --regexp stop -e start /tmp/file
start
stop
$ grep --regexp start --regexp=stop -e start /tmp/file
start
stop
$ zstdgrep --regexp=start --regexp=stop /tmp/file
/tmp/file:start
/tmp/file:stop
Incorrect parameters
$ zstdgrep --regexp start --regexp stop /tmp/file
zstd: can't stat --regexp : No such file or directory -- ignored 
grep: start: No such file or directory
zstd: can't stat stop : No such file or directory -- ignored 
grep: start: No such file or directory
grep: start: No such file or directory
$ zstdgrep -e start -e stop /tmp/file
zstd: can't stat -e : No such file or directory -- ignored 
zstd: can't stat stop : No such file or directory -- ignored 
/tmp/file:start

# --file= and -f with different behaviours for
# -, /dev/fd/0, /dev/stdin as pattern files 
# also regarding when to print the name of the examined file

$ echo start | grep -f - /tmp/file
start
$ echo start | zstdgrep -f - /tmp/file
$ echo start | grep --file=- /tmp/file
start
$ echo start | zstdgrep --file=- /tmp/file
/tmp/file:start

# --file= and -f with different behaviours
# Process substitutions with bash not working as with grep on its own

$ cp  /tmp/file /tmp/file2
$ grep --file=<( echo start ) /tmp/file /tmp/file2
/tmp/file:start
/tmp/file2:start
$ grep -f <( echo start ) /tmp/file /tmp/file2
/tmp/file:start
/tmp/file2:start
$ zstdgrep --file=<( echo start ) /tmp/file /tmp/file2
/tmp/file:start
/tmp/file2:start
$ zstdgrep -f <( echo start ) /tmp/file /tmp/file2
/tmp/file:start

Expected behavior For the behavious of the wrapper to mimic precisely what grep would do on its own.

Additional context Zstd version 1.4.4

コントリビューターガイド