Skip to content

Commit

Permalink
new version
Browse files Browse the repository at this point in the history
  • Loading branch information
wxnacy committed Mar 23, 2019
1 parent 6ee2c3c commit 6105607
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 15 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,11 @@ $ go get -u github.com/mdempsky/gocode
现在的代码补全功能,如果当行代码比较复杂,需要在想要补全的报名前加一个空格,这不影响代码输出,只是稍微有点别扭,比如:

![wgo1](wgo1.gif)

## 更新日志

### 1.0.3
- 修复没有安装 `gocode` 报错的 bug
- 增加 `var x = 1` 表达式的运行
- 增加运行时的版本信息
- 修改导入包异常的 bug
14 changes: 4 additions & 10 deletions code.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ func (this *Code) Format() string {
this.clear()
var isLastInput bool
var mainString = strings.Join(this.mainFunc, "\n")
mainString = "\n" + mainString
mainString += this.lastInput
this.codes = append(this.codes, "package main")
if !isLastInput && strings.HasPrefix(this.lastInput, "import") {
Expand All @@ -191,7 +192,9 @@ func (this *Code) Format() string {
ims := strings.Split(d, "/")
importName = ims[len(ims) - 1]
}
if strings.Contains(mainString, importName + ".") {
if strings.Contains(mainString, "(" + importName + ".") ||
strings.Contains(mainString, " " + importName + ".") ||
strings.Contains(mainString, "\n" + importName + ".") {
ifmt = "\t\"%s\""
} else {
ifmt = "\t_ \"%s\""
Expand Down Expand Up @@ -222,13 +225,10 @@ func (this *Code) Run() (string, error){
cmd.Stdout = &out
cmd.Stderr = &outErr
err := cmd.Run()
// this.Print()
// Logger().Debug(this.Format())
if err != nil {
fmt.Println(err)
}
if out.String() != "" {
// Logger().Debug(out.String())
fmt.Println(out.String())
return out.String(), nil
}
Expand All @@ -240,7 +240,6 @@ func (this *Code) Run() (string, error){
return "", errors.New(outErr.String())
} else {
this.input()
// Logger().Debug(out.String())
return "", nil
}
}
Expand All @@ -259,11 +258,6 @@ func initTempDir() {
}
}

// func destroyTempDir() {
// err := os.RemoveAll(tempDir())
// handlerErr(err)
// }

func writeCode(code string) {
initTempDir()
f, err := os.OpenFile(tempFile(), os.O_CREATE|os.O_WRONLY, 0600)
Expand Down
24 changes: 24 additions & 0 deletions commands/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"os/exec"
"bytes"
"strings"
"errors"
)

// Determine if a command exists
Expand All @@ -21,3 +22,26 @@ func HasCommand(name string) (path string, flag bool) {
}
return
}

func Command(name string, args ...string) (string, error) {
c := exec.Command(name, args...)
var out bytes.Buffer
var outErr bytes.Buffer
c.Stdout = &out
c.Stderr = &outErr
err := c.Run()
if err != nil {
return "", err
}
var outStr = out.String()
if outStr != "" {
outStr = strings.Trim(outStr, "\n")
return outStr, nil
}
var outErrStr = outErr.String()
if outErrStr != "" {
outErrStr = strings.Trim(outErrStr, "\n")
return "", errors.New(outErrStr)
}
return "", nil
}
7 changes: 6 additions & 1 deletion common.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ func tempDir() string {

}
tempdir = fmt.Sprintf("%s%s-%d/", tmp, "wgo", time.Now().Unix())
tempdir = fmt.Sprintf("%s%s-%d/", tmp, "wgo", 0)
// tempdir = fmt.Sprintf("%s%s-%d/", tmp, "wgo", 0)
}
return tempdir
}

func destroyTempDir() {
err := os.RemoveAll(tempDir())
handlerErr(err)
}

func tempCompleteFile() string {
if tempCmpltFile == "" {
tempCmpltFile = fmt.Sprintf("%swgo_complete.go", tempDir())
Expand Down
2 changes: 1 addition & 1 deletion install
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ BIN=wgo
PWD=`pwd`
BIN_LINUX=`pwd`/bin/linux_amd64
BIN_DARWIN=`pwd`/bin/darwin_amd64
VER=`cat ./version`

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go install $SOURCE_DIR
# CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go install $SOURCE_DIR
# CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go install $SOURCE_DIR
go install $SOURCE_DIR
VER=`wgo version`

test -d bin || mkdir bin
test -d bin/linux_amd64 || mkdir bin/linux_amd64
Expand Down
3 changes: 1 addition & 2 deletions push_tag
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
# TAG_NAME=$1
# PUSH_MSG=${@/$1/}
./install
TAG_NAME=`cat ./version`
TAG_NAME=`wgo version`
PUSH_MSG=${@}


main(){
git pull origin master
git add .
Expand Down
2 changes: 1 addition & 1 deletion run
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

go install && wgo
go install && wgo $@
38 changes: 38 additions & 0 deletions wgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (

"strings"
"os"
"fmt"
"flag"
)


Expand Down Expand Up @@ -66,13 +68,49 @@ func changeLivePrefix() (string, bool) {
return LivePrefixState.LivePrefix, LivePrefixState.IsEnable
}

var VER = `%s
Wgo version %s
Copyright (C) 2019 wxnacy
`

const (
VERSION = "1.0.3"
)

var args []string
func initArgs() {
flag.Parse()
args = flag.Args()
// fmt.Println(args)
// fmt.Println(os.Args)
}

func commandArgs() {
if len(args) > 0 {
arg := args[0]
switch arg {
case "version": {
fmt.Println(VERSION)
os.Exit(0)
}
}
}
}

func main() {
initArgs()
commandArgs()
initLogger()

goVer, _ := commands.Command("go", "version")

fmt.Println(fmt.Sprintf(VER, goVer, VERSION))
p := prompt.New(
executor,
completer,
prompt.OptionPrefix(">>> "),
prompt.OptionLivePrefix(changeLivePrefix),
)
p.Run()
destroyTempDir()
}

0 comments on commit 6105607

Please sign in to comment.