prvng_core/nulib/lib_provisioning/extensions/commands.nu

279 lines
8.1 KiB
Text
Raw Normal View History

2025-10-07 10:32:04 +01:00
# Extension Management CLI Commands
refactor(cache/coredns/extensions/vm): selective imports — 6 files (ADR-025 L2) Combined batch of 6 L2 refactors. Same mechanical pattern (star -> selective); grouped in one commit because batch 1 was staged but not committed before batch 2 was prepared. === extensions/commands.nu (4 stars -> 1 selective, 3 dead) === loader_oci.nu [load-extension] (kept, already selective) discovery.nu [4 symbols] cache.nu / versions.nu / utils/logging.nu DROPPED (dead) === coredns/commands.nu (4 stars -> 3 selective, 2 dead + 1 broken) === config/loader.nu [get-config] (already selective; promoted to absolute) service.nu [8 symbols] zones.nu [9 symbols] corefile.nu [2 symbols] utils/log.nu REMOVED (file does not exist — dangling import) utils/logging.nu DROPPED (dead) === cache/agent.nu (4 stars -> 2 selective, 2 dead) === cache_manager.nu [4 symbols] batch_updater.nu [2 symbols] version_loader.nu / grace_checker.nu DROPPED (dead) === vm/vm_persistence.nu (3 stars -> 2 selective, 1 dead) === result.nu [6 symbols] vm/lifecycle.nu [vm-delete] vm/persistence.nu DROPPED (dead) === vm/nested_provisioning.nu (3 stars -> 3 selective) === vm/lifecycle.nu [vm-info] vm/volume_management.nu [volume-attach volume-detach] vm/network_management.nu [network-connect network-disconnect] === vm/cleanup_scheduler.nu (3 stars -> 1 selective, 1 dead) === vm/vm_persistence.nu [4 symbols] vm/lifecycle.nu DROPPED (dead) Note: line ~211 embeds an intentional template string containing `use lib_provisioning/vm/cleanup_scheduler.nu *` — it's Nu script code written to disk at runtime for the scheduler daemon. NOT a real import. Validation (ide-check 50 errors after vs baseline): extensions/commands.nu 0 vs 0 ✓ coredns/commands.nu 50 vs 50 ✓ (pre-existing transitive noise) cache/agent.nu 0 vs 0 ✓ vm/vm_persistence.nu 50 vs 50 ✓ vm/nested_provisioning.nu 50 vs 50 ✓ vm/cleanup_scheduler.nu 50 vs 50 ✓ 21 star-imports eliminated (~10% of remaining 221). Refs: ADR-025
2026-04-17 08:47:32 +01:00
# Selective imports (ADR-025 Phase 3 Layer 2).
# cache.nu, versions.nu and utils/logging.nu star-imports were dead — dropped.
use lib_provisioning/extensions/loader_oci.nu [load-extension]
use lib_provisioning/extensions/discovery.nu [
discover-all-extensions get-extension-versions list-extensions search-extensions
]
2025-10-07 10:32:04 +01:00
# Load extension from any source
export def "ext load" [
extension_name: string # Extension name
--type: string = "taskserv" # Extension type (provider, taskserv, cluster)
--version: string = "latest" # Version constraint
--source: string = "auto" # Source type (auto, oci, gitea, local)
--force (-f) # Force reload
] {
print $"Loading extension: ($extension_name)"
let result = (load-extension $type $extension_name $version --source-type $source --force=$force)
if $result.success {
print $"✅ Loaded ($extension_name):($result.version?) from ($result.source)"
} else {
print $"❌ Failed to load ($extension_name): ($result.error?)"
exit 1
}
}
# Search for extensions
export def "ext search" [
query: string # Search query
--source: string = "all" # Source to search (all, oci, gitea, local)
] {
print $"Searching for: ($query)"
let results = (search-extensions $query --source $source)
if ($results | is-empty) {
print " (no extensions found)"
return
}
print ""
$results | select name type version source | sort-by type name
}
# List available extensions
export def "ext list" [
--type: string = "" # Filter by extension type
--source: string = "all" # Source to list (all, oci, gitea, local)
--format: string = "table" # Output format (table, json, yaml)
] {
list-extensions --extension-type $type --source $source --format $format
}
# Show extension info
export def "ext info" [
extension_name: string # Extension name
--version: string = "latest" # Extension version
--source: string = "auto" # Source type
] {
print $"Extension: ($extension_name)"
# Discover to find extension
let all_extensions = (discover-all-extensions)
let matches = ($all_extensions | where name == $extension_name)
if ($matches | is-empty) {
print " ❌ Extension not found"
return
}
for ext in $matches {
print ""
print $" Source: ($ext.source)"
print $" Type: ($ext.type)"
print $" Version: ($ext.version)"
if ($ext.description? | is-not-empty) {
print $" Description: ($ext.description)"
}
if $ext.source == "oci" {
print $" Registry: ($ext.registry)"
print $" Namespace: ($ext.namespace)"
}
if $ext.source == "local" {
print $" Path: ($ext.path)"
}
}
}
# List extension versions
export def "ext versions" [
extension_name: string # Extension name
--source: string = "all" # Source to check
] {
print $"Versions of ($extension_name):"
let versions = (get-extension-versions $extension_name --source $source)
if ($versions | is-empty) {
print " (no versions found)"
return
}
$versions | select version source | sort-by source version
}
# Cache management commands
export def "ext cache list" [
--type: string = "" # Filter by extension type
] {
list-cached --extension-type $type
}
export def "ext cache clear" [
--type: string = "" # Extension type to clear
--name: string = "" # Extension name to clear
--all # Clear all cache
] {
if $all {
clear-cache
print "✅ Cleared all extension cache"
} else if ($type | is-not-empty) and ($name | is-not-empty) {
clear-cache --extension-type $type --extension-name $name
print $"✅ Cleared cache for ($name)"
} else if ($type | is-not-empty) {
clear-cache --extension-type $type
print $"✅ Cleared cache for all ($type)"
} else {
print "❌ Specify --all, or --type and --name"
exit 1
}
}
export def "ext cache stats" [] {
let stats = (get-cache-stats)
print "📊 Extension Cache Statistics"
print ""
print $" Total extensions: ($stats.total_extensions)"
print $" Total size: ($stats.total_size_bytes) bytes"
print $" Cache directory: ($stats.cache_dir)"
print $" Last updated: ($stats.last_updated)"
print ""
print " By type:"
for type_stat in $stats.by_type {
print $" • ($type_stat.type): ($type_stat.count)"
}
print ""
print " By source:"
for source_stat in $stats.by_source {
print $" • ($source_stat.source): ($source_stat.count)"
}
}
export def "ext cache prune" [
--days: int = 30 # Remove entries older than days
] {
print $"Pruning cache entries older than ($days) days..."
let result = (prune-cache $days)
print $"✅ Removed ($result.removed_count) extensions"
if ($result.removed_extensions | length) > 0 {
print ""
print " Removed:"
for ext in $result.removed_extensions {
print $" • ($ext.name) ($ext.version) - ($ext.type)"
}
}
}
# Pull extension to cache without loading
export def "ext pull" [
extension_name: string # Extension name
--type: string = "taskserv" # Extension type
--version: string = "latest" # Version to pull
--source: string = "auto" # Source type
] {
print $"Pulling ($extension_name):($version) to cache..."
let result = (load-extension $type $extension_name $version --source-type $source)
if $result.success {
print $"✅ Pulled ($extension_name):($result.version?) to cache"
} else {
print $"❌ Failed to pull: ($result.error?)"
exit 1
}
}
# Publish extension to OCI registry
export def "ext publish" [
extension_path: string # Path to extension
--version: string # Version to publish
--registry: string = "" # OCI registry
--namespace: string = "" # Registry namespace
--force (-f) # Overwrite existing
] {
# Delegate to publish_extension.nu tool
let tool_path = ($env.FILE_PWD | path dirname | path dirname | path dirname | path dirname | path join "tools" "publish_extension.nu")
let args = [
$extension_path
--version $version
]
let args_with_registry = if ($registry | is-not-empty) {
$args | append [--registry $registry]
} else {
$args
}
let args_with_namespace = if ($namespace | is-not-empty) {
$args_with_registry | append [--namespace $namespace]
} else {
$args_with_registry
}
let final_args = if $force {
$args_with_namespace | append [--force]
} else {
$args_with_namespace
}
nu $tool_path ...$final_args
}
# Discover extensions from all sources
export def "ext discover" [
--type: string = "" # Filter by type
--refresh # Force refresh from sources
] {
print "🔍 Discovering extensions..."
let extensions = (discover-all-extensions $type)
if ($extensions | is-empty) {
print " (no extensions found)"
return
}
print ""
print $"Found ($extensions | length) extensions:"
print ""
$extensions | select name type version source | sort-by type source name
}
# Test OCI connection
export def "ext test-oci" [] {
use ../oci/client.nu test-oci-connection
print "Testing OCI registry connection..."
print ""
let result = (test-oci-connection)
print $" Registry reachable: ($result.registry_reachable)"
print $" Authentication valid: ($result.authentication_valid)"
print $" Catalog accessible: ($result.catalog_accessible)"
if ($result.errors | is-not-empty) {
print ""
print " Errors:"
for error in $result.errors {
print $" • ($error)"
}
}
}