Add prefix/suffix support, short ID fallback, unit docs

- config: add Prefix/Suffix fields to Config struct
- systemd: ServiceName/Generate/UnitPath/Install/Uninstall/Enable/Disable/Status all accept prefix+suffix
- runtime: fall back to short container ID (12 chars) when container has no name
- cmd: active, status, install all thread prefix/suffix from config
- systemd/generator_test.go: updated all calls + added TestGenerate_WithPrefixSuffix
- docs/generated-units.md: full examples of every unit type + ordering + naming
- README: updated config docs, prefix/suffix section, link to docs/
This commit is contained in:
2026-04-03 15:47:56 +02:00
parent 5078558d01
commit a8c12c8c21
11 changed files with 419 additions and 51 deletions

View File

@@ -12,6 +12,7 @@ type Docker struct{}
func (d *Docker) Name() string { return "docker" }
type dockerContainer struct {
ID string `json:"ID"`
Names string `json:"Names"`
Image string `json:"Image"`
Command string `json:"Command"`
@@ -41,8 +42,15 @@ func (d *Docker) ListRunning() ([]Container, error) {
continue
}
name := strings.TrimPrefix(c.Names, "/")
// Fall back to short container ID if no name assigned
if name == "" {
continue
if len(c.ID) >= 12 {
name = c.ID[:12]
} else if c.ID != "" {
name = c.ID
} else {
continue
}
}
containers = append(containers, Container{
Name: name,

View File

@@ -12,6 +12,7 @@ type Podman struct{}
func (p *Podman) Name() string { return "podman" }
type podmanContainer struct {
ID string `json:"Id"`
Names []string `json:"Names"`
Image string `json:"Image"`
Command string `json:"Command"`
@@ -41,8 +42,15 @@ func (p *Podman) ListRunning() ([]Container, error) {
if len(c.Names) > 0 {
name = c.Names[0]
}
// Fall back to short container ID if no name assigned
if name == "" {
continue
if len(c.ID) >= 12 {
name = c.ID[:12]
} else if c.ID != "" {
name = c.ID
} else {
continue
}
}
containers = append(containers, Container{
Name: name,