Skip to content

Commit

Permalink
shadow: add support for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
xhd2015 committed Jul 6, 2024
1 parent 53e47a0 commit 84c0399
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 20 deletions.
22 changes: 22 additions & 0 deletions cmd/xgo/shadow/exclude_path.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import (
"fmt"
)

func excludeInList(dir string, path string, list []string) ([]string, error) {
n := len(list)
j := 0
for i := 0; i < n; i++ {
d := list[i]
if d == dir {
continue
}
list[j] = d
j++
}
if j == n {
return nil, fmt.Errorf("xgo shadow not found in PATH: %s", path)
}
return list[:j], nil
}
20 changes: 5 additions & 15 deletions cmd/xgo/shadow/prepare_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,20 @@
package main

import (
"fmt"
"os"
"path/filepath"
"strings"
)

func exclude(dir string) (func(), error) {
path := os.Getenv("PATH")

list := filepath.SplitList(path)
n := len(list)
j := 0
for i := 0; i < n; i++ {
d := list[i]
if d == dir {
continue
}
list[j] = d
j++
}
if j == n {
return nil, fmt.Errorf("xgo shadow not found in PATH: %s", dir)

newList, err := excludeInList(dir, path, list)
if err != nil {
return nil, err
}
os.Setenv("PATH", strings.Join(list[:j], string(filepath.ListSeparator)))
os.Setenv("PATH", strings.Join(newList, string(filepath.ListSeparator)))
return func() {
os.Setenv("PATH", path)
}, nil
Expand Down
19 changes: 16 additions & 3 deletions cmd/xgo/shadow/prepare_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,24 @@
package main

import (
"fmt"
"os"
"path/filepath"
"strings"
)

var xgo_shadow int = "not support windows yet"
// test on powershell:
// $env:path="C:\Users\xhd2015\.xgo\shadow;"+$env:path

func exclude(dir string) (func(), error) {
return nil, fmt.Errorf("windows not supported")
path := os.Getenv("path")
list := filepath.SplitList(path)

newList, err := excludeInList(dir, path, list)
if err != nil {
return nil, err
}
os.Setenv("path", strings.Join(newList, string(filepath.ListSeparator)))
return func() {
os.Setenv("path", path)
}, nil
}
4 changes: 2 additions & 2 deletions cmd/xgo/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import "fmt"

// auto updated
const VERSION = "1.0.44"
const REVISION = "5a3329d7a88d9360bd34c434b2a4902fa302fdce+1"
const NUMBER = 288
const REVISION = "53e47a022cd9314ede199ca6b70066352c6cec0f+1"
const NUMBER = 289

// manually updated
const CORE_VERSION = "1.0.43"
Expand Down

0 comments on commit 84c0399

Please sign in to comment.