diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-10-21 20:29:52 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-10-21 20:29:52 +0900 |
| commit | b1a4d801be033b41c559e9642ee05e2f0ec43d5b (patch) | |
| tree | c6792307b993c1fa715285518debb95c858630ef /cmd | |
| parent | 56beae17fe7b208c144539821a3c34c395870372 (diff) | |
hst/container: flags string representation
This is useful for a user-facing representation other than JSON. This also gets rid of the ugly, outdated flags string builder in cmd/hakurei.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/hakurei/print.go | 27 | ||||
| -rw-r--r-- | cmd/hakurei/print_test.go | 20 |
2 files changed, 29 insertions, 18 deletions
diff --git a/cmd/hakurei/print.go b/cmd/hakurei/print.go index 040a3b04..8f6e7139 100644 --- a/cmd/hakurei/print.go +++ b/cmd/hakurei/print.go @@ -89,24 +89,19 @@ func printShowInstance( if params.Hostname != "" { t.Printf(" Hostname:\t%s\n", params.Hostname) } - flags := make([]string, 0, 7) - writeFlag := func(name string, flag uintptr, force bool) { - if params.Flags&flag != 0 || force { - flags = append(flags, name) + flags := params.Flags.String() + + // this is included in the upper hst.Config struct but is relevant here + const flagDirectWayland = "directwl" + if config.DirectWayland { + // hardcoded value when every flag is unset + if flags == "none" { + flags = flagDirectWayland + } else { + flags += ", " + flagDirectWayland } } - writeFlag("userns", hst.FUserns, false) - writeFlag("devel", hst.FDevel, false) - writeFlag("net", hst.FHostNet, false) - writeFlag("abstract", hst.FHostAbstract, false) - writeFlag("device", hst.FDevice, false) - writeFlag("tty", hst.FTty, false) - writeFlag("mapuid", hst.FMapRealUID, false) - writeFlag("directwl", 0, config.DirectWayland) - if len(flags) == 0 { - flags = append(flags, "none") - } - t.Printf(" Flags:\t%s\n", strings.Join(flags, " ")) + t.Printf(" Flags:\t%s\n", flags) if params.Path != nil { t.Printf(" Path:\t%s\n", params.Path) diff --git a/cmd/hakurei/print_test.go b/cmd/hakurei/print_test.go index caea8995..bc65bac3 100644 --- a/cmd/hakurei/print_test.go +++ b/cmd/hakurei/print_test.go @@ -43,7 +43,7 @@ func TestPrintShowInstance(t *testing.T) { Groups: video, dialout, plugdev Home: /data/data/org.chromium.Chromium Hostname: localhost - Flags: userns devel net abstract device tty mapuid + Flags: multiarch, compat, devel, userns, net, abstract, tty, mapuid, device, runtime, tmpdir Path: /run/current-system/sw/bin/chromium Arguments: chromium --ignore-gpu-blocklist --disable-smooth-scrolling --enable-features=UseOzonePlatform --ozone-platform=wayland @@ -88,6 +88,22 @@ App Flags: none `, false}, + {"config flag none directwl", nil, &hst.Config{DirectWayland: true, Container: new(hst.ContainerConfig)}, false, false, `Error: container configuration missing path to home directory! + +App + Identity: 0 + Enablements: (no enablements) + Flags: directwl + +`, false}, + {"config flag directwl", nil, &hst.Config{DirectWayland: true, Container: &hst.ContainerConfig{Flags: hst.FMultiarch}}, false, false, `Error: container configuration missing path to home directory! + +App + Identity: 0 + Enablements: (no enablements) + Flags: multiarch, directwl + +`, false}, {"config nil entries", nil, &hst.Config{Container: &hst.ContainerConfig{Filesystem: make([]hst.FilesystemConfigJSON, 1)}, ExtraPerms: make([]hst.ExtraPermConfig, 1)}, false, false, `Error: container configuration missing path to home directory! App @@ -124,7 +140,7 @@ App Groups: video, dialout, plugdev Home: /data/data/org.chromium.Chromium Hostname: localhost - Flags: userns devel net abstract device tty mapuid + Flags: multiarch, compat, devel, userns, net, abstract, tty, mapuid, device, runtime, tmpdir Path: /run/current-system/sw/bin/chromium Arguments: chromium --ignore-gpu-blocklist --disable-smooth-scrolling --enable-features=UseOzonePlatform --ozone-platform=wayland |
