Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add regexp flag to grep and support quotes #61

Merged
merged 1 commit into from
Jan 26, 2021
Merged

Add regexp flag to grep and support quotes #61

merged 1 commit into from
Jan 26, 2021

Conversation

mattlqx
Copy link
Collaborator

@mattlqx mattlqx commented Jan 24, 2021

This adds a regexp flag to the grep command in the spirit of the userland grep binary. In order to support regexps that may include spaces, supported needed added for quoting. my implementation is not very good, but it appears to get the job done including accounting for escaping.

I'm not very experienced in golang so apologies in advance.

# Standard term search
http://localhost:8888 /> grep fruit KV1/
/KV1/src/ambivalence/1> fruit = apple
/KV1/src/ambivalence/1/a> fruit = banana
/KV1/src/dev/1> fruit = apple
/KV1/src/dev/2> fruit = banana
/KV1/src/dev/3> fruit = berry

# Regex search
http://localhost:8888 /> grep fr.it KV1/ -e
/KV1/src/ambivalence/1> fruit = apple
/KV1/src/ambivalence/1/a> fruit = banana
/KV1/src/dev/1> fruit = apple
/KV1/src/dev/2> fruit = banana
/KV1/src/dev/3> fruit = berry

http://localhost:8888 /> grep [abcdef]rui[qrst] KV1/ -e
/KV1/src/ambivalence/1> fruit = apple
/KV1/src/ambivalence/1/a> fruit = banana
/KV1/src/dev/1> fruit = apple
/KV1/src/dev/2> fruit = banana
/KV1/src/dev/3> fruit = berry

http://localhost:8888 /> grep app.* KV1/ -e
/KV1/src/ambivalence/1> fruit = apple
/KV1/src/dev/1> fruit = apple

# quoted space search
http://localhost:8888 /> grep "spaced val" KV1/
/KV1/src/spaces/foo> bar = a spaced value

# escaped quoted search
http://localhost:8888 /> grep "\"quote" KV1/
/KV1/src/quoted/foo> bar = a "quoted" value

@mattlqx mattlqx mentioned this pull request Jan 24, 2021
@fishi0x01 fishi0x01 self-assigned this Jan 26, 2021
@fishi0x01 fishi0x01 added the enhancement New feature or request label Jan 26, 2021
Copy link
Owner

@fishi0x01 fishi0x01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will merge this later today and take care of codeclimate issues before crafting a new release.

Thanks a lot for the great contribution! Highly appreciated 🙇

main.go Show resolved Hide resolved
test/suites/commands/grep.bats Show resolved Hide resolved
cli/grep.go Show resolved Hide resolved
this adds a regexp flag to the `grep` command in the spirit of the userland grep binary.
@mattlqx
Copy link
Collaborator Author

mattlqx commented Jan 26, 2021

Thanks for taking a look. I got the codeclimate issues all taken care of. Since you liked this, I'd like to take care of being able to grep on just keys or values next.

@fishi0x01 fishi0x01 merged commit 7db5a57 into fishi0x01:master Jan 26, 2021
@fishi0x01
Copy link
Owner

fishi0x01 commented Jan 26, 2021

Thank you @mattlqx 🙇

(Reference to original Issue #59)

@mattlqx mattlqx deleted the grep-regexp branch January 26, 2021 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants