GithubHelp home page GithubHelp logo

hhy5277 / go-pry Goto Github PK

View Code? Open in Web Editor NEW

This project forked from d4l3k/go-pry

0.0 3.0 0.0 98 KB

An interactive REPL for Go that allows you to drop into your code at any point.

License: MIT License

Go 100.00%

go-pry's Introduction

go-pry

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

Build Status GoDoc

go-pry

Example

go-pry Animated Example go-pry Example

Usage

Install go-pry

go get github.com/d4l3k/go-pry
go install 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

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.

go-pry's People

Contributors

benhamill avatar d4l3k avatar mattn avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.