Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/d4l3k/go-pry
An interactive REPL for Go that allows you to drop into your code at any point.
https://github.com/d4l3k/go-pry
go interpreter repl
Last synced: 18 days ago
JSON representation
An interactive REPL for Go that allows you to drop into your code at any point.
- Host: GitHub
- URL: https://github.com/d4l3k/go-pry
- Owner: d4l3k
- License: mit
- Created: 2015-03-05T00:10:14.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-02-21T05:42:01.000Z (over 1 year ago)
- Last Synced: 2024-10-04T09:50:56.910Z (about 1 month ago)
- Topics: go, interpreter, repl
- Language: Go
- Homepage: https://gopry.rice.sh/
- Size: 243 KB
- Stars: 3,000
- Watchers: 36
- Forks: 64
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- go-awesome - go-pry - Interactively type and run Go code in terminal like Python, R, PHP, etc (Open source library / Runner)
- awesome-golang-repositories - go-pry
README
# go-pry
go-pry - an interactive REPL for Go that allows you to drop into your code at any point.
![Tests](https://github.com/d4l3k/go-pry/actions/workflows/unittest.yml/badge.svg)
[![GoDoc](https://godoc.org/github.com/d4l3k/go-pry/pry?status.svg)](https://godoc.org/github.com/d4l3k/go-pry/pry)![go-pry](https://i.imgur.com/yr1BEsK.png)
Example
![go-pry Animated Example](https://i.imgur.com/H8hFzPV.gif)
![go-pry Example](https://i.imgur.com/0rmwVY7.png)## Usage
Install go-pry
```bash
go get github.com/d4l3k/go-pry
go install -i github.com/d4l3k/go-pry```
Add the pry statement to the code
```go
package mainimport "github.com/d4l3k/go-pry/pry"
func main() {
a := 1
pry.Pry()
}
```Run the code as you would normally with the `go` command. go-pry is just a wrapper.
```bash
# Run
go-pry run readme.go
```If you want completions to work properly, also install `gocode` if it
is not installed in your system```bash
go get -u github.com/nsf/gocode
```## How does it work?
go-pry is built using a combination of meta programming as well as a massive amount of reflection. When you invoke the go-pry command it looks at the Go files in the mentioned directories (or the current in cases such as `go-pry build`) and processes them. Since Go is a compiled language there's no way to dynamically get in scope variables, and even if there was, unused imports would be automatically removed for optimization purposes. Thus, go-pry has to find every instance of `pry.Pry()` and inject a large blob of code that contains references to all in scope variables and functions as well as those of the imported packages. When doing this it makes a copy of your file to `..gopry` and modifies the `.go` then passes the command arguments to the standard `go` command. Once the command exits, it restores the files.If the program unexpectedly fails there is a custom command `go-pry restore [files]` that will move the files back. An alternative is to just remove the `pry.Apply(...)` line.
## Inspiration
go-pry is greatly inspired by [Pry REPL](http://pryrepl.org) for Ruby.
## License
go-pry is licensed under the MIT license.
Made by [Tristan Rice](https://fn.lc).