Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion fleetctl/list_unit_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,45 @@ var (
"target": mapTargetField,
"tmachine": mapTargetField,
"state": func(u schema.Unit, full bool) string {
if suToGlobal(u) || u.CurrentState == "" {
if suToGlobal(u) {
states, err := cAPI.UnitStates()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty wasteful. Could we pass in the states through the map function instead?

if err != nil {
return "-"
}
var (
inactive int
loaded int
launched int
currentStates []string
)
for _, state := range states {
if state.Name == u.Name {
if (state.SystemdActiveState == "active") || (state.SystemdSubState == "running") {
launched++
continue
}
if state.SystemdLoadState == "loaded" {
loaded++
continue
}
inactive++
}
}
if launched != 0 {
s := fmt.Sprintf("launched(%d)", launched)
currentStates = append(currentStates, s)
}
if loaded != 0 {
s := fmt.Sprintf("loaded(%d)", loaded)
currentStates = append(currentStates, s)
}
if inactive != 0 {
s := fmt.Sprintf("inactive(%d)", inactive)
currentStates = append(currentStates, s)
}
return strings.Join(currentStates, " ")
}
if u.CurrentState == "" {
return "-"
}
return u.CurrentState
Expand Down