summaryrefslogtreecommitdiff
path: root/exit.go
diff options
context:
space:
mode:
Diffstat (limited to 'exit.go')
-rw-r--r--exit.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/exit.go b/exit.go
index 83f2ddd..9752214 100644
--- a/exit.go
+++ b/exit.go
@@ -6,6 +6,7 @@ import (
"time"
"go.wit.com/lib/cobol"
+ "golang.org/x/term"
)
// since we know when the command starts (duh, this parses os.Args)
@@ -22,6 +23,18 @@ func BadExit(msg string, err error) {
PB.badExit(msg, err)
}
+func isInteractive() {
+ // For os.Stdin, this is typically 0.
+ stdinFd := int(os.Stdin.Fd())
+
+ // IsTerminal() returns true if the given file descriptor is connected to a terminal.
+ if term.IsTerminal(stdinFd) {
+ fmt.Println("Running in an INTERACTIVE terminal.")
+ } else {
+ fmt.Println("Running in a NON-INTERACTIVE environment (pipe, script, etc.).")
+ }
+}
+
func (pb *Argv) goodExit(msg string) {
go ExitWatchdog()
if me.appExit != nil {
@@ -34,6 +47,7 @@ func (pb *Argv) goodExit(msg string) {
} else {
appname = pb.AppInfo.APPNAME
}
+ isInteractive()
fmt.Printf("%s: %s (%s)\n", appname, msg, cobol.FormatDuration(dur))
os.Exit(0)
}
@@ -43,6 +57,7 @@ func (pb *Argv) badExit(msg string, err error) {
if me.appExit != nil {
me.appExit()
}
+ isInteractive()
// print out errors. this handles wrapped errors which is a useful
if err != nil {
if u, ok := err.(interface{ Unwrap() []error }); ok {
@@ -65,7 +80,7 @@ func (pb *Argv) badExit(msg string, err error) {
appname = pb.AppInfo.APPNAME
}
fmt.Printf("%s error: %s (%s)\n", appname, msg, cobol.FormatDuration(dur))
- os.Exit(1)
+ os.Exit(int(ExitPB))
}
// this code doesn't need to be this complicated. I put it here as reference code for myself so I could remember where it is.