aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authortsne <tsne.dev@outlook.com>2026-07-06 16:52:20 +0200
committertsne <tsne.dev@outlook.com>2026-07-06 19:21:15 +0200
commit2c41acab4c97f584e8e199b31dc456194b8d7e6c (patch)
tree42381deb6c4f6da0f32945432207a31b4d86664e /cmd
downloadhopper-2c41acab4c97f584e8e199b31dc456194b8d7e6c.tar.gz
initial
Diffstat (limited to 'cmd')
-rw-r--r--cmd/hopper/main.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/cmd/hopper/main.go b/cmd/hopper/main.go
new file mode 100644
index 0000000..cc58d0d
--- /dev/null
+++ b/cmd/hopper/main.go
@@ -0,0 +1,48 @@
+package main
+
+import (
+ "context"
+ "os"
+ "os/signal"
+ "strconv"
+ "sync/atomic"
+ "syscall"
+
+ "tsne.dev/hopper/internal/cli"
+ "tsne.dev/hopper/internal/log"
+)
+
+func main() {
+ log.Init(os.Stdout, os.Stderr)
+
+ sigch := make(chan os.Signal, 1)
+ signal.Notify(sigch, syscall.SIGINT, syscall.SIGTERM)
+
+ ctx, cancel := context.WithCancelCause(context.Background())
+ defer cancel(nil)
+
+ var receivedSignal int64
+ go func() {
+ sig := (<-sigch).(syscall.Signal)
+ atomic.StoreInt64(&receivedSignal, int64(sig))
+
+ var signame string
+ switch sig {
+ case syscall.SIGINT:
+ signame = "SIGINT"
+ case syscall.SIGTERM:
+ signame = "SIGTERM"
+ default:
+ signame = "signal " + strconv.Itoa(int(sig))
+ }
+
+ log.Print("received %s", signame)
+ cancel(cli.CancellationError("operation aborted (" + signame + ")"))
+ }()
+
+ code := cli.Run(ctx, os.Args[1:])
+ if sig := atomic.LoadInt64(&receivedSignal); sig != 0 {
+ code = 128 + int(sig)
+ }
+ os.Exit(code)
+}