# Image list — display current state of all role image snapshots.

use ./state.nu *

export def image-list [--provider: string = ""]: nothing -> list<record> {
    let states = (image-state-list --provider $provider)
    if ($states | length) == 0 {
        print "No image role states found."
        print "Build one with: provisioning build image create <role> --infra <path>"
        return []
    }
    let rows = ($states | each {|s|
        let fresh = (do {
            image-state-is-fresh $s.provider $s.role
        } catch { false })
        {
            provider:    $s.provider,
            role:        $s.role,
            snapshot_id: $s.snapshot_id,
            built_at:    ($s.built_at? | default "—"),
            fresh:       $fresh,
            os_base:     ($s.os_base? | default "—"),
        }
    })
    $rows | table
    $rows
}
