Skip to content

Commit

Permalink
feature:colorized outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
miaotiao committed Jan 22, 2022
1 parent 31e5fc6 commit 0dadded
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
3 changes: 2 additions & 1 deletion common.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ func WinExec(name string, arg ...string) (string, error) {
return string(output), err
}

func CurrentPath() string {
// InstallPath get install path
func InstallPath() string {
ex, err := os.Executable()
if err != nil {
panic(err)
Expand Down
23 changes: 14 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
var PhpMap map[string]string

const (
PvmVersion = "0.0.1"
PvmVersion = "0.0.2"
)

func main() {
Expand Down Expand Up @@ -45,8 +45,8 @@ func getPhpMap() map[string]string {

PhpMap = make(map[string]string)
// 获取文件内容
if !FileExists("./php.txt") {
err := php2go.FilePutContents("./php.txt", "", 0777)
if !FileExists(confPath()) {
err := php2go.FilePutContents(confPath(), "", 0777)
if err != nil {
fmt.Println(err.Error())
return nil
Expand All @@ -64,14 +64,14 @@ func getPhpMap() map[string]string {
return nil
}

err = php2go.FilePutContents("./php.txt", currentPhpVersion+" "+phpPath, 0777)
err = php2go.FilePutContents(confPath(), currentPhpVersion+" "+phpPath, 0777)
if err != nil {
color.Red(err.Error())
return nil
}
}

raw, err := ioutil.ReadFile("./php.txt")
raw, err := ioutil.ReadFile(confPath())
if err != nil {
color.Red("php.txt can't read")
return nil
Expand Down Expand Up @@ -118,12 +118,17 @@ func lsPhp() {
}

// 将新的 phpMap 写入 php.txt 中
err := php2go.FilePutContents("./php.txt", newPhpString, 0777)
err := php2go.FilePutContents(confPath(), newPhpString, 0777)
if err != nil {
color.Red(err.Error())
}
}

// confPath conf file path
func confPath() string {
return InstallPath() + "/php.txt"
}

func addPhp(pPath string) {
phpExePath := pPath + "/php.exe"
if !FileExists(phpExePath) {
Expand All @@ -149,7 +154,7 @@ func addPhp(pPath string) {
}
}
newPhpString += phpVersion + " " + pPath + "\r\n"
err = php2go.FilePutContents("./php.txt", newPhpString, 0777)
err = php2go.FilePutContents(confPath(), newPhpString, 0777)
if err != nil {
color.Red(err.Error())
}
Expand Down Expand Up @@ -182,9 +187,9 @@ func usePhp(key string) {

func addSelfPath() {
// todo 判断是否已经加入
currentPath := CurrentPath()
InstallPath := InstallPath()
// 将当前目录加入到运行环境中
err := addToEnv(currentPath)
err := addToEnv(InstallPath)
if err != nil {
color.Red(err.Error())
}
Expand Down

0 comments on commit 0dadded

Please sign in to comment.