#!/usr/bin/env nu # Version Consistency Checker # Ensures nushell system version matches submodule version # Get nushell version from submodule Cargo.toml def get_submodule_version [] { let nushell_cargo = "nushell/Cargo.toml" if not ($nushell_cargo | path exists) { error make {msg: "Nushell submodule not found. Please run 'git submodule update --init --recursive'"} } try { let content = open $nushell_cargo $content.package.version } catch { error make {msg: "Could not read nushell version from submodule"} } } # Get installed nushell version - try project binary first, then system def get_system_version [] { # Try project binary first (more reliable, avoids broken system nu) let project_binary = "nushell/target/release/nu" if ($project_binary | path exists) { try { let version = (do { ^$project_binary --version } | complete) if $version.exit_code == 0 { return ($version.stdout | str trim) } } catch { # Fall through to system nu } } # Fall back to system nu try { nu --version | str trim } catch { error make {msg: "Could not get system nushell version - system binary appears broken or missing"} } } # Check if versions match def check_versions [] { let submodule_version = get_submodule_version let system_version = get_system_version { submodule: $submodule_version, system: $system_version, match: ($submodule_version == $system_version) } } # Main function for version checking def main [ --fix # Attempt to fix version mismatch --quiet # Suppress output except errors ] { let versions = check_versions if not $quiet { print $"🔍 Version Check:" print $" Submodule: ($versions.submodule)" print $" Project Binary: ($versions.system)" } if $versions.match { if not $quiet { print "✅ Versions match - OK" } return true } else { print "❌ Version mismatch detected!" print $" Expected: ($versions.submodule) - from nushell submodule (Cargo.toml)" print $" Found: ($versions.system) - project or system binary" print "" if $fix { print "🔧 Attempting to fix version mismatch..." print "💡 Running update_nushell.sh to install correct version..." try { # Call the update_nushell.sh script to fix the installation let result = run-external "bash" ["scripts/sh/update_nushell.sh", "update"] print "✅ Nushell updated successfully" return true } catch { print "❌ Failed to update nushell automatically" print "🛠️ Manual fix required:" print $" 1. Run: ./scripts/sh/update_nushell.sh update" print $" 2. Or install nushell ($versions.submodule) manually" return false } } else { print "🛠️ To fix this issue:" print " 1. Run: nu scripts/nu/check_version.nu --fix" print " 2. Or manually: ./scripts/sh/update_nushell.sh update" return false } } } # Export function for use by other scripts export def version_check [--quiet] { let versions = check_versions if not $versions.match { if not $quiet { print $"❌ Version mismatch: system=($versions.system), required=($versions.submodule)" } return false } return true }