#!/usr/bin/env sh

if [ $# -lt 1 ]
then
    echo "usage: $0 command-name"
    echo "  This script generates a file at commands/commands/command-name.py, containing the base of a rollbot command."
    echo "  The command-name must be a valid python identifier, and should only be composed of lowercase letters and underscores"
    exit 1
fi

if ! [[ "$1" =~ ^[a-z][a-z_]*$ ]]
then
    echo "Command names should be composed entirely of lowercase letters and underscores"
    exit 1
fi

COMMAND_FILE="./commands/commands/$1.py"

if [[ -f $COMMAND_FILE ]]
then
    echo "Command module with this name already exists - pick a new module name. You can always bind it to a different command word later!"
    exit 1
fi

echo "Populating $COMMAND_FILE with basic command called $1"

echo "from rollbot import as_command" >> $COMMAND_FILE
echo "" >> $COMMAND_FILE
echo "" >> $COMMAND_FILE
echo "@as_command" >> $COMMAND_FILE
echo "def $1():" >> $COMMAND_FILE
echo "    return \"Hello, world!\"" >> $COMMAND_FILE

echo "Done! Command is ready for you to edit at $COMMAND_FILE, you do not need to modify any configuration!"
