diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml deleted file mode 100644 index 0457cb1..0000000 --- a/bitbucket-pipelines.yml +++ /dev/null @@ -1,21 +0,0 @@ -image: golang:1.15 - -pipelines: - default: - - parallel: - - step: - name: Test and Build - script: - - go mod vendor - - go mod tidy - - go test -v - - mkdir build - - ./build.sh - - export BUILDPATH="build/$(uname)/gostations" - - curl -X POST --user "${BITBUCKET_USERNAME}:${BITBUCKET_APP_PASSWORD}" "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"${BUILDPATH}" - - - step: - name: Lint code - image: golangci/golangci-lint:v1.31.0 - script: - - golangci-lint run -v diff --git a/commander.go b/commander.go index 9ecc190..9d9b6f6 100644 --- a/commander.go +++ b/commander.go @@ -4,10 +4,21 @@ import ( "fmt" "os" "os/exec" + "runtime" ) func isInstalled(name string) bool { - cmd := exec.Command("/bin/sh", "-c", "command -v " + name) + var cmd *exec.Cmd + + // check for the operating system + if runtime.GOOS == "windows" { + // 'where' command is used on Windows to locate executables + cmd = exec.Command("where.exe", name) + } else { + // 'command' is used on Unix systems + cmd = exec.Command("/bin/sh", "-c", "command -v "+name) + } + if err := cmd.Run(); err != nil { return false } diff --git a/stations.go b/stations.go index 4accb94..2b3dd43 100644 --- a/stations.go +++ b/stations.go @@ -8,27 +8,27 @@ import ( var version string -func showVersion(){ +func showVersion() { fmt.Println(version) } -func precheck(){ - if !isInstalled(player()){ +func precheck() { + if !isInstalled(player()) { fmt.Printf("%s is either not installed, or not on your $PATH. Cannot continue.\n", player()) os.Exit(1) } } -func main(){ +func main() { argCount := len(os.Args[1:]) var ( - name string + name string country string - state string - tags string + state string + tags string notok bool - version bool + version bool ) flag.Usage = func() { fmt.Printf("Usage: \n") @@ -42,7 +42,7 @@ func main(){ flag.StringVar(&country, "c", "", "Home country.") flag.StringVar(&state, "s", "", "Home state (if in the United States).") flag.StringVar(&tags, "t", "", "Tag (or comma-separated tag list)") - flag.BoolVar(¬ok, "x", false,"If toggled, will show stations that are down") + flag.BoolVar(¬ok, "x", false, "If toggled, will show stations that are down") flag.BoolVar(&version, "v", false, "Show version.") flag.Parse() @@ -66,4 +66,4 @@ func main(){ os.Exit(1) } -} \ No newline at end of file +}