8000 Allow standard input too · Issue #5 · mvdan/gogrep · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Jun 9, 2021. It is now read-only.

Allow standard input too #5

Open
rogpeppe opened this issue Sep 18, 2017 · 4 comments
Open

Allow standard input too #5

rogpeppe opened this issue Sep 18, 2017 · 4 comments

Comments

@rogpeppe
Copy link
Collaborator

Sometimes it's useful to be able to search an arbitrary
portion of a Go program (for example to see where any
identifiers named "a" are within a given function).
It would be nice if gogrep could do this.

@mvdan
Copy link
Owner
mvdan commented Sep 18, 2017

This occurred to me too, but I'm not sure how to go about it. The tool uses gotool, which means that any arguments are taken as either package paths, directories or Go files making up a single package.

And, when you don't give any arguments, . is assumed.

On the other hand, grep tools tend to understand no arguments as standard input. Should we do the same? Or did you have another way of specifying stdin in mind?

We could always go with the slightly hacky - argument meaning stdin.

I'm also not clear on how we could support arbitrary portions of Go code. Surely those can't always type-check properly. Are you saying that we would ignore typechecking in that scenario?

@rogpeppe
Copy link
Collaborator Author

Yeah, maybe gogrep -i to use stdin? I'm not generally keen on abusing - to mean stdin, although the probability of collision is pretty low here.

As for type checking, I'd drop typechecking when reading stdin unless the input represents a complete Go package file. It could print an error if a type was specified in the pattern.

@mvdan
Copy link
Owner
mvdan commented Sep 18, 2017

Well, - is neither a valid Go package name nor a valid Go source file name, so I'd think it's a better option than adding a flag. I dislike that strategy when a - argument could be valid, such as when one does cat - expecting to print the file named -.

Dropping typechecking sounds like something we have to do one way or another. For example, typechecking a single file out of an entire package could very easily not typecheck. I'll open a separate issue.

@mvdan
Copy link
Owner
mvdan commented Sep 19, 2017

@rogpeppe feel free to work on this if you'd like, since I have little use for partial source code parsing (I assume you do because of Acme).

parse.go already has the code you need, and quite funnily it's a more powerful version of what gofmt uses when reading stdin. gofmt allows files, top-level declarations and statements, while we allow those as well as value and type expressions.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0