feat(cmd): optionally fetch status from =ExitCode

resolves #4478
This commit is contained in:
Jan De Dobbeleer 2023-12-02 11:54:58 +01:00 committed by Jan De Dobbeleer
parent adf8731183
commit 1bdc22bf40

View file

@ -35,6 +35,7 @@ const (
WINDOWS = "windows"
DARWIN = "darwin"
LINUX = "linux"
CMD = "cmd"
)
func pid() string {
@ -628,6 +629,17 @@ func (env *Shell) HasCommand(command string) bool {
func (env *Shell) StatusCodes() (int, string) {
defer env.Trace(time.Now())
if env.CmdFlags.Shell != CMD || env.CmdFlags.ErrorCode == 0 {
return env.CmdFlags.ErrorCode, env.CmdFlags.PipeStatus
}
errorCode := env.Getenv("=ExitCode")
if len(errorCode) > 0 {
env.Debug(errorCode)
env.CmdFlags.ErrorCode, _ = strconv.Atoi(errorCode)
}
return env.CmdFlags.ErrorCode, env.CmdFlags.PipeStatus
}