aboutsummaryrefslogtreecommitdiffhomepage
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/hakurei/command.go28
-rw-r--r--cmd/hakurei/command_test.go2
-rw-r--r--cmd/hakurei/main.go9
3 files changed, 12 insertions, 27 deletions
diff --git a/cmd/hakurei/command.go b/cmd/hakurei/command.go
index f1032f94..0600a559 100644
--- a/cmd/hakurei/command.go
+++ b/cmd/hakurei/command.go
@@ -6,11 +6,9 @@ import (
"io"
"log"
"os"
- "os/signal"
"os/user"
"strconv"
"sync"
- "syscall"
"time"
"hakurei.app/command"
@@ -25,7 +23,7 @@ import (
"hakurei.app/system/dbus"
)
-func buildCommand(out io.Writer) command.Command {
+func buildCommand(ctx context.Context, out io.Writer) command.Command {
var (
flagVerbose bool
flagJSON bool
@@ -45,7 +43,7 @@ func buildCommand(out io.Writer) command.Command {
config := tryPath(args[0])
config.Args = append(config.Args, args[1:]...)
- runApp(config)
+ app.Main(ctx, std, config)
panic("unreachable")
})
@@ -165,8 +163,7 @@ func buildCommand(out io.Writer) command.Command {
}
}
- // invoke app
- runApp(config)
+ app.Main(ctx, std, config)
panic("unreachable")
}).
Flag(&flagDBusConfigSession, "dbus-config", command.StringFlag("builtin"),
@@ -249,22 +246,3 @@ func buildCommand(out io.Writer) command.Command {
return c
}
-
-func runApp(config *hst.Config) {
- ctx, stop := signal.NotifyContext(context.Background(),
- syscall.SIGINT, syscall.SIGTERM)
- defer stop() // unreachable
- a := app.MustNew(ctx, std)
-
- if sa, err := a.Seal(config); err != nil {
- hlog.BeforeExit()
- if m, ok := container.GetErrorMessage(err); ok {
- log.Fatal(m)
- } else {
- log.Fatalln("cannot seal app:", err)
- }
- } else {
- sa.Main()
- panic("unreachable")
- }
-}
diff --git a/cmd/hakurei/command_test.go b/cmd/hakurei/command_test.go
index dbbcea90..8ce9a23d 100644
--- a/cmd/hakurei/command_test.go
+++ b/cmd/hakurei/command_test.go
@@ -68,7 +68,7 @@ Flags:
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
out := new(bytes.Buffer)
- c := buildCommand(out)
+ c := buildCommand(t.Context(), out)
if err := c.Parse(tc.args); !errors.Is(err, command.ErrHelp) && !errors.Is(err, flag.ErrHelp) {
t.Errorf("Parse: error = %v; want %v",
err, command.ErrHelp)
diff --git a/cmd/hakurei/main.go b/cmd/hakurei/main.go
index a636cfcb..b71f50c8 100644
--- a/cmd/hakurei/main.go
+++ b/cmd/hakurei/main.go
@@ -4,10 +4,13 @@ package main
//go:generate cp ../../LICENSE .
import (
+ "context"
_ "embed"
"errors"
"log"
"os"
+ "os/signal"
+ "syscall"
"hakurei.app/container"
"hakurei.app/internal"
@@ -44,7 +47,11 @@ func main() {
log.Fatal("this program must not run as root")
}
- buildCommand(os.Stderr).MustParse(os.Args[1:], func(err error) {
+ ctx, stop := signal.NotifyContext(context.Background(),
+ syscall.SIGINT, syscall.SIGTERM)
+ defer stop() // unreachable
+
+ buildCommand(ctx, os.Stderr).MustParse(os.Args[1:], func(err error) {
hlog.Verbosef("command returned %v", err)
if errors.Is(err, errSuccess) {
hlog.BeforeExit()