#!/usr/bin/env nu
# List all available providers

def main [] {
    let provisioning = ($env.PROVISIONING | default '/usr/local/provisioning')
    let providers_base = ($provisioning | path join 'extensions' | path join 'providers')

    if not ($providers_base | path exists) {
        print 'PROVIDERS list: (none found)'
        return
    }

    # Discover all providers from directories
    let all_providers = (
        ls $providers_base
        | where type == 'dir'
        | each {|prov_dir|
            let prov_name = ($prov_dir.name | path basename)
            if $prov_name != 'prov_lib' {
                {name: $prov_name, type: 'providers', version: '0.0.1'}
            } else {
                null
            }
        }
        | compact
    )

    if ($all_providers | length) == 0 {
        print 'PROVIDERS list: (none found)'
    } else {
        print 'PROVIDERS list: '
        print ''
        $all_providers | table
    }
}
