export def upcloud_check_requirements [
  settings: record 
  fix_error: bool
] { 
  let has_upctl = (^bash -c "type -P upctl")
  if ($has_upctl | path exists) == false and $fix_error {
    ( ^($env.PROVISIONING_NAME) "tools" "install" "upctl")
  } 
  let has_upctl = (^bash -c "type -P upctl")
  if ($has_upctl | path exists) == false {
    (throw-error $"🛑 CLI command upclouds not found" 
       "upcloud_check_requirements" --span (metadata $has_upctl).span)
    exit 1
  }
  let upctl_version = (^upctl version | grep "Version" | cut -f2 -d":"  | sed 's/ //g')
  let req_version = (open  $env.PROVISIONING_REQ_VERSIONS).upctl?.version? | default "")
  if ($upctl_version != $req_version ) and $fix_error { 
    ( ^($env.PROVISIONING_NAME) "tools" "update" "upctl")
  } 
  let upctl_version = (^upctl version | grep "Version" | cut -f2 -d":"  | sed 's/ //g')
  if $upctl_version != $req_version { 
    print $"warning❗ upctl command as CLI for UpCloud ($upctl_version) with Provisioning is not ($req_version)" 
  } 
}