use ../../../../core/nulib/lib_provisioning/config/accessor.nu *

export def aws_check_requirements [
  settings: record 
  fix_error: bool
] { 
  let has_aws = (^bash -c "type -P aws")
  if ($has_aws | path exists) == false and $fix_error {
    ( ^((get-provisioning-name)) "tools" "install" "aws")
  } 
  let has_aws = (^bash -c "type -P aws")
  if ($has_aws | path exists) == false {
    (throw-error $"🛑 CLI command aws not found" 
       "aws_check_requirements" --span (metadata $has_aws).span)
    exit 1
  }
  let aws_version = (^aws --version | cut -f1 -d" "  | sed 's,aws-cli/,,g')
  let req_version = (open  (get-provisioning-req-versions)).aws?.version? | default ""
  if ($aws_version != $req_version ) and $fix_error { 
    ( ^((get-provisioning-name)) "tools" "update" "aws")
  } 
  let aws_version = (^aws --version | cut -f1 -d" "  | sed 's,aws-cli/,,g')
  if $aws_version != $req_version { 
    print $"warning❗ aws command as CLI for AWS ($aws_version) with Provisioning is not ($req_version)" 
  } 
}