Skip to content

Commit

Permalink
Implement --debug flag, fixes #124
Browse files Browse the repository at this point in the history
  • Loading branch information
bitprophet committed Feb 28, 2014
1 parent a9c426f commit 2992b0c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
2 changes: 2 additions & 0 deletions docs/changelog.rst
Expand Up @@ -2,6 +2,8 @@
Changelog
=========

* :feature:`124` Add a ``--debug`` flag to the core parser to enable easier
debugging (on top of existing ``INVOKE_DEBUG`` env var.)
* :feature:`125` Improve output of Failure exceptions when printed.
* :release:`0.7.0 <2014.01.28>`
* :feature:`109` Add a ``default`` kwarg to `.Collection.add_task` allowing
Expand Down
6 changes: 5 additions & 1 deletion invoke/cli.py
Expand Up @@ -9,7 +9,7 @@
from .parser import Parser, Context as ParserContext, Argument
from .executor import Executor
from .exceptions import Failure, CollectionNotFound, ParseError
from .util import debug, pty_size
from .util import debug, pty_size, enable_logging
from ._version import __version__


Expand Down Expand Up @@ -147,6 +147,10 @@ def parse(argv, collection=None):
debug("After core-args pass, leftover argv: %r" % (core.unparsed,))
args = core[0].args

# Enable debugging from here on out, if debug flag was given.
if args.debug.value:
enable_logging()

# Print version & exit if necessary
if args.version.value:
print("Invoke %s" % __version__)
Expand Down
7 changes: 5 additions & 2 deletions invoke/util.py
Expand Up @@ -6,10 +6,13 @@
import termios


def enable_logging():
logging.basicConfig(level=logging.DEBUG)

# Allow from-the-start debugging (vs toggled during load of tasks module) via
# shell env var
# shell env var.
if os.environ.get('INVOKE_DEBUG'):
logging.basicConfig(level=logging.DEBUG)
enable_logging()

# Add top level logger functions to global namespace. Meh.
log = logging.getLogger('invoke')
Expand Down
7 changes: 7 additions & 0 deletions tests/_support/debugging.py
@@ -0,0 +1,7 @@
from invoke import task
from invoke.util import debug


@task
def foo():
debug("my-sentinel")
5 changes: 1 addition & 4 deletions tests/cli.py
Expand Up @@ -229,10 +229,7 @@ def no_deduping(self):

@trap
def debug_flag(self):
expected = """
wut
"""
eq_(run("invoke -d -c debugging foo").stdout, expected)
assert 'my-sentinel' in run("invoke -d -c debugging foo").stderr

class run_options:
"run() related CLI flags"
Expand Down

0 comments on commit 2992b0c

Please sign in to comment.