Repository: sphinx-doc/sphinx

Issue:
Not possible to set  boolean `latex_use_xindy` via `-D` option to sphinx-build
**Describe the bug**

Impossible to override [`latex_use_xindy`](http://www.sphinx-doc.org/en/master/usage/configuration.html#confval-latex_use_xindy) from command line invocation of `sphinx-build`.

**To Reproduce**
With any project

```
sphinx-build -b latex . _build/latex -D latex_use_xindy=0
```

produces

```
WARNING: The config value `latex_use_xindy' has type `str', defaults to `bool'.
```
And the latex output directory will actually be configured for PDF build to use `xindy`.

Notice that for example
```
sphinx-build -b latex . _build/latex -D latex_use_latex_multicolumn=0
```
raises no warning and behaves as expected. Same for
```
sphinx-build -b latex . _build/latex -D smartquotes=0
```
which works fine.

**Expected behavior**
People reading documentation are rewarded with Sphinx behaving as promised :smile:

**Your project**

Any project.


**Environment info**
- OS: Mac
- Python version: 3.7.5
- Sphinx version: tested with 2.0.1 and current 2.0 branch


**Additional context**


- #6898 



Discussion:
codecov[bot]: # [Codecov](https://codecov.io/gh/sphinx-doc/sphinx/pull/6908?src=pr&el=h1) Report
> Merging [#6908](https://codecov.io/gh/sphinx-doc/sphinx/pull/6908?src=pr&el=desc) into [master](https://codecov.io/gh/sphinx-doc/sphinx/commit/7ec567b6d09ca126f24242a24ff0d485da63a6c4?src=pr&el=desc) will **decrease** coverage by `0.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/sphinx-doc/sphinx/pull/6908/graphs/tree.svg?width=650&token=VFlFSELbkw&height=150&src=pr)](https://codecov.io/gh/sphinx-doc/sphinx/pull/6908?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #6908      +/-   ##
==========================================
- Coverage   84.59%   84.58%   -0.02%     
==========================================
  Files         266      267       +1     
  Lines       41250    41277      +27     
  Branches     5963     5968       +5     
==========================================
+ Hits        34897    34914      +17     
- Misses       5034     5040       +6     
- Partials     1319     1323       +4
```


| [Impacted Files](https://codecov.io/gh/sphinx-doc/sphinx/pull/6908?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [sphinx/builders/latex/\_\_init\_\_.py](https://codecov.io/gh/sphinx-doc/sphinx/pull/6908/diff?src=pr&el=tree#diff-c3BoaW54L2J1aWxkZXJzL2xhdGV4L19faW5pdF9fLnB5) | `80.89% <100%> (ø)` | :arrow_up: |
| [sphinx/config.py](https://codecov.io/gh/sphinx-doc/sphinx/pull/6908/diff?src=pr&el=tree#diff-c3BoaW54L2NvbmZpZy5weQ==) | `85.47% <100%> (-1.45%)` | :arrow_down: |
| [sphinx/\_\_init\_\_.py](https://codecov.io/gh/sphinx-doc/sphinx/pull/6908/diff?src=pr&el=tree#diff-c3BoaW54L19faW5pdF9fLnB5) | `73.91% <0%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/sphinx-doc/sphinx/pull/6908?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/sphinx-doc/sphinx/pull/6908?src=pr&el=footer). Last update [7ec567b...797d8ec](https://codecov.io/gh/sphinx-doc/sphinx/pull/6908?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

tk0miya: I have to add test for Config.
jfbu: Can you rebase this to 2.0 branch?
tk0miya: oh, I have wrong target branch. changed.

Patch:
diff --git a/CHANGES b/CHANGES
index 5e57e5c05..dcc480c8e 100644
--- a/CHANGES
+++ b/CHANGES
@@ -87,6 +87,8 @@ Bugs fixed
 * #6876: LaTeX: multi-line display of authors on title page has ragged edges
 * #6887: Sphinx crashes with docutils-0.16b0
 * #6920: sphinx-build: A console message is wrongly highlighted
+* #6900: sphinx-build: ``-D`` option does not considers ``0`` and ``1`` as a
+  boolean value
 
 Testing
 --------
diff --git a/sphinx/builders/latex/__init__.py b/sphinx/builders/latex/__init__.py
index 6a0d70e5e..de4223a0e 100644
--- a/sphinx/builders/latex/__init__.py
+++ b/sphinx/builders/latex/__init__.py
@@ -464,7 +464,7 @@ def setup(app: Sphinx) -> Dict[str, Any]:
     app.add_config_value('latex_logo', None, None, [str])
     app.add_config_value('latex_appendices', [], None)
     app.add_config_value('latex_use_latex_multicolumn', False, None)
-    app.add_config_value('latex_use_xindy', default_latex_use_xindy, None)
+    app.add_config_value('latex_use_xindy', default_latex_use_xindy, None, [bool])
     app.add_config_value('latex_toplevel_sectioning', None, None,
                          ENUM(None, 'part', 'chapter', 'section'))
     app.add_config_value('latex_domain_indices', True, None, [list])
diff --git a/sphinx/config.py b/sphinx/config.py
index cbe04b3ee..ddee765b7 100644
--- a/sphinx/config.py
+++ b/sphinx/config.py
@@ -217,6 +217,12 @@ def convert_overrides(self, name, value):
             defvalue = self.values[name][0]
             if self.values[name][2] == Any:
                 return value
+            elif type(defvalue) is bool or self.values[name][2] == [bool]:
+                if value == '0':
+                    # given falsy string from command line option
+                    return False
+                else:
+                    return bool(value)
             elif isinstance(defvalue, dict):
                 raise ValueError(__('cannot override dictionary config setting %r, '
                                     'ignoring (use %r to set individual elements)') %


Test patch:
diff --git a/tests/test_config.py b/tests/test_config.py
index a5da0d6ec..1d3a49e95 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -119,6 +119,20 @@ def test_overrides():
     assert config.value8 == ['abc', 'def', 'ghi']
 
 
+def test_overrides_boolean():
+    config = Config({}, {'value1': '1',
+                         'value2': '0',
+                         'value3': '0'})
+    config.add('value1', None, 'env', [bool])
+    config.add('value2', None, 'env', [bool])
+    config.add('value3', True, 'env', ())
+    config.init_values()
+
+    assert config.value1 is True
+    assert config.value2 is False
+    assert config.value3 is False
+
+
 @mock.patch("sphinx.config.logger")
 def test_errors_warnings(logger, tempdir):
     # test the error for syntax errors in the config file