Yet another Go REPL that works nicely. Featured with line editing, code completion, and more.

gore CI Status

Yet another Go REPL that works nicely. Featured with line editing, code completion, and more.

Screencast

(Screencast taken with cho45/KeyCast)

Usage

gore

After a prompt is shown, enter any Go expressions/statements/functions or commands described below.

To quit the session, type Ctrl-D or use :q command.

Features

  • Line editing with history
  • Multi-line input
  • Package importing with completion
  • Evaluates any expressions, statements and function declarations
  • No "evaluated but not used" errors
  • Code completion (requires gocode)
  • Showing documents
  • Auto-importing (gore -autoimport)

REPL Commands

Some functionalities are provided as commands in the REPL:

:import <package path>  Import package
:type <expr>            Print the type of expression
:print                  Show current source
:write [<filename>]     Write out current source to file
:clear                  Clear the codes
:doc <expr or pkg>      Show document
:help                   List commands
:quit                   Quit the session

Supported Versions

Only the latest major version.

Installation

The gore command requires Go tool-chains on runtime, so standalone binary is not distributed.

go get github.com/motemen/gore/cmd/gore

Make sure $GOPATH/bin is in your $PATH.

Also recommended:

go get github.com/mdempsky/gocode   # for code completion

Or you can use Docker:

git clone https://github.com/motemen/gore.git
cd gore
docker build -t gore .
docker run -it --rm gore

FAQ/Caveats

  • gore runs code using go run for each input. All the inputted lines are evaluated again and again so you can't bind the evaluated time by time.Now(), for example. If you don't like this behavior, you may want to use yaegi.
  • gore support Go modules. You can load local modules when you start gore at the project directory. You don't need to go get to check the usage of a remote repository, :import github.com/... will automatically download that module. Also, you don't need to go get the pretty print module anymore. If you want to load a local code from $GOPATH, you need to create the modules file (go mod init ...) and then start gore at the project directory.

License

The MIT License.

Author

motemen <[email protected]>

