diff --git a/cmd/sips/sips.go b/cmd/sips/sips.go index 5b99d03..45145f9 100644 --- a/cmd/sips/sips.go +++ b/cmd/sips/sips.go @@ -92,7 +92,7 @@ func run(ctx context.Context) error { } func main() { - ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) + ctx, cancel := signal.NotifyContext(context.Background(), cli.Signals...) defer cancel() err := run(ctx) diff --git a/cmd/sipsctl/sipsctl.go b/cmd/sipsctl/sipsctl.go index c24f5ef..c3aada4 100644 --- a/cmd/sipsctl/sipsctl.go +++ b/cmd/sipsctl/sipsctl.go @@ -3,15 +3,15 @@ package main import ( "context" - "os" "os/signal" "github.com/DeedleFake/sips/cmd/sipsctl/cmd" + "github.com/DeedleFake/sips/internal/cli" "github.com/DeedleFake/sips/internal/log" ) func main() { - ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) + ctx, cancel := signal.NotifyContext(context.Background(), cli.Signals...) defer cancel() err := cmd.ExecuteContext(ctx) diff --git a/internal/cli/cli_posix.go b/internal/cli/cli_posix.go new file mode 100644 index 0000000..92804b7 --- /dev/null +++ b/internal/cli/cli_posix.go @@ -0,0 +1,14 @@ +// +build linux unix darwin netbsd openbsd freebsd + +package cli + +import ( + "os" + + "golang.org/x/sys/unix" +) + +var Signals = []os.Signal{ + os.Interrupt, + unix.SIGTERM, +} diff --git a/internal/cli/cli_windows.go b/internal/cli/cli_windows.go new file mode 100644 index 0000000..33ba85e --- /dev/null +++ b/internal/cli/cli_windows.go @@ -0,0 +1,12 @@ +package cli + +import ( + "os" + + "golang.org/x/sys/windows" +) + +var Signals = []os.Signal{ + os.Interrupt, + windows.SIGTERM, +}