Files
unitdore/cmd/list.go
T
warkanum f0827fcdd7 feat: podman-compose stack units and root/user execution scopes
- syncup: podman first, docker only as fallback (podman wins on name clash;
  existing docker units found in podman switch to podman)
- syncup: group podman-compose containers into one `kind: stack` unit per
  project (project, working_dir, compose_files, compose_bin from labels);
  disable existing member units ("part of stack <project>")
- generator: compose mode (podman-compose up/stop, WorkingDirectory) with
  pod start/stop fallback when compose binary/dir/files are missing
- reconcile: stacks disabled with "stack not found" when neither compose
  files nor pod exist
- root: scan root + rootless users listed in `users:` (podman only)
- non-root: config ~/.config/unitdore/units.yaml, own user units only
- sysuser package: runuser with XDG_RUNTIME_DIR/DBUS env, home/linger lookup
- install: warn when linger is not enabled for user units
- testdata/stack: podman-compose test stack and captured podman ps fixture
- docs: README, generated-units, man page, AGENTS, PLAN
2026-10-12 19:05:51 +02:00

90 lines
1.9 KiB
Go

package cmd
import (
"fmt"
"sort"
"strings"
"github.com/spf13/cobra"
"github.com/warkanum/unitdore/config"
"github.com/warkanum/unitdore/systemd"
)
var listCmd = &cobra.Command{
Use: "list",
Short: "List all tracked units with service file locations",
RunE: runList,
}
func init() {
rootCmd.AddCommand(listCmd)
}
func runList(cmd *cobra.Command, args []string) error {
cfg, err := config.Load(configPath)
if err != nil {
return err
}
if len(cfg.Units) == 0 {
fmt.Println("No units tracked. Run 'unitdore syncup' to discover containers.")
return nil
}
units := make([]config.Unit, len(cfg.Units))
copy(units, cfg.Units)
sort.Slice(units, func(i, j int) bool {
if units[i].Order != units[j].Order {
return units[i].Order < units[j].Order
}
return units[i].Name < units[j].Name
})
prefix, suffix := cfg.Prefix, cfg.Suffix
type row struct{ name, runtime, enabled, installed, path string }
rows := make([]row, 0, len(units))
for _, u := range units {
enabled := "yes"
if !u.Enabled {
enabled = "no"
}
installed := "no"
unitPath := "—"
if p, err := systemd.UnitPath(u, prefix, suffix); err == nil {
unitPath = p
if systemd.IsInstalled(u, prefix, suffix) {
installed = "yes"
}
}
rows = append(rows, row{u.Name, runtimeLabel(u), enabled, installed, unitPath})
}
cols := []string{"NAME", "RUNTIME", "ENABLED", "INSTALLED", "SERVICE FILE"}
widths := make([]int, len(cols))
for i, c := range cols {
widths[i] = len(c)
}
for _, r := range rows {
vals := []string{r.name, r.runtime, r.enabled, r.installed, r.path}
for i, v := range vals {
if len(v) > widths[i] {
widths[i] = len(v)
}
}
}
fmt.Println()
printRow(cols, widths)
fmt.Println(strings.Repeat("─", totalWidth(widths)))
for _, r := range rows {
printRow([]string{r.name, r.runtime, r.enabled, r.installed, r.path}, widths)
}
fmt.Println()
return nil
}