diff --git a/README.rst b/README.rst index 7bddb24af..908c629b8 100644 --- a/README.rst +++ b/README.rst @@ -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 --------------------- diff --git a/poethepoet/__version__.py b/poethepoet/__version__.py index 81332143e..a974d21dc 100644 --- a/poethepoet/__version__.py +++ b/poethepoet/__version__.py @@ -1 +1 @@ -__version__ = "0.11.0b4" +__version__ = "0.11.0b5" diff --git a/poethepoet/ui.py b/poethepoet/ui.py index a53180629..b7e01146d 100644 --- a/poethepoet/ui.py +++ b/poethepoet/ui.py @@ -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( @@ -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, diff --git a/pyproject.toml b/pyproject.toml index 2de6b72e2..278a94edf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "] readme = "README.rst" diff --git a/tests/conftest.py b/tests/conftest.py index 3f60e4573..f69a0bf10 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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") diff --git a/tests/fixtures/high_verbosity/pyproject.toml b/tests/fixtures/high_verbosity/pyproject.toml new file mode 100644 index 000000000..c226261da --- /dev/null +++ b/tests/fixtures/high_verbosity/pyproject.toml @@ -0,0 +1,5 @@ +[tool.poe] +verbosity = 1 + +[tool.poe.tasks] +test = "echo Hello there!" diff --git a/tests/fixtures/verbosity_default/pyproject.toml b/tests/fixtures/low_verbosity/pyproject.toml similarity index 100% rename from tests/fixtures/verbosity_default/pyproject.toml rename to tests/fixtures/low_verbosity/pyproject.toml diff --git a/tests/test_poe_config.py b/tests/test_poe_config.py index 56365cfc0..2734027e8 100644 --- a/tests/test_poe_config.py +++ b/tests/test_poe_config.py @@ -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"