Skip to content

Commit

Permalink
PR Feedback
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Jacob Beck committed May 7, 2019
1 parent e043643 commit 32c5679
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/dbt/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
17 changes: 14 additions & 3 deletions core/dbt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down
24 changes: 22 additions & 2 deletions core/dbt/task/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand All @@ -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": [],
Expand Down

0 comments on commit 32c5679

Please sign in to comment.