github.com/Racer159/jackal@v0.32.7-0.20240401174413-0bd2339e4f2e/src/cmd/common/utils.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // SPDX-FileCopyrightText: 2021-Present The Jackal Authors 3 4 // Package common handles command configuration across all commands 5 package common 6 7 import ( 8 "os" 9 "os/signal" 10 "syscall" 11 12 "github.com/Racer159/jackal/src/config/lang" 13 "github.com/Racer159/jackal/src/pkg/message" 14 ) 15 16 // SuppressGlobalInterrupt suppresses the global error on an interrupt 17 var SuppressGlobalInterrupt = false 18 19 // SetBaseDirectory sets the base directory. This is a directory with a jackal.yaml. 20 func SetBaseDirectory(args []string) string { 21 if len(args) > 0 { 22 return args[0] 23 } 24 return "." 25 } 26 27 // ExitOnInterrupt catches an interrupt and exits with fatal error 28 func ExitOnInterrupt() { 29 c := make(chan os.Signal, 1) 30 signal.Notify(c, os.Interrupt, syscall.SIGTERM) 31 go func() { 32 <-c 33 if !SuppressGlobalInterrupt { 34 message.Fatal(lang.ErrInterrupt, lang.ErrInterrupt.Error()) 35 } 36 }() 37 }