Skip to content

Commit

Permalink
Add batch file support (for working on windows)
Browse files Browse the repository at this point in the history
  • Loading branch information
3846masa committed Jan 31, 2017
1 parent 926f422 commit aba79b0
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/ioutil"
"os"
"path"
"runtime"
"strings"

"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -36,6 +37,15 @@ func (pm *PackageManager) Install(pkg *Package) error {
}

d = append([]byte("#!/usr/bin/env whalebrew\n"), d...)

if runtime.GOOS == "windows" {
batch := []byte("@whalebrew %~dp0\\" + pkg.Name + " %*")
batchPath := packagePath + ".bat"
if err := ioutil.WriteFile(batchPath, batch, 0755); err != nil {
return err
}
}

return ioutil.WriteFile(packagePath, d, 0755)
}

Expand Down Expand Up @@ -89,6 +99,14 @@ func (pm *PackageManager) Uninstall(packageName string) error {
if !isPackage {
return fmt.Errorf("%s is not a Whalebrew package", p)
}
if runtime.GOOS == "windows" {
batchPath := p + ".bat"
if _, err := os.Stat(batchPath); err == nil {
if err := os.Remove(batchPath); err != nil {
return err
}
}
}
return os.Remove(p)
}

Expand Down

0 comments on commit aba79b0

Please sign in to comment.