#!/usr/bin/env bash

# Nomarchy Log Upload Script
# Uploads stdin or a file to a pastebin service.

set -e

if [[ -t 0 ]] && [[ -z $1 ]]; then
    echo "Usage: some-command | nomarchy-upload-log"
    echo "       nomarchy-upload-log <file>"
    exit 1
fi

# Use ix.io as the default pastebin
if [[ -n $1 ]]; then
    url=$(curl -F "f:1=@$1" ix.io)
else
    url=$(curl -F "f:1=@-" ix.io)
fi

echo "Log uploaded to: $url"
if command -v wl-copy &>/dev/null; then
    echo "$url" | wl-copy
    echo "Link copied to clipboard."
fi
