How to compare keys in yaml files?

后端 未结 4 952
醉梦人生
醉梦人生 2021-02-14 15:27

There are two ruby on rails internationalization yaml files. One file is complete and another one is with missing keys. How can I compare two yaml files and see missing keys in

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-14 16:12

    I couldn't find a fast tool to do that. I decided to write my own tool for this.

    You can install it with cabal:

    $ cabal update
    $ cabal install yamlkeysdiff
    

    Then you can diff two files this way:

    $ yamlkeysdiff file1.yml file2.yml
    > missing key in file2
    < missing key in file1
    

    You can also compare two subsets of the files:

    $ yamlkeysdiff "file1.yml#key:subkey" "file2.yml#otherkey"
    

    It behaves exactly like diff, you can do this:

    $ yamlkeysdiff file1.yml file2.yml && echo Is the same || echo Is different
    

提交回复
热议问题