Merge "Centralize shared CLI options"

This commit is contained in:
Zuul 2019-07-17 15:27:47 +00:00 committed by Gerrit Code Review
commit d43d73da94

@ -16,6 +16,7 @@ import logging
import click
import spyglass
from spyglass import cli
from spyglass.site_processors.site_processor import SiteProcessor
LOG = logging.getLogger(__name__)
@ -23,23 +24,6 @@ LOG = logging.getLogger(__name__)
LOG_FORMAT = '%(asctime)s %(levelname)-8s %(name)s:' \
'%(funcName)s [%(lineno)3d] %(message)s'
@click.option(
'-v',
'--verbose',
is_flag=True,
default=False,
help='Enable debug messages in log.')
@click.group()
def excel(*, verbose):
"""Plugin for extracting site data from Excel spreadsheets"""
if verbose:
log_level = logging.DEBUG
else:
log_level = logging.INFO
logging.basicConfig(format=LOG_FORMAT, level=log_level)
EXCEL_FILE_OPTION = click.option(
'-x',
'--excel-file',
@ -61,52 +45,21 @@ EXCEL_SPEC_OPTION = click.option(
'Excel file. Required for spyglass-plugin-xls plugin.',
)
SITE_CONFIGURATION_FILE_OPTION = click.option(
'-c',
'--site-configuration',
'site_configuration',
type=click.Path(exists=True, readable=True, dir_okay=False),
required=False,
help='Path to site specific configuration details YAML file.')
INTERMEDIARY_DIR_OPTION = click.option(
'-d',
'--intermediary-dir',
'intermediary_dir',
type=click.Path(exists=True, file_okay=False, writable=True),
default='./',
help='Directory in which the intermediary file will be created.')
SITE_NAME_CONFIGURATION_OPTION = click.option(
'-s',
'--site-name',
'site_name',
type=click.STRING,
required=False,
help='Name of the site for which the intermediary is being generated.')
TEMPLATE_DIR_OPTION = click.option(
'-t',
'--template-dir',
'template_dir',
type=click.Path(exists=True, readable=True, file_okay=False),
required=True,
help='Path to the directory containing manifest J2 templates.')
MANIFEST_DIR_OPTION = click.option(
'-m',
'--manifest-dir',
'manifest_dir',
type=click.Path(exists=True, writable=True, file_okay=False),
required=False,
help='Path to place created manifest files.')
FORCE_OPTION = click.option(
'--force',
'force',
@click.option(
'-v',
'--verbose',
is_flag=True,
default=False,
help="Forces manifests to be written, regardless of undefined data.")
help='Enable debug messages in log.')
@click.group()
def excel(*, verbose):
"""Plugin for extracting site data from Excel spreadsheets"""
if verbose:
log_level = logging.DEBUG
else:
log_level = logging.INFO
logging.basicConfig(format=LOG_FORMAT, level=log_level)
@excel.command(
@ -115,9 +68,9 @@ FORCE_OPTION = click.option(
help='Generates an intermediary file from passed excel data.')
@EXCEL_FILE_OPTION
@EXCEL_SPEC_OPTION
@SITE_CONFIGURATION_FILE_OPTION
@INTERMEDIARY_DIR_OPTION
@SITE_NAME_CONFIGURATION_OPTION
@cli.SITE_CONFIGURATION_FILE_OPTION
@cli.INTERMEDIARY_DIR_OPTION
@cli.SITE_NAME_CONFIGURATION_OPTION
def generate_intermediary(*args, **kwargs):
process_input_ob = \
spyglass.cli.intermediary_processor('excel', **kwargs)
@ -140,12 +93,12 @@ def generate_intermediary(*args, **kwargs):
)
@EXCEL_FILE_OPTION
@EXCEL_SPEC_OPTION
@SITE_CONFIGURATION_FILE_OPTION
@INTERMEDIARY_DIR_OPTION
@SITE_NAME_CONFIGURATION_OPTION
@TEMPLATE_DIR_OPTION
@MANIFEST_DIR_OPTION
@FORCE_OPTION
@cli.SITE_CONFIGURATION_FILE_OPTION
@cli.INTERMEDIARY_DIR_OPTION
@cli.SITE_NAME_CONFIGURATION_OPTION
@cli.TEMPLATE_DIR_OPTION
@cli.MANIFEST_DIR_OPTION
@cli.FORCE_OPTION
def generate_manifests_and_intermediary(*args, **kwargs):
process_input_ob = \
spyglass.cli.intermediary_processor('excel', **kwargs)