#!/usr/bin/env bash
#
# Cli app for managing files with configz
# see https://github.com/adeattwood/dotfiles
# see https://github.com/adeattwood/configz
#
# Author:  Ade Attwood <code@adeattwood.co.uk>
# Version: 0.0.2
# Updated: 2018-07-16
#

SCRIPT="$(realpath "$(readlink -f "$0")")";
DOTFILES_DIR=${SCRIPT%%site-modules/core/files/bin/dotfiles*}

MODULES="$(ls -1 "$DOTFILES_DIR"/modules)"
MODULES="${MODULES//.lua/}"

case $1 in
    apply)
        shift
        cd "$DOTFILES_DIR"
        for module in $@; do
          RUST_LOG=info configz --module "modules.$module";
        done
        exit 0;
    ;;
    list)
      echo "$MODULES" | column
      exit 0;
    ;;
esac

cat << HELP
    ____        __  _____ __         
   / __ \____  / /_/ __(_) /__  _____
  / / / / __ \/ __/ /_/ / / _ \/ ___/
 / /_/ / /_/ / /_/ __/ / /  __(__  ) 
/_____/\____/\__/_/ /_/_/\___/____/  
                                     
Usage: dotfiles <command>

Author: Ade Attwood <code@adeattwood.co.uk>

Commands:
    list        List all of the available configz modules
    apply       Apply a configz module

Examples:

Apply the zsh configz module
$ dotfiles apply zsh

HELP