Owner
Comments
  • Cannot run `gore`

    Cannot run `gore`

    $ gore
    gore: could not load 'fmt' package: err: exit status 1: stderr: build flag -mod=mod only valid when using modules
    
    

    I have GOPATH and GOROOT set up correctly and it is reflected in go env

  • gore can't import vendored packages

    gore can't import vendored packages

    I'm trying to import a package inside a vendor subdirectory in my project. I get the following when importing directly:

    gore> :import github.com/aws/aws-sdk-go
    error: import: can't find import: vendor/github.com/aws/aws-sdk-go
    

    I tried working around it by treating my vendor directory as a temporary GOPATH, and it worked:

    ln -s $PWD/vendor /tmp/go/src
    GOPATH=/tmp/go go install github.com/aws/aws-sdk-go
    GOPATH=/tmp/go gore
    gore> :import github.com/aws/aws-sdk-go
    (no error)
    

    This isn't really a workable solution though. Is there a way for gore to find these packages? I know they have to be go install'ed first - maybe that's part of the issue?

  • astutil gone, cannot build

    astutil gone, cannot build

    Same issues with https://github.com/vektra/mockery/issues/6

    commands.go:17:2: cannot find package "golang.org/x/tools/go/ast/astutil" in any of:
            /usr/lib/go/src/golang.org/x/tools/go/ast/astutil (from $GOROOT)
            /home/asd/Dropbox/go/src/golang.org/x/tools/go/ast/astutil (from $GOPATH)
    
  • Failure with 'malformed module path

    Failure with 'malformed module path "XXX": missing dot in first path element'

    I have a config module available on GOPATH. I verify this by running the following program:

    package main
    
    import (
        "config"
        "fmt"
    )
    
    func main() {
        _ = config.NewConfig()
        fmt.Printf("OK\n")
    }
    
    

    When run, this prints as expected:

    $ go run main.go
    OK
    

    However, with gore, I get an error:

    $ gore
    gore version 0.5.0  :help for help
    gore> :import config
    gore> :import fmt
    gore> _ = config.NewConfig()
    cannot load config: malformed module path "config": missing dot in first path element
    gore> fmt.Printf("OK\n")
    cannot load config: malformed module path "config": missing dot in first path element
    gore> :print
    package main
    
    import (
        "github.com/k0kubun/pp"
        "fmt"
        "config"
    )
    
    func __gore_p(xs ...interface{}) {
        for _, x := range xs {
            pp.Println(x)
        }
    }
    func main() { _ = config.NewConfig(); _, _ = fmt.Printf("OK\n") }
    
    gore> 
    

    Am I doing something wrong? I just updated gore after running into #172 and I've tried updating gore both with GO111MODULE=on and without.

  • gore failed on MacOS 10.15.6 with go 1.15.7

    gore failed on MacOS 10.15.6 with go 1.15.7

    ~ > go version go version go1.15.7 darwin/amd64

    ~ > gore gore: could not load 'fmt' package: err: exit status 1: stderr: build flag -mod=mod only valid when using modules

  • Import packages from external golang source code

    Import packages from external golang source code

    I want to import package from external golang source. This pull request enables that by -include option.

    $ cd $GOPATH/src/github.com/motemen/gore
    $ gore -include main.go
    gore version 0.0.0  :help for help
    gore> homedir.Dir()
    "/Users/tcnksm"
    nil
    gore>
    

    I'm not sure implicit vs. explicit import (cf. https://github.com/motemen/gore/pull/2) But for me, session should be what I expected like ruby's irb.

    This is just proposal.

  • writing a function in gore?

    writing a function in gore?

    I'm sure I'm missing something very obvious but I'm not sure how to write a multi-line function in gore:

    [dtenenba@C02S72TRFVH8 ~]$ gore
    gore version 0.2.6  :help for help
    gore> func Foo() string {
    .....     return "foo"
    ..... }
    .....
    

    How do I get out of ..... land and back to the gore> prompt so I can call my function? Same thing happens if I write the function as a one-liner:

    [dtenenba@C02S72TRFVH8 ~]$ gore
    gore version 0.2.6  :help for help
    gore> func Foo() string { return "foo" }
    .....
    
  • Import fails to find pacakge that exists

    Import fails to find pacakge that exists

    Really loving gore so far, but found an odd bug.

    If I run this command first: go get github.com/leanovate/gopter then try the following gore commands:

    :import github.com/leanovate/gopter (this one works).

    :import github.com/leanovate/gopter/gen This one fails with error: import: can't find import: github.com/leanovate/gopter/prop

    Double checking that it exists:

    $ grep 'package prop' $GOPATH/src/github.com/leanovate/gopter/prop/*
    /Users/ash/code/go/src/github.com/leanovate/gopter/prop/check_condition_func.go:package prop
    /Users/ash/code/go/src/github.com/leanovate/gopter/prop/check_condition_func_test.go:package prop
    /Users/ash/code/go/src/github.com/leanovate/gopter/prop/convert_result.go:package prop
    

    Have I done something stupid? Is this a bug in gopter? I got the package name from the Invalidconcat example here: https://godoc.org/github.com/leanovate/gopter/prop#example-package--Invalidconcat

  • String length error

    String length error

    Note that I entered a } after if i == 5 { break } but for some reason that's not shown in the output.

    $ gore -autoimport
    gore version 0.2.5  :help for help
    gore> for i := 0; i < 50000; i++ {
    .....     if err := exec.Command("./myscript", fmt.Sprintf("name+%[email protected]", i), fmt.Sprintf("password-%v, i), fmt.Sprintf("first-%v", i), fmt.Sprintf("last-%v", i)).Run(); err != nil {
    .....     fmt.Println("Error: %v: %v", i, err)
    ..... }
    ..... if i == 5 { break }
    panic: runtime error: makeslice: len out of range
    
    goroutine 1 [running]:
    strings.Repeat(0x35e968, 0x4, 0xffffffffffffffff, 0x0, 0x0)
        /usr/local/Cellar/go/1.5.1/libexec/src/strings/strings.go:464 +0x5f
    main.(*contLiner).promptString(0x8205f1880, 0x0, 0x0)
        /Users/Me/src/github.com/motemen/gore/liner.go:33 +0x54
    main.(*contLiner).Reindent(0x8205f1880)
        /Users/Me/src/github.com/motemen/gore/liner.go:81 +0xfc
    main.main()
        /Users/Me/src/github.com/motemen/gore/main.go:119 +0xb16
    
    goroutine 5 [syscall]:
    os/signal.loop()
        /usr/local/Cellar/go/1.5.1/libexec/src/os/signal/signal_unix.go:22 +0x18
    created by os/signal.init.1
        /usr/local/Cellar/go/1.5.1/libexec/src/os/signal/signal_unix.go:28 +0x37
    
    goroutine 6 [select, locked to thread]:
    runtime.gopark(0x427130, 0x82061c728, 0x362798, 0x6, 0x3f118, 0x2)
        /usr/local/Cellar/go/1.5.1/libexec/src/runtime/proc.go:185 +0x163
    runtime.selectgoImpl(0x82061c728, 0x0, 0x18)
        /usr/local/Cellar/go/1.5.1/libexec/src/runtime/select.go:392 +0xa64
    runtime.selectgo(0x82061c728)
        /usr/local/Cellar/go/1.5.1/libexec/src/runtime/select.go:212 +0x12
    runtime.ensureSigM.func1()
        /usr/local/Cellar/go/1.5.1/libexec/src/runtime/signal1_unix.go:227 +0x323
    runtime.goexit()
        /usr/local/Cellar/go/1.5.1/libexec/src/runtime/asm_amd64.s:1696 +0x1
    
  • backslashes break gore's scanner

    backslashes break gore's scanner

    gore> h\ello<enter>
    ..... <enter>
    ..... <ctrl-d>
    gore> hello\t<enter>
    ..... <enter>
    ..... <ctrl-d>
    gore> he\\llo<enter>
    ..... <enter>
    .....
    

    Only a couple escape sequences are valid: https://golang.org/ref/spec#Rune_literals

  • Error occurs: `Unexpected package creation during export data loading`

    Error occurs: `Unexpected package creation during export data loading`

    $ gore
    gore version 0.5.0  :help for help
    gore> :import config
    gore> :print
    package main
    
    import (
        "github.com/k0kubun/pp"
        "config"
    )
    
    func __gore_p(xs ...interface{}) {
        for _, x := range xs {
            pp.Println(x)
        }
    }
    func main() {}
    
    gore> cfg := config.NewConfig()
    2020/01/17 18:53:02 Unexpected package creation during export data loading
    

    How can I progress?

  • Printing the values of variables should be optional

    Printing the values of variables should be optional

    If I do at the gore> prompt

    some_var, err := some_func()
    

    the values of some_var and err are always printed. Can this be made optional? If I want to type more than one command when exploring some library, for example, I don't necessarily want to clutter the display with all elements of returned structures. Of course, typing the name of a variable should display the value, as it does currently - it just shouldn't perhaps print automatically on assignments. This is related to #139, I guess.

  • importing database driver

    importing database driver

    gore> :import github.com/lib/pq no errors connect to a postgres database gore> (*errors.errorString)sql: unknown driver "postgres" (forgotten import?)

    How do I import github.com/lib/pq properly? Thank you!

Related tags
Ghdl - A much more convenient way to download GitHub release binaries on the command line, works on Win & Unix-like systems

ghdl Memorize ghdl as github download ghdl is a fast and simple program (and als

Oct 12, 2022
A ready to use Pastebin written in Go Lang, fork the files and start editing/using it.

A ready to use Pastebin written in Go Lang, fork the files and start editing/using it.

Dec 31, 2021
bash completion for go and wgo

Source go-pkg-complete.bash.inc to get tab completion for the go tool. Hitting tab after {go,wgo} will complete to any of the standard go subcommands.

Dec 6, 2022
Go package and associated command line utility to generate random yet human-readable names and identifiers
Go package and associated command line utility to generate random yet human-readable names and identifiers

namegen | What's this? Go package and associated command line utility to generate random yet human-readable names and identifiers. Somewhat inspired b

Oct 19, 2022
Works with HashiCorp HCL. Allows to append the input file with blocks and attributes from the template file

About hclmergetool Works with HashiCorp HCL. Allows to append the input file with blocks and attributes from the template file Installation Binary Rel

Feb 6, 2022
The primary place where Optimism works on stuff related to Optimistic Ethereum
The primary place where Optimism works on stuff related to Optimistic Ethereum

The Optimism Monorepo TL;DR This is the primary place where Optimism works on stuff related to Optimistic Ethereum. Documentation Extensive documentat

Dec 16, 2022
Go-turing-i2c-cmdline - Controlling the i2c management bus of the turing pi with i2c works fine

go-turing-i2c-cmdline What is it? Controlling the i2c management bus of the turi

Jan 24, 2022
Library to work with MimeHeaders and another mime types. Library support wildcards and parameters.

Mime header Motivation This library created to help people to parse media type data, like headers, and store and match it. The main features of the li

Nov 9, 2022
safe and easy casting from one type to another in Go

cast Easy and safe casting from one type to another in Go Don’t Panic! ... Cast What is Cast? Cast is a library to convert between different go types

Jan 7, 2023
The High Code Framework (low-code for devs)

hof - the high code framework The hof tool tries to remove redundent development activities by using high level designs, code generation, and diff3 wh

Dec 24, 2022
🎄 My code for the Advent of Code of year 2021 in Go.

Advent of Code 2021 This repository contains all code that I wrote for the Advent of Code 2021. This year I chose to try and learn Go. Enjoy! Built wi

Dec 9, 2021
Quickly clone an entire org/users repositories into one directory - Supports GitHub, GitLab, Bitbucket, and more
Quickly clone an entire org/users repositories into one directory - Supports GitHub, GitLab, Bitbucket, and more

ghorg ghorg allows you to quickly clone all of an orgs, or users repos into a single directory. This can be useful in many situations including Search

Jan 1, 2023
jacobin - A more than minimal JVM written in Go and capable of running Java 11 bytecode.

This overview gives the background on this project, including its aspirations and the features that it supports. The remaining pages discuss the basics of JVM operation and, where applicable, how Jacobin implements the various steps, noting any items that would be of particular interest to JVM cognoscenti.

Dec 29, 2022
Heat, heat and more heat!
Heat, heat and more heat!

Load Operator The intention of this project is to escape from the bad weather during the winter season. ;) Instead of getting wet and cold, it is used

Nov 15, 2021
A patcher for the MS-DOS version of Fallout 1 including Crafty's sFall1 patches and maybe more

A patcher for the MS-DOS version of Fallout 1 including Crafty's sFall1 patches and maybe more

Oct 13, 2022
Clockwise is a meeting cost calculator designed to encourage more efficient meetings.
Clockwise is a meeting cost calculator designed to encourage more efficient meetings.

↻lockwise Clockwise is a meeting cost calculator designed to encourage more efficient meetings. The meetings will continue until morale improves.

Oct 25, 2022
XSD (XML Schema Definition) parser and Go/C/Java/Rust/TypeScript code generator

xgen Introduction xgen is a library written in pure Go providing a set of functions that allow you to parse XSD (XML schema definition) files. This li

Jan 1, 2023
Visualize how a projects source code is distributed among its files and folders
Visualize how a projects source code is distributed among its files and folders

Source Code Visualizer Visualize the code distribution in a project. Applications Applications include: Visualizing code distribution for more educate

Jul 31, 2022
Advent of Code is an Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like.

Advent of Code 2021 Advent of Code is an Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved

Dec 2, 2021