-
Notifications
You must be signed in to change notification settings - Fork 176
/
Copy pathutils.go
39 lines (33 loc) · 1.01 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors
// Package common handles command configuration across all commands
package common
import (
"os"
"os/signal"
"syscall"
"github.com/defenseunicorns/zarf/src/config/lang"
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/defenseunicorns/zarf/src/types"
)
// SuppressGlobalInterrupt suppresses the global error on an interrupt
var SuppressGlobalInterrupt = false
// SetBaseDirectory sets base directory on package config when given in args
func SetBaseDirectory(args []string, pkgConfig *types.PackagerConfig) {
if len(args) > 0 {
pkgConfig.CreateOpts.BaseDir = args[0]
} else {
pkgConfig.CreateOpts.BaseDir = "."
}
}
// ExitOnInterrupt catches an interrupt and exits with fatal error
func ExitOnInterrupt() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
if !SuppressGlobalInterrupt {
message.Fatal(lang.ErrInterrupt, lang.ErrInterrupt.Error())
}
}()
}