Skip to content

Commit

Permalink
Dump all properties to JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
john-kurkowski committed Nov 6, 2023
1 parent f0320ae commit bb75a7b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 3 additions & 0 deletions tests/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,8 @@ def test_cli_json_output(
"domain": "bbc",
"suffix": "co.uk",
"fqdn": "www.bbc.co.uk",
"ipv4": "",
"ipv6": "",
"is_private": False,
"registered_domain": "bbc.co.uk",
}
10 changes: 4 additions & 6 deletions tldextract/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""tldextract CLI."""


import argparse
import dataclasses
import json
import logging
import os.path
Expand Down Expand Up @@ -98,14 +98,12 @@ def main() -> None:
for i in args.input:
ext = tld_extract(i)
if args.json:
properties = ("fqdn", "ipv4", "ipv6", "registered_domain")
print(
json.dumps(
{
"subdomain": ext.subdomain,
"domain": ext.domain,
"suffix": ext.suffix,
"fqdn": ext.fqdn,
"registered_domain": ext.registered_domain,
**dataclasses.asdict(ext),
**{prop: getattr(ext, prop) for prop in properties},
}
)
)
Expand Down

0 comments on commit bb75a7b

Please sign in to comment.