Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
amirrezaask committed Oct 19, 2019
1 parent a0bfbbd commit 0ac7c3e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 43 deletions.
82 changes: 41 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Build Status](https://travis-ci.org/golobby/gshell.png?branch=master)](https://travis-ci.org/golobby/gshell)
[![Coverage State](https://coveralls.io/repos/github/golobby/gshell/badge.png?branch=master)](https://coveralls.io/github/golobby/gshell)
# gshell
[![Build Status](https://travis-ci.org/golobby/repl.png?branch=master)](https://travis-ci.org/golobby/repl)
[![Coverage State](https://coveralls.io/repos/github/golobby/repl/badge.png?branch=master)](https://coveralls.io/github/golobby/repl)
# repl
## Getting Started

### Requirements
Expand All @@ -11,106 +11,106 @@
go get golang.org/x/tools/cmd/goimports
```

## Installing gshell
## Installing repl
```bash
go get github.com/golobby/gshell
go install github.com/golobby/gshell
go get github.com/golobby/repl
go install github.com/golobby/repl
```
####
## Why
gshell is a REPL, Read-Eval-Print-Loop. In scripting languages like PHP or Python there is an environment called gshell, which is
repl is a REPL, Read-Eval-Print-Loop. In scripting languages like PHP or Python there is an environment called repl, which is
basically a command line interface that is connected to the language interpreter and it would show instantly the result of
user input. In Golang we don't have this feature by default but it does'nt mean that we cannot benefit the power that gshell gives
user input. In Golang we don't have this feature by default but it does'nt mean that we cannot benefit the power that repl gives
us.

## How
gshell parses the input and put the code you entered in one of these categories:
repl parses the input and put the code you entered in one of these categories:
- Imports
- Var declaration/assignment
- type definition
- function definition
- function calls

then gshell creates a file from state of the session running.
then repl creates a file from state of the session running.

#### gshell Pipeline
`gshell Prompt -> goimports -> go compiler -> shows result of compile`
#### repl Pipeline
`repl Prompt -> goimports -> go compiler -> shows result of compile`

## Features

### Global Access to vars
In a gshell you need to have access to the vars defined no matter what scope you are in, gshell provides this feature by
In a repl you need to have access to the vars defined no matter what scope you are in, repl provides this feature by
defining all vars in a global scope.
```go
gshell> func someFunc() string {
...gshell> return fmt.Sprint(a)
...gshell> }
gshell> a = 2
gshell> someFunc() // 2
repl> func someFunc() string {
...repl> return fmt.Sprint(a)
...repl> }
repl> a = 2
repl> someFunc() // 2
```

### Variable Redefine/assignment
gshell does not care about either type or value of a variable, so you can redefine or change type of variable with ease.
repl does not care about either type or value of a variable, so you can redefine or change type of variable with ease.
```go
gshell> x := 3
gshell> x := "amirreza"
gshell> x := someType{}
gshell> var x = 5
// all above codes are valid in a gshell interpreter
repl> x := 3
repl> x := "amirreza"
repl> x := someType{}
repl> var x = 5
// all above codes are valid in a repl interpreter
```

### Instant Expression Evaluation
gshell can easily evaluate any valid Go expression.
repl can easily evaluate any valid Go expression.
```go
gshell> 2 // <int> 2
gshell> 2*3*(2+1) // <int> 18
gshell> "Hello World" // <string> "Hello World"
repl> 2 // <int> 2
repl> 2*3*(2+1) // <int> 18
repl> "Hello World" // <string> "Hello World"
```

### Automated Imports
gshell uses the power of goimports so it can almost identify all packages you use and automatically import them for you.
repl uses the power of goimports so it can almost identify all packages you use and automatically import them for you.
```go
gshell> fmt.Println("Hello") // no need for manual import, goimports will take care of that
repl> fmt.Println("Hello") // no need for manual import, goimports will take care of that
```

### Helpful Error Messages
gshell does not suppress any error message so you can see exact error message from go toolchain
repl does not suppress any error message so you can see exact error message from go toolchain

### Go module discovery
gshell build from ground up to be compatible with go modules, so when you fire up a gshell in go project which is a go module project
gshell instantly identifies your module and imports it as a module with local path, so you can access all your public
repl build from ground up to be compatible with go modules, so when you fire up a repl in go project which is a go module project
repl instantly identifies your module and imports it as a module with local path, so you can access all your public
types and functions.(watch Demo)

### Shell Commands

#### Go Doc
go doc is available as a shell command so you can access any document about any package with gshell.
go doc is available as a shell command so you can access any document about any package with repl.
```go
gshell> :doc fmt
gshell> :doc json.Marshal
repl> :doc fmt
repl> :doc json.Marshal
```
#### Eval
```go
gshell> :e 1+2
repl> :e 1+2
// <int> 3
gshell> :e "HelloWorld"
repl> :e "HelloWorld"
// <string> "HelloWorld"
```
#### Dump
shows formatted view of current session state.
```go
gshell> :dump
repl> :dump
```
#### Pop
pops latest entered code from session.
```go
gshell> :pop
repl> :pop
```

#### file
file shows exactly code that will be generated from current state of session.
```go
gshell> :file
repl> :file
```
## Demo
[![asciicast](https://asciinema.org/a/273628.svg)](https://asciinema.org/a/273628)
Expand Down
2 changes: 1 addition & 1 deletion interpreter/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (s *Interpreter) Eval(code string) (string, error) {

// used as value
func createTmpDir(workingDirectory string) (string, error) {
sessionDir := workingDirectory + "/.gshell/sessions/" + fmt.Sprint(time.Now().Nanosecond())
sessionDir := workingDirectory + "/.repl/sessions/" + fmt.Sprint(time.Now().Nanosecond())
err := os.MkdirAll(sessionDir, 500)
if err != nil {
return sessionDir, err
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ func main() {
}
fmt.Printf("gshell v%s\n", version)

p := prompt.New(handler, completer, prompt.OptionPrefix("gshell> "))
p := prompt.New(handler, completer, prompt.OptionPrefix("repl> "))
p.Run()
}

0 comments on commit 0ac7c3e

Please sign in to comment.