josephburnett / jd

JSON diff and patch
MIT License
826 stars 38 forks source link

Add a version flag #32

Closed iainelder closed 3 years ago

iainelder commented 3 years ago

I expect all my command line tools to have a simple way to check the version, such as the GNU standard --version option.

The standard --version option should direct the program to print information about its name, version, origin and legal status, all on standard output, and then exit successfully.

I see no way to get the version from jd with a successful exit.

jd without flags prints the version after a usage statement and exits with error code 1.

$ jd

Usage: jd [OPTION]... FILE1 [FILE2]
Diff and patch JSON files.

Prints the diff of FILE1 and FILE2 to STDOUT.
When FILE2 is omitted the second input is read from STDIN.
When patching (-p) FILE1 is a diff.

Options:
  -p        Apply patch FILE1 to FILE2 or STDIN.
  -o=FILE3  Write to FILE3 instead of STDOUT.
  -set      Treat arrays as sets.
  -mset     Treat arrays as multisets (bags).
  -setkeys  Keys to identify set objects
  -yaml     Read and write YAML instead of JSON.
  -port=N   Serve web UI on port N

Examples:
  jd a.json b.json
  cat b.json | jd a.json
  jd -o patch a.json b.json; jd patch a.json
  jd -set a.json b.json

Version: v1.3.0

$ echo $?
1

jd with the --version flag does not print the version and exits with error code 2.

$ jd --version
flag provided but not defined: -version
Usage of jd:
  -mset
        Arrays as multisets
  -o string
        Output file
  -p    Patch mode
  -port int
        Serve web UI on port
  -set
        Arrays as sets
  -setkeys string
        Keys to identify set objects
  -yaml
        Read and write YAML
$ echo $?
2
josephburnett commented 3 years ago

Good idea! https://github.com/josephburnett/jd/commit/425e20e83cf0a08c996696a920985be8d2eda41b

iainelder commented 3 years ago

@josephburnett Thanks! Can you make a new release that includes this option?

josephburnett commented 3 years ago

Sure. Here is the latest release which includes the --version flag: https://github.com/josephburnett/jd/releases/tag/v1.4.0

iainelder commented 3 years ago

Perfect, thanks @josephburnett :-)