#!/usr/bin/env bash
#-------------------------------------------------------------------------------
# Copyright (C) 2012-2019 British Crown (Met Office) & Contributors.
#
# This file is part of Rose, a framework for meteorological suites.
#
# Rose is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Rose is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Rose. If not, see <http://www.gnu.org/licenses/>.
#-------------------------------------------------------------------------------
# NAME
#     rose macro
#
# SYNOPSIS
#     rose macro [OPTIONS] [MACRO_NAME ...]
#
# DESCRIPTION
#     List or run macros associated with a suite or application.
#
#     Macros are listed/run according to the config dir (`$PWD` unless
#     `--config=DIR` is set):
#
#     * If the config dir is an app directory (or is within an app directory)
#       macros will be listed/run for the `rose-app.conf` file of that app.
#     * Otherwise macros will be listed/run for the `rose-suite.conf`,
#       `rose-suite.info` and (unless `--suite-only` is set) all
#       `rose-app.conf` files.
#
#     If a configuration contains optional configurations:
#
#     * For validator macros, validate the main configuration, then
#       validate each main + optional configuration in turn.
#     * For transform macros, transform the main configuration, then
#       transform each main + optional configuration, recreating each
#       optional configuration as the diff vs the transformed main.
#
# OPTIONS
#     --config=DIR, -C DIR
#         Use configuration in `DIR` instead of `$PWD`.
#     --fix, -F
#         Prepend all internal transformer (fixer) macros to the argument
#         list.
#     --meta-path=PATH, -M PATH
#         Prepend `PATH` to the metadata search path (look here first).
#         This option can be used repeatedly to load multiple paths.
#     --non-interactive, --yes, -y
#         Switch off interactive prompting (=answer yes to everything).
#     --output=DIR, -O DIR
#         The location of the output directory. Only meaningful if
#         there is at least one transformer in the argument list.
#     --quiet, -q
#         Reduce verbosity.
#     --suite-only
#         Run only for suite level macros.
#     --transform, -T
#         Prepend all transformer macros to the argument list.
#     --validate, -V
#         Prepend all validator macros to the argument list.
#
# ARGUMENTS
#     MACRO_NAME ...
#         A list of macro names to run. If no macro names are specified and
#         `--fix`, `--validate` are not used, list all available macros.
#         Otherwise, run the specified macro names.
#
# ENVIRONMENT VARIABLES
#     optional ROSE_META_PATH
#         Prepend `$ROSE_META_PATH` to the metadata search path.
#-------------------------------------------------------------------------------
exec python2 -m rose.macro "$@"
