set dotenv-load := true

[arg("level", pattern="trace|debug|info|warn|error|off")]
run-filtered-logs level='debug':
    RUST_LOG=none,openscq30_lib={{level}},openscq30_gui={{level}},openscq30_i18n={{level}} cargo run

# This can be used to build and run opencq30-gui on a remote windows machine (typically a VM) when developing on Linux
# Make sure to set the OPENSCQ30_WINDOWS_REMOTE_* environment variables. A .env file can be used.
[arg("level", pattern="trace|debug|info|warn|error|off")]
run-remote-windows level='debug':
    #!/usr/bin/env bash
    set -euo pipefail

    user="$OPENSCQ30_WINDOWS_REMOTE_USER"
    password="$OPENSCQ30_WINDOWS_REMOTE_PASSWORD"
    host="$OPENSCQ30_WINDOWS_REMOTE_HOST"

    dest="$user@$host"
    path="C:/Users/$user/OpenSCQ30"
    log_level="${1:-{{level}}}"

    CC=x86_64-w64-mingw32-gcc \
        cargo build \
        --target x86_64-pc-windows-gnu \
        --features bundled-dependencies \
        --features rust-embed/debug-embed

    # If it's currently running, we can't overwrite the file
    ssh "$dest" "taskkill /f /im openscq30-gui.exe" || true
    scp ../target/x86_64-pc-windows-gnu/debug/openscq30-gui.exe "$dest:$path/"

    # We can't easily set an environment variable and run openscq30-gui.exe in one go with psexec,
    # so a script is generated and uploaded as a workaround.
    echo """
    \$env:RUST_LOG='none,openscq30_lib=$log_level,openscq30_gui=$log_level,openscq30_i18n=$log_level'
    $path/openscq30-gui.exe
    """ | curl -T - "sftp://$dest/$path/launch.ps1"

    ssh "$dest" \
        -t "psexec \
            -d \
            -nobanner \
            -accepteula \
            -u \"$user\" \
            -p \"$password\" \
            -i 1 \
            powershell -NonInteractive -Command \"$path/launch.ps1\""


[arg("profile", pattern="dev|release|release-fast")]
build profile features='':
    cargo build --profile '{{profile}}' --features '{{features}}'

test:
    cargo test

test-cov:
    cargo llvm-cov --no-report --no-cfg-coverage

install path:
    ./scripts/install.sh "{{path}}"

uninstall path:
    ./scripts/uninstall.sh "{{path}}"

alias fmt := format
format:
    cargo fmt

format-check:
    cargo fmt --check
