#!/bin/sh

# script/help: Display information about available scripts.

set -e

cd "$(dirname "$0")/.."

printf "\033[1m%s\033[36m %s\033[32m %s\033[0m \n\n" "Development environment for" "ludeeus/awesomeversion" ""

echo "Available scripts:"
echo ""

for script in $(find script -type f -executable | sort); do
  script_name=$(basename "$script")
  description=$(awk -v prefix="# script/$script_name:" '
    BEGIN {desc=""}
    $0 ~ prefix {
      line = $0
      sub(prefix, "", line)
      sub(/^# */, "", line)
      desc = desc (desc ? " " : "") line
      next
    }
    desc != "" {exit}
    END {print desc}
  ' "$script")
  if [ -z "$description" ]; then
    description="No description available"
  fi
  if [ ${#description} -gt 60 ]; then
    description=$(echo "$description" | cut -c1-57)...
  fi
  printf " \033[36m %-25s\033[0m %s\n" "script/$script_name" "$description"
done

echo ""
