#!/usr/bin/env bash
ROOT=$(cd -- "$(dirname -- "$0")" && pwd)
export AZURE_CONFIG_DIR="$ROOT/azconfig"
export AZURE_DEVOPS_EXT_PAT=synthetic-evidence-pat
AZ="$ROOT/azure/bin/az"
for side in before after; do
  RUN="$ROOT/run-$(date -u +%Y%m%dT%H%M%S)-$side"
  mkdir -p "$RUN"
  {
    echo "Side: $side. Real Azure CLI against synthetic local on-prem REST collection."
    "$AZ" version --query '"azure-cli"' -o tsv
    "$AZ" extension show --name azure-devops --query version -o tsv
    "$AZ" repos pr list --detect false --query '[].{id:pullRequestId,title:title,status:status}' -o json
    echo "repos pr list exit=$?"
    "$AZ" account show --query user.name -o tsv
    echo "account show exit=$?"
    "$AZ" devops project list --top 1 --query 'value[0].url' -o tsv
    echo "project list exit=$?"
  } > "$RUN/cli.txt" 2>&1
  cat "$RUN/cli.txt"
done
