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

allow number parameter for --head and --tail #233

Merged
merged 1 commit into from
May 20, 2014

Conversation

blaenk
Copy link
Contributor

@blaenk blaenk commented May 19, 2014

Hey! I love aura and hope this is a welcome contribution!

This allows one to specify a specific number of items to include in the --head and --tail options to the search command. This change is backwards-compatible in that the number parameter is optional. If the flag is called in the same way as it was before this change, the number is still assumed to be 10.

In other words, the following continues to work, showing the first 10 results:

$ aura -As --head needle

The following now works as well, showing the first 3 results:

$ aura -As --head=3 needle

The reason I made this was because the default value of 10 always scrolled the result I was interested in past my terminal height, since usually what I'm looking for is one of the first if not the first result.

It's working nicely :)

This allows one to specify a specific number of items to include in the
--head and --tail options to the search command. This change is
backwards-compatible in that the number parameter is optional. If the
flag is called in the same way as it was before this change, the number
is still assumed to be 10.

In other words, the following continues to work, showing the first 10
results:

```
$ aura -As --head needle
```

The following now works as well, showing the first 3 results:

```
$ aura -As --head=3 needle
```
@bb010g
Copy link
Contributor

bb010g commented May 20, 2014

Aren't these equivalent?
aura -As needle | head -n 20; aura -As --head needle
aura -As needle | head -n 6; aura -As --head=3 needle
POSIX head and tail take care of trimming outputs so programs don't have to.

@blaenk
Copy link
Contributor Author

blaenk commented May 20, 2014

They're indeed equivalent. I just figured since the flags are already in aura it wouldn't hurt to add this optional parameter, especially since it allows one to specify the number in terms of results without having to worry about the description line.

@fosskers
Copy link
Owner

Piped to /usr/bin/head, the behaviour of -n {6,20} isn't as intuitive, I think. Seeing --head=3 I assumed right away "that will give me three results", which indeed it does.

@fosskers
Copy link
Owner

I've reviewed the code. Looks good. I liked your taking advantage of Maybe's Monad status.

@blaenk
Copy link
Contributor Author

blaenk commented May 20, 2014

Haha thanks. I was thinking about how to best express that and I remembered about the monad :)

@fosskers
Copy link
Owner

My knee-jerk reaction is to attempt to express everything using Applicative, but your example there is literally the reason Monads exist.

Also, sorry Aura/Flags.hs is such a gong show. This will be cleared up in Aura 2.

@blaenk
Copy link
Contributor Author

blaenk commented May 20, 2014

Yeah, I really like applicative as well, but I came to the same conclusion.

Yeah, didn't want to say anything but it took me a while to figure out what was what :) I just noticed the plans for Aura 2. I'm going to go over the design document when I have time. I'd love to help out wherever I can.

@fosskers
Copy link
Owner

By all means! And thanks for this patch.

Also note that all current behaviour has to be added to the design doc as well. Kinda like an ultra man page.

fosskers added a commit that referenced this pull request May 20, 2014
Allow numbered parameter for --head and --tail
@fosskers fosskers merged commit 73cb6c2 into fosskers:master May 20, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants