From 32c567903922015e31ff2f4b0e04348f3eb65b21 Mon Sep 17 00:00:00 2001 From: Jacob Beck Date: Tue, 7 May 2019 07:57:06 -0600 Subject: [PATCH] PR Feedback Fixed error logging to display errors in dbt ls Add models flag Make all of models, select, exclude have a metavar of 'SELECTOR' for -h --- core/dbt/logger.py | 2 +- core/dbt/main.py | 17 ++++++++++++++--- core/dbt/task/list.py | 24 ++++++++++++++++++++++-- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/core/dbt/logger.py b/core/dbt/logger.py index a1b3e590bad..7ec7426c619 100644 --- a/core/dbt/logger.py +++ b/core/dbt/logger.py @@ -50,7 +50,7 @@ def notice(self, msg, *args, **kwargs): stdout_handler.setFormatter(logging.Formatter('%(message)s')) stdout_handler.setLevel(NOTICE) -stderr_handler = logging.StreamHandler() +stderr_handler = logging.StreamHandler(sys.stderr) stderr_handler.setFormatter(logging.Formatter('%(message)s')) stderr_handler.setLevel(WARNING) diff --git a/core/dbt/main.py b/core/dbt/main.py index f270ed3b21d..18f1dacd9b6 100644 --- a/core/dbt/main.py +++ b/core/dbt/main.py @@ -93,8 +93,8 @@ def main(args=None): exit_code = e.code except BaseException as e: - logger.info("Encountered an error:") - logger.info(str(e)) + logger.warn("Encountered an error:") + logger.warn(str(e)) if logger_initialized(): logger.debug(traceback.format_exc()) @@ -592,13 +592,24 @@ def _build_list_subparser(subparsers, base_subparser): '--select', required=False, nargs='+', + metavar='SELECTOR', help="Specify the nodes to select.", - dest='models' + ) + sub.add_argument( + '-m', + '--models', + required=False, + nargs='+', + metavar='SELECTOR', + help="Specify the models to select and set the resource-type to " + "'model'. Mutually exclusive with '--select' (or '-s') and " + "'--resource-type'", ) sub.add_argument( '--exclude', required=False, nargs='+', + metavar='SELECTOR', help="Specify the models to exclude." ) # in python 3.x you can use the 'aliases' kwarg, but in python 2.7 you get diff --git a/core/dbt/task/list.py b/core/dbt/task/list.py index b4095b46c0b..55204454268 100644 --- a/core/dbt/task/list.py +++ b/core/dbt/task/list.py @@ -33,7 +33,17 @@ class ListTask(GraphRunnableTask): def __init__(self, args, config): super(ListTask, self).__init__(args, config) - self.config.args.single_threaded = True + self.args.single_threaded = True + if self.args.models: + if self.args.select: + raise dbt.exceptions.RuntimeException( + '"models" and "select" are mutually exclusive arguments' + ) + if self.args.resource_types: + raise dbt.exceptions.RuntimeException( + '"models" and "resource_type" are mutually exclusive ' + 'arguments' + ) @classmethod def pre_init_hook(cls): @@ -96,6 +106,9 @@ def run(self): @property def resource_types(self): + if self.args.models: + return [NodeType.Model] + values = set(self.config.args.resource_types) if not values: return list(self.DEFAULT_RESOURCE_VALUES) @@ -108,9 +121,16 @@ def resource_types(self): values.update(self.ALL_RESOURCE_VALUES) return list(values) + @property + def selector(self): + if self.args.models: + return self.args.models + else: + return self.args.select + def build_query(self): return { - "include": self.args.models, + "include": self.selector, "exclude": self.args.exclude, "resource_types": self.resource_types, "tags": [],