|
19 | 19 | import re
|
20 | 20 | import sys
|
21 | 21 | from textwrap import dedent
|
22 |
| -from typing import TYPE_CHECKING, Callable, Iterable, List, Optional |
| 22 | +from typing import TYPE_CHECKING, Callable, Iterable, List, Optional, TextIO |
23 | 23 |
|
24 | 24 | from cylc.flow.context_node import ContextNode
|
25 | 25 | from cylc.flow.parsec.exceptions import (
|
@@ -183,32 +183,36 @@ def idump(self, items=None, sparse=False, prefix='',
|
183 | 183 | if null:
|
184 | 184 | mkeys = [[]]
|
185 | 185 | if json:
|
186 |
| - self.jdump(mkeys, sparse, prefix, oneline, none_str, handle=handle) |
| 186 | + self.jdump(mkeys, sparse, oneline, none_str, handle=handle) |
187 | 187 | else:
|
188 | 188 | self.mdump(mkeys, sparse, prefix, oneline, none_str, handle=handle)
|
189 | 189 |
|
190 | 190 | def jdump(
|
191 | 191 | self,
|
192 |
| - mkeys=None, |
193 |
| - sparse=False, |
194 |
| - prefix='', |
195 |
| - oneline=False, |
196 |
| - none_str='', |
197 |
| - handle=None |
198 |
| - ): |
| 192 | + mkeys: Optional[Iterable] = None, |
| 193 | + sparse: bool = False, |
| 194 | + oneline: bool = False, |
| 195 | + none_str: Optional[str] = None, |
| 196 | + handle: Optional[TextIO] = None |
| 197 | + ) -> None: |
199 | 198 | """Dump a config to JSON format.
|
| 199 | +
|
| 200 | + Args: |
| 201 | + mkeys: Items to display. |
| 202 | + sparse: Only display user set items, not defaults. |
| 203 | + oneline: Output on a single line. |
| 204 | + none_str: Value to give instead of null. |
| 205 | + handle: Where to write the output. |
200 | 206 | """
|
201 |
| - # When we call json.dumps we use indent to |
202 |
| - # control whether output is multi-line: |
203 |
| - indent = None |
204 |
| - if not oneline: |
205 |
| - indent = 4 |
| 207 | + # Use json indent to control online output: |
| 208 | + indent = None if oneline else 4 |
206 | 209 |
|
207 |
| - for keys in mkeys: |
| 210 | + for keys in mkeys or []: |
208 | 211 | if not keys:
|
209 | 212 | keys = []
|
210 | 213 | cfg = self.get(keys, sparse)
|
211 |
| - cfg.repl_val(cfg, None, none_str) |
| 214 | + if none_str: |
| 215 | + cfg.repl_val(cfg, None, none_str) |
212 | 216 | data = json.dumps(cfg, indent=indent)
|
213 | 217 |
|
214 | 218 | print(data, file=handle or sys.stdout)
|
|
0 commit comments