Skip to content

Commit

Permalink
Windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
alxarch committed Feb 1, 2019
1 parent 1be7614 commit bb32302
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ before:
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- darwin
- windows
- freebsd
archive:
replacements:
darwin: Darwin
Expand Down
17 changes: 17 additions & 0 deletions internal/exit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//+build !windows

package internal

import (
"os/exec"
"syscall"
)

func ExitCode(err error) int {
if err, ok := err.(*exec.ExitError); ok {
if code, ok := err.ProcessState.Sys().(syscall.WaitStatus); ok {
return int(code)
}
}
return 2
}
17 changes: 17 additions & 0 deletions internal/exit_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//+build windows

package internal

import (
"os/exec"
"syscall"
)

func ExitCode(err error) int {
if err, ok := err.(*exec.ExitError); ok {
if status, ok := err.ProcessState.Sys().(syscall.WaitStatus); ok {
return int(status.ExitCode)
}
}
return 2
}
13 changes: 2 additions & 11 deletions yjq.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"os"
"os/exec"
"sync"
"syscall"

"github.com/alxarch/yjq/internal"
"github.com/alxarch/yjq/internal/yjq"
"github.com/spf13/pflag"
)
Expand Down Expand Up @@ -144,17 +144,8 @@ func main() {
}
}

func exitCode(err error) int {
if err, ok := err.(*exec.ExitError); ok {
if code, ok := err.ProcessState.Sys().(syscall.WaitStatus); ok {
return int(code)
}
}
return 2
}

func onExit(err error) {
switch code := exitCode(err); code {
switch code := internal.ExitCode(err); code {
case 2, 3:
logger.Println(err)
fallthrough
Expand Down

2 comments on commit bb32302

@glensc
Copy link

@glensc glensc commented on bb32302 Feb 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pardon me, but aren't exit.go and exit_windows.go here identical?

@alxarch
Copy link
Owner Author

@alxarch alxarch commented on bb32302 Feb 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, on Windows the syscall.WaitStatus is a struct and on Posix it's uint32 hence the need for build tags

Please sign in to comment.