Skip to content
Open
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
20 changes: 18 additions & 2 deletions Sources/ContainerCommands/Container/ContainerStop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,23 @@ extension Application {
let filters = ContainerListFilters().withoutMachines()
containers = try await client.list(filters: filters).map { $0.id }
} else {
containers = containerIds
// Fetch all running containers so we can resolve partial IDs
let runningContainers = try await client.list(filters: ContainerListFilters().withoutMachines())

var resolvedContainers: [String] = []
for shortId in containerIds {
// Find running containers where the full ID starts with the user's input
let matches = runningContainers.filter { $0.id.hasPrefix(shortId) }

if matches.isEmpty {
throw ContainerizationError(.notFound, message: "No such container: \(shortId)")
} else if matches.count > 1 {
throw ContainerizationError(.invalidArgument, message: "Ambiguous container ID: \(shortId)")
} else {
resolvedContainers.append(matches[0].id)
}
}
containers = resolvedContainers
}

let opts = ContainerStopOptions(
Expand Down Expand Up @@ -104,4 +120,4 @@ extension Application {
}
}
}
}
}