diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-09-24 18:44:14 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-09-24 18:44:14 +0900 |
| commit | 1c4f593566943d8a0ce16eb3cae77f8c50238202 (patch) | |
| tree | 2ac5c41a84127ff4cd5a275c81e834c495a109c9 /cmd | |
| parent | b99c63337df4068b36d7d8de2ae79fd274172977 (diff) | |
internal/app: unexport outcome, remove app struct
The App struct no longer does anything, and the outcome struct is entirely opaque.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/hakurei/command.go | 28 | ||||
| -rw-r--r-- | cmd/hakurei/command_test.go | 2 | ||||
| -rw-r--r-- | cmd/hakurei/main.go | 9 |
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() |
