MCPcopy
hub / github.com/d4l3k/go-pry

github.com/d4l3k/go-pry @main sqlite

repository ↗ · DeepWiki ↗
232 symbols 1,012 edges 44 files 65 documented · 28%
README

go-pry

go-pry - an interactive REPL for Go that allows you to drop into your code at any point.

Tests GoDoc

go-pry

Example

go-pry Animated Example go-pry Example

Usage

Install go-pry

go get github.com/d4l3k/go-pry
go install -i github.com/d4l3k/go-pry

Add the pry statement to the code

package main

import "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.

# Run
go-pry run readme.go

If you want completions to work properly, also install gocode if it is not installed in your system

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 .<filename>.gopry and modifies the <filename>.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 for Ruby.

License

go-pry is licensed under the MIT license.

Made by Tristan Rice.

Extension points exported contracts — how you extend this code

Core symbols most depended-on inside this repo

Error
called by 86
pry/helpers.go
NewScope
called by 73
pry/interpreter.go
InterpretString
called by 73
pry/interpreter.go
Set
called by 37
pry/interpreter.go
Len
called by 16
pry/io_default.go
NewChild
called by 13
pry/interpreter.go
Close
called by 12
pry/pry.go
Pry
called by 11
pry/pry.go

Shape

Function 142
Method 69
Struct 17
Interface 3
FuncType 1

Languages

Go100%

Modules by API surface

pry/interpreter_test.go72 symbols
pry/interpreter.go23 symbols
generate/generate.go20 symbols
pry/pry_test.go13 symbols
pry/pry.go9 symbols
pry/tty_js.go8 symbols
pry/suggestions.go7 symbols
pry/io_js.go7 symbols
pry/io_default.go6 symbols
pry/helpers.go6 symbols
pry/importer_default.go5 symbols
playground/server/server.go5 symbols

Dependencies from manifests, versioned

github.com/cenkalti/backoffv2.2.1+incompatible · 1×
github.com/davecgh/go-spewv1.1.1 · 1×
github.com/gorilla/handlersv1.5.1 · 1×
github.com/mattn/go-colorablev0.1.8 · 1×
github.com/mattn/go-ttyv0.0.3 · 1×
github.com/mgutz/ansiv0.0.0-2020070608092 · 1×
github.com/mitchellh/go-homedirv1.1.0 · 1×
golang.org/x/toolsv0.1.5 · 1×
nprogress0.2.0 · 1×
xterm3.8.1 · 1×

For agents

$ claude mcp add go-pry \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact