From 5136e3e3014fd3407a8b259b041a463865cd51aa Mon Sep 17 00:00:00 2001 From: Robpol86 Date: Sat, 13 Aug 2016 20:23:44 -0700 Subject: [PATCH] Renaming -C to -N and passing it to sphinx-build. When user requests to disable colors in sphinx-versioning, they'll expect sphinx-build to also not show colors (no colors anywhere at all). Fixing this. Renaming --no-colors short option -C to -N to be consistent with sphinx-build. Fixes https://github.com/Robpol86/sphinxcontrib-versioning/issues/16 --- README.rst | 3 +++ docs/settings.rst | 10 +++++----- sphinxcontrib/versioning/__main__.py | 4 ++-- sphinxcontrib/versioning/sphinx_.py | 2 ++ tests/test__main__/test_arguments.py | 2 +- tests/test__main__/test_main_build_scenarios.py | 12 ++++++------ 6 files changed, 19 insertions(+), 14 deletions(-) diff --git a/README.rst b/README.rst index c24f0790f..0e3be05b2 100644 --- a/README.rst +++ b/README.rst @@ -57,10 +57,13 @@ Changed * ``--sort`` no longer takes a comma separated string. Now specify multiple times (like ``--grm-exclude``). * Renamed ``--sort`` value "chrono" to "time". * Reordered positional command line arguments. Moved ``REL_SOURCE`` before the destination arguments. + * Renamed command line option ``-C`` to ``-N`` for consistency with sphinx-build. Fixed * Exposing sphinx-build verbosity to SCVersioning. Specify one ``-v`` to make SCVersioning verbose and two or more to make sphinx-build verbose. + * Using ``--no-colors`` also turns off colors from sphinx-build. + * https://github.com/Robpol86/sphinxcontrib-versioning/issues/16 1.1.0 - 2016-08-07 ------------------ diff --git a/docs/settings.rst b/docs/settings.rst index 420a71e4f..07e56e627 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -22,15 +22,15 @@ be specified before the build/push command or else you'll get an error. Change the current working directory of the program to this path. -.. option:: -C, --no-colors - - By default INFO, WARNING, and ERROR log/print statements use console colors. Use this argument to disable colors and - log/print plain text. - .. option:: -g , --git-root Path to directory in the local repo. Default is the current working directory. +.. option:: -N, --no-colors + + By default INFO, WARNING, and ERROR log/print statements use console colors. Use this argument to disable colors and + log/print plain text. + .. option:: -v, --verbose Enable verbose/debug logging with timestamps and git command outputs. Implies :option:`--no-colors`. If specified diff --git a/sphinxcontrib/versioning/__main__.py b/sphinxcontrib/versioning/__main__.py index fb9f5e5fb..4a1e2eab8 100755 --- a/sphinxcontrib/versioning/__main__.py +++ b/sphinxcontrib/versioning/__main__.py @@ -109,8 +109,8 @@ def get_params(self, ctx): @click.group(cls=ClickGroup) @click.option('-c', '--chdir', help='Make this the current working directory before running.', type=IS_EXISTS_DIR) -@click.option('-C', '--no-colors', help='Disable colors in the terminal output.', is_flag=True) @click.option('-g', '--git-root', help='Path to directory in the local repo. Default is CWD.', type=IS_EXISTS_DIR) +@click.option('-N', '--no-colors', help='Disable colors in the terminal output.', is_flag=True) @click.option('-v', '--verbose', help='Debug logging. Specify more than once for more logging.', count=True) @click.version_option(version=__version__) @click.make_pass_decorator(Config, ensure=True) @@ -120,7 +120,7 @@ def cli(config, **options): Supports only building locally with the "build" sub command or build and push to origin with the "push" sub command. For more information for either run them with their own --help. - The options below are global and must be specified before the sub command name (e.g. -C build ...). + The options below are global and must be specified before the sub command name (e.g. -N build ...). \f :param sphinxcontrib.versioning.lib.Config config: Runtime configuration. diff --git a/sphinxcontrib/versioning/sphinx_.py b/sphinxcontrib/versioning/sphinx_.py index ef3748329..5cecdf75f 100644 --- a/sphinxcontrib/versioning/sphinx_.py +++ b/sphinxcontrib/versioning/sphinx_.py @@ -140,6 +140,8 @@ def _build(argv, versions, current_name): config = Config.from_context() if config.verbose > 1: argv += ('-v',) * (config.verbose - 1) + if config.no_colors: + argv += ('-N',) # Build. result = build_main(argv) diff --git a/tests/test__main__/test_arguments.py b/tests/test__main__/test_arguments.py index 9c3a38f23..bad36e543 100644 --- a/tests/test__main__/test_arguments.py +++ b/tests/test__main__/test_arguments.py @@ -98,7 +98,7 @@ def test_global_options(tmpdir, local_empty, run, push): empty = tmpdir.ensure_dir('empty') repo = tmpdir.ensure_dir('repo') run(repo, ['git', 'init']) - args = ['-c', str(empty), '-C', '-g', str(repo), '-v', '-v'] + args + args = ['-c', str(empty), '-N', '-g', str(repo), '-v', '-v'] + args result = CliRunner().invoke(cli, args) config = result.exception.args[0] assert config.chdir == str(empty) diff --git a/tests/test__main__/test_main_build_scenarios.py b/tests/test__main__/test_main_build_scenarios.py index 2fbfa2429..b21365071 100644 --- a/tests/test__main__/test_main_build_scenarios.py +++ b/tests/test__main__/test_main_build_scenarios.py @@ -404,23 +404,23 @@ def test_error_bad_path(tmpdir, run): :param run: conftest fixture. """ with pytest.raises(CalledProcessError) as exc: - run(tmpdir, ['sphinx-versioning', '-C', '-c', 'unknown', 'build', '.', str(tmpdir)]) + run(tmpdir, ['sphinx-versioning', '-N', '-c', 'unknown', 'build', '.', str(tmpdir)]) assert 'Directory "unknown" does not exist.\n' in exc.value.output tmpdir.ensure('is_file') with pytest.raises(CalledProcessError) as exc: - run(tmpdir, ['sphinx-versioning', '-C', '-c', 'is_file', 'build', '.', str(tmpdir)]) + run(tmpdir, ['sphinx-versioning', '-N', '-c', 'is_file', 'build', '.', str(tmpdir)]) assert 'Directory "is_file" is a file.\n' in exc.value.output with pytest.raises(CalledProcessError) as exc: - run(tmpdir, ['sphinx-versioning', '-C', 'build', '.', str(tmpdir)]) + run(tmpdir, ['sphinx-versioning', '-N', 'build', '.', str(tmpdir)]) assert 'Failed to find local git repository root in {}.'.format(repr(str(tmpdir))) in exc.value.output repo = tmpdir.ensure_dir('repo') run(repo, ['git', 'init']) empty = tmpdir.ensure_dir('empty') with pytest.raises(CalledProcessError) as exc: - run(repo, ['sphinx-versioning', '-C', '-g', str(empty), 'build', '.', str(tmpdir)]) + run(repo, ['sphinx-versioning', '-N', '-g', str(empty), 'build', '.', str(tmpdir)]) assert 'Failed to find local git repository root in {}.'.format(repr(str(empty))) in exc.value.output @@ -432,7 +432,7 @@ def test_error_no_docs_found(tmpdir, local, run): :param run: conftest fixture. """ with pytest.raises(CalledProcessError) as exc: - run(local, ['sphinx-versioning', '-C', '-v', 'build', '.', str(tmpdir)]) + run(local, ['sphinx-versioning', '-N', '-v', 'build', '.', str(tmpdir)]) assert 'No docs found in any remote branch/tag. Nothing to do.\n' in exc.value.output @@ -444,5 +444,5 @@ def test_error_bad_root_ref(tmpdir, local_docs, run): :param run: conftest fixture. """ with pytest.raises(CalledProcessError) as exc: - run(local_docs, ['sphinx-versioning', '-C', '-v', 'build', '.', str(tmpdir), '-r', 'unknown']) + run(local_docs, ['sphinx-versioning', '-N', '-v', 'build', '.', str(tmpdir), '-r', 'unknown']) assert 'Root ref unknown not found in: master\n' in exc.value.output