Skip to content

Commit

Permalink
Response to review
Browse files Browse the repository at this point in the history
- Ensure --json help message is useful.
- Make the null value reporting only happen to actual null values.
  • Loading branch information
wxtim committed Aug 27, 2024
1 parent 5480b12 commit f9f9f39
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
13 changes: 13 additions & 0 deletions cylc/flow/parsec/OrderedDict.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,19 @@ def prepend(self, key, value):
self[key] = value
self.move_to_end(key, last=False)

@staticmethod
def repl_val(target, replace, replacement):
"""Replace dictionary values with a string.
Designed to be used recursively.
"""
for key, val in target.items():
if isinstance(val, dict):
OrderedDictWithDefaults.repl_val(
val, replace, replacement)
elif val == replace:
target[key] = replacement


class DictTree:
"""An object providing a single point of access to a tree of dicts.
Expand Down
4 changes: 1 addition & 3 deletions cylc/flow/parsec/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,9 @@ def jdump(
if not keys:
keys = []
cfg = self.get(keys, sparse)
cfg.repl_val(cfg, None, none_str)
data = json.dumps(cfg, indent=indent)

# We can replace null values with our none_str:
data = data.replace('null', f'"{none_str}"')

print(data, file=handle or sys.stdout)

def mdump(self, mkeys=None, sparse=False, prefix='',
Expand Down
3 changes: 1 addition & 2 deletions cylc/flow/scripts/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ def get_option_parser() -> COP:
parser.add_option(
'--json',
help=(
'Print metadata from a Cylc configuration.'
),
'Returns config as JSON rather than Cylc Config format.'),
default=False,
action='store_true',
dest='json'
Expand Down

0 comments on commit f9f9f39

Please sign in to comment.