gore

package module
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 9, 2021 License: MIT Imports: 35 Imported by: 0

README

gore CI Status

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 <motemen@gmail.com>

Documentation

Index

Constants

View Source
const Version = "0.5.2"

Version of gore.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error string

Error ...

const (
	ErrContinue Error = "<continue input>"
	ErrQuit     Error = "<quit session>"
	ErrCmdRun   Error = "<command failed>"
)

Errors

func (Error) Error

func (e Error) Error() string

type Gore added in v0.4.1

type Gore struct {
	// contains filtered or unexported fields
}

Gore ...

func New added in v0.4.1

func New(opts ...Option) *Gore

New Gore

func (*Gore) Run added in v0.4.1

func (g *Gore) Run() error

Run ...

type Option added in v0.4.1

type Option func(*Gore)

Option for Gore

func AutoImport added in v0.4.1

func AutoImport(autoImport bool) Option

AutoImport option

func ErrWriter added in v0.4.1

func ErrWriter(errWriter io.Writer) Option

ErrWriter option

func ExtFiles added in v0.4.1

func ExtFiles(extFiles string) Option

ExtFiles option

func OutWriter added in v0.4.1

func OutWriter(outWriter io.Writer) Option

OutWriter option

func PackageName added in v0.4.1

func PackageName(packageName string) Option

PackageName option

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session ...

func NewSession

func NewSession(stdout, stderr io.Writer) (*Session, error)

NewSession creates a new Session.

func (*Session) Clear added in v0.4.0

func (s *Session) Clear() error

Clear the temporary directory.

func (*Session) Eval

func (s *Session) Eval(in string) error

Eval the input.

func (*Session) Run

func (s *Session) Run() error

Run the session.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL