45 lines
896 B
Go
45 lines
896 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
|
|
"gitea.maximumdirect.net/eric/notarius/internal/cli"
|
|
"go.maximumdirect.net/commandkit"
|
|
"go.maximumdirect.net/releasekit/buildinfo"
|
|
)
|
|
|
|
func main() {
|
|
os.Exit(run())
|
|
}
|
|
|
|
func run() int {
|
|
app, err := cli.NewApplication(buildinfo.Version(), cli.Options{})
|
|
if err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
return 1
|
|
}
|
|
ctx, stop := interruptContext()
|
|
defer stop()
|
|
outcome := app.Execute(ctx, os.Args[1:], commandkit.Streams{Out: os.Stdout, Err: os.Stderr})
|
|
return outcome.Status
|
|
}
|
|
|
|
func interruptContext() (context.Context, func()) {
|
|
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
|
done := make(chan struct{})
|
|
go func() {
|
|
<-ctx.Done()
|
|
// Restore ordinary signal handling while cooperative cleanup runs.
|
|
stop()
|
|
close(done)
|
|
}()
|
|
return ctx, func() {
|
|
stop()
|
|
<-done
|
|
}
|
|
}
|