#!/usr/bin/env bash

SOURCE="${BASH_SOURCE[0]}"

# If the current source is a symbolic link, we need to resolve it to an
# actual directory name. We'll use PHP to do this easier than we can
# do it in pure Bash. So, we'll call into PHP CLI here to resolve.
if [[ -L "$SOURCE" ]]
then
    DIR=$(php -r "echo dirname(realpath('$SOURCE'));")
else
    DIR="$( cd "$( dirname "$SOURCE" )" && pwd )"
fi

# If we are in the global Composer "bin" directory, we need to bump our
# current directory up two, so that we will correctly proxy into the
# YesWiki CLI script which is written in PHP. Will use PHP to do it.
if [ ! -f "$DIR/yeswicli" ]
then
    DIR=$(php -r "echo realpath('$DIR/../YesWiki/yeswiki');")
fi

php $DIR/includes/commands/console $@

# TODO : add those commands
# extension
#  extension:disable                            disable an extension
#  extension:enable                             enable an extension
#  extension:install                            install an extension
#  extension:list                               List all available extensions
#  extension:remove                             remove an extension
#  extension:update                             update an extension or all extensions

# config
#  config:import                         Import a list of configs
#  config:list                           List all configs
#  config:value:delete                   Delete a system config value
#  config:value:get                      Get a system config value
#  config:value:set                      Set a system config value
