Skip to content

Commit

Permalink
atlasexec: expose exit code (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
masseelch authored May 6, 2024
1 parent 560253a commit 7b55c90
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion atlasexec/atlas.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ func (c *Client) SchemaInspect(ctx context.Context, params *SchemaInspectParams)
args = append(args, "--dev-url", params.DevURL)
}
switch {
case params.Format == "sql":
case params.Format == "sql":
args = append(args, "--format", "{{ sql . }}")
case params.Format != "":
args = append(args, "--format", params.Format)
Expand Down Expand Up @@ -650,6 +650,14 @@ func (e *Error) Error() string {
return e.Stdout
}

// ExitCode returns the exit code of the command.
func (e *Error) ExitCode() int {
if e.err == nil {
return new(exec.ExitError).ExitCode()
}
return e.err.ExitCode()
}

func (e *Error) Unwrap() error {
return e.err
}
Expand Down
7 changes: 7 additions & 0 deletions atlasexec/atlas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ import (
"github.com/stretchr/testify/require"
)

func TestError(t *testing.T) {
err := atlasexec.Error{}
require.NotPanics(t, func() {
err.ExitCode()
})
}

func Test_NewClient(t *testing.T) {
execPath, err := exec.LookPath("atlas")
require.NoError(t, err)
Expand Down

0 comments on commit 7b55c90

Please sign in to comment.