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 file support #8

Closed
bep opened this issue May 24, 2015 · 7 comments
Closed

Add file support #8

bep opened this issue May 24, 2015 · 7 comments

Comments

@bep
Copy link

bep commented May 24, 2015

Useful little util.

It would be nice if it, in addition to the stdin support, could work with file(s) as arguments.

Currently this works:

cat myfile.txt | xurls

This just hangs there, waiting:

xurls myfile.txt

An example of a Go tool that works as expected for a *nix CLI tool would be ccat.

@mvdan
Copy link
Owner

mvdan commented May 24, 2015

Is it a common pattern for all unix tools that work with stdin/stdout to also accept files as arguments? I don't see why it shouldn't be supported, but just wondering.

I'm also thinking about multiple files. I'm guessing you would have xurls file1 file2 work just like cat file1 file2 | xurls, as in without distinguishing files?

@mvdan
Copy link
Owner

mvdan commented May 24, 2015

Also, of course the tool hanging when given an argument is a bug :)

@bep
Copy link
Author

bep commented May 24, 2015

Most (all?) of the *nix tools in the GNU Utils package that works on text works on files + stdin, cat, grep, more, less, tail ... So it's common. So common it was the first my fingers tried.

Ideally it should work like cat does, so xurls file1 file2 xurls *.txt etc should work (maybe spin up some Go routines to make it snappier).

@mvdan mvdan closed this as completed in 99bef8b May 24, 2015
@mvdan
Copy link
Owner

mvdan commented May 24, 2015

Done. I've followed the pattern that cat uses, explained in the commit for future reference.

@mvdan
Copy link
Owner

mvdan commented May 25, 2015

I just noticed your mentioning of goroutines. For multiple files it could be used. They are cheap so that shouldn't be a problem, and it could indeed speed things up for large files or async I/O.

The only disadvantage I can think of is that the urls will no longer be output in the correct order like cat prints the lines in order, even though at no point we say we're doing them in order.

@bep
Copy link
Author

bep commented May 25, 2015

The go routines would be a nice addon (not important), but is a different issue.

@mvdan
Copy link
Owner

mvdan commented May 25, 2015

Could you please open a separate issue describing it?

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

No branches or pull requests

2 participants