Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the -v and -q flags incremental #35

Merged
merged 3 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -393,18 +393,25 @@ You can also specify an env file (with bashlike syntax) to load for all tasks li
Default command verbosity
-------------------------

You can configure the verbosity level for poe commands by passing `--quiet` or
`--verbose` on the CLI. If you want to change the default verbosity level for
all commands, you can use the :toml:`tool.poe.verbose` option in pyproject.toml
like so:
You can alter the verbosity level for poe commands by passing :bash:`--quiet` /
:bash:`-q` (which decreases verbosity) or :bash:`--verbose` / :bash:`-v` (which
increases verbosity) on the CLI.

If you want to change the default verbosity level for all commands, you can use
the :toml:`tool.poe.verbose` option in pyproject.toml like so:

.. code-block:: toml

[tool.poe]
verbosity = -1

:toml:`-1` is equivalent to :bash:`--quiet` and :toml:`1` is equivalent to
:bash:`--verbose`. :toml:`0` is the default.
:toml:`-1` is the quietest and :toml:`1` is the most verbose. :toml:`0` is the
default.

Note that the command line arguments are incremental: :bash:`-q` subtracts one
from the default verbosity, and :bash:`-v` adds one. So setting the default
verbosity to :toml:`-1` and passing :bash:`-v -v` on the command line is
equivalent to setting the verbosity to :toml:`0` and just passing :bash:`-v`.

Run poe from anywhere
---------------------
Expand Down
2 changes: 1 addition & 1 deletion poethepoet/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.11.0b4"
__version__ = "0.11.0b5"
28 changes: 12 additions & 16 deletions poethepoet/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,22 @@ def build_parser(self) -> argparse.ArgumentParser:
help="Print the version and exit",
)

verbosity_group = parser.add_mutually_exclusive_group()
verbosity_group.add_argument(
parser.add_argument(
"-v",
"--verbose",
dest="verbosity",
action="store_const",
metavar="verbose_mode",
dest="increase_verbosity",
action="count",
default=0,
const=1,
help="More console spam",
help="Increase command output (repeatable)",
)
verbosity_group.add_argument(

parser.add_argument(
"-q",
"--quiet",
dest="verbosity",
action="store_const",
metavar="quiet_mode",
const=-1,
help="Less console spam",
dest="decrease_verbosity",
action="count",
default=0,
help="Decrease command output (repeatable)",
)

parser.add_argument(
Expand Down Expand Up @@ -129,12 +126,11 @@ def build_parser(self) -> argparse.ArgumentParser:
def parse_args(self, cli_args: Sequence[str]):
self.parser = self.build_parser()
self.args = self.parser.parse_args(cli_args)
self.verbosity: int = self["verbosity"] or 0
self.verbosity: int = self["increase_verbosity"] - self["decrease_verbosity"]
self._color.with_colors(self.args.ansi)

def set_default_verbosity(self, default_verbosity: int):
if not self.verbosity:
self.verbosity = default_verbosity
self.verbosity += default_verbosity

def print_help(
self,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "poethepoet"
version = "0.11.0b4"
version = "0.11.0b5"
description = "A task runner that works well with poetry."
authors = ["Nat Noordanus <[email protected]>"]
readme = "README.rst"
Expand Down
9 changes: 7 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,13 @@ def scripts_project_path():


@pytest.fixture
def verbosity_default_project_path():
return PROJECT_ROOT.joinpath("tests", "fixtures", "verbosity_default")
def low_verbosity_project_path():
return PROJECT_ROOT.joinpath("tests", "fixtures", "low_verbosity")


@pytest.fixture
def high_verbosity_project_path():
return PROJECT_ROOT.joinpath("tests", "fixtures", "high_verbosity")


@pytest.fixture(scope="function")
Expand Down
5 changes: 5 additions & 0 deletions tests/fixtures/high_verbosity/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[tool.poe]
verbosity = 1

[tool.poe.tasks]
test = "echo Hello there!"
27 changes: 23 additions & 4 deletions tests/test_poe_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,34 @@ def test_setting_global_env_vars(run_poe_subproc, is_windows):
assert result.stderr == ""


def test_setting_default_verbosity(run_poe_subproc, verbosity_default_project_path):
result = run_poe_subproc("test", cwd=verbosity_default_project_path,)
def test_setting_default_verbosity(run_poe_subproc, low_verbosity_project_path):
result = run_poe_subproc("test", cwd=low_verbosity_project_path,)
assert result.capture == ""
assert result.stdout == "Hello there!\n"
assert result.stderr == ""


def test_override_default_verbosity(run_poe_subproc, verbosity_default_project_path):
result = run_poe_subproc("-v", "test", cwd=verbosity_default_project_path,)
def test_override_default_verbosity(run_poe_subproc, low_verbosity_project_path):
result = run_poe_subproc("-v", "-v", "test", cwd=low_verbosity_project_path,)
assert result.capture == "Poe => echo Hello there!\n"
assert result.stdout == "Hello there!\n"
assert result.stderr == ""


def test_partially_decrease_verbosity(run_poe_subproc, high_verbosity_project_path):
result = run_poe_subproc("-q", "test", cwd=high_verbosity_project_path,)
assert result.capture == "Poe => echo Hello there!\n"
assert result.stdout == "Hello there!\n"
assert result.stderr == ""


def test_decrease_verbosity(run_poe_subproc, dummy_project_path, is_windows):
result = run_poe_subproc("-q", "part1", cwd=dummy_project_path,)
assert result.capture == ""
assert result.stderr == ""
if is_windows:
# On Windows, "echo 'Hello'" results in "'Hello'".
assert result.stdout == "'Hello'\n"
else:
# On UNIX, "echo 'Hello'" results in just "Hello".
assert result.stdout == "Hello\n"