This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: json.tool ought to have a help flag
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, berker.peksag, martin.panter, pitrou, python-dev, rhettinger
Priority: normal Keywords: easy, patch

Created on 2014-03-20 18:56 by benjamin.peterson, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue21000.diff berker.peksag, 2014-03-20 19:19 review
issue21000_v2.diff berker.peksag, 2014-03-21 18:03 review
Messages (7)
msg214261 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2014-03-20 18:56
I current get this behavior:
% python3 -m json.tool -h
Traceback (most recent call last):
  File "/usr/lib64/python3.3/runpy.py", line 160, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib64/python3.3/runpy.py", line 73, in _run_code
    exec(code, run_globals)
  File "/usr/lib64/python3.3/json/tool.py", line 40, in <module>
    main()
  File "/usr/lib64/python3.3/json/tool.py", line 21, in main
    infile = open(sys.argv[1], 'r')
FileNotFoundError: [Errno 2] No such file or directory: '-h'

Instead of that, json.tool should show a helpful message expalining what it does in response to the -h or --help flags.
msg214367 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2014-03-21 14:12
Very nice, but your help message still doesn't explain what json.tool does. :)
msg214369 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-03-21 14:27
Perhaps this thing should use argparse?
msg214395 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2014-03-21 18:03
Here's a new patch. Changes:
- Updated the output of -h option
- Added documentation
- Switched to argparse
msg214413 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2014-03-21 23:17
This looks like a nice improvement.
msg214439 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2014-03-22 04:17
Thanks a lot for the excellent patch!
msg214440 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-03-22 04:17
New changeset a2ad16e86e60 by Benjamin Peterson in branch 'default':
improve the command-line interface of json.tool (closes #21000)
http://hg.python.org/cpython/rev/a2ad16e86e60
History
Date User Action Args
2022-04-11 14:58:00adminsetgithub: 65199
2014-03-22 04:17:58python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg214440

resolution: fixed
stage: patch review -> resolved
2014-03-22 04:17:40benjamin.petersonsetmessages: + msg214439
2014-03-21 23:17:21rhettingersetnosy: + rhettinger
messages: + msg214413
2014-03-21 18:03:38berker.peksagsetfiles: + issue21000_v2.diff

messages: + msg214395
2014-03-21 14:27:05pitrousetnosy: + pitrou
messages: + msg214369
2014-03-21 14:12:58benjamin.petersonsetmessages: + msg214367
2014-03-21 07:20:53berker.peksagsetnosy: + berker.peksag
2014-03-21 00:31:07martin.pantersetnosy: + martin.panter
2014-03-20 19:19:48berker.peksagsetfiles: + issue21000.diff
keywords: + patch
stage: needs patch -> patch review
2014-03-20 18:56:04benjamin.petersoncreate