Files
unitdore/cmd/list.go
T
warkanum 91811b4fa1 feat: order/delay in service files, enable cmd, --all on unit commands
- install/uninstall/start/stop/enable take <name> or --all; *all kept as shortcuts
- add enable (enable at boot + start); startall no longer enables
- order/delay resolved by config.ResolveOrder and written into systemd,
  OpenRC and runit service files (After=/sleep), so they apply at boot
- install --all stops and disables units before removing their files
- update regenerates all installed, enabled units and removes disabled ones
- edit creates the config dir; docs and man page updated
- tests: fake Init for cmd, ResolveOrder, backend ordering output
2026-10-12 21:31:41 +02:00

86 lines
1.7 KiB
Go

package cmd
import (
"fmt"
"strings"
"github.com/spf13/cobra"
"github.com/warkanum/unitdore/config"
"github.com/warkanum/unitdore/initsys"
)
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 := sortUnits(cfg.Units, false)
prefix, suffix := cfg.Prefix, cfg.Suffix
ini, err := initsys.New(cfg)
if err != nil {
return err
}
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 := ini.UnitPath(u, prefix, suffix); err == nil {
unitPath = p
if ini.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
}