Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

command line tool #23

Open
ghost opened this issue Jul 18, 2016 · 1 comment
Open

command line tool #23

ghost opened this issue Jul 18, 2016 · 1 comment

Comments

@ghost
Copy link

ghost commented Jul 18, 2016

this would be useful as a command line tool as well, something like:

__main__.py

    #!/usr/bin/env python

    """
        Cli jsonmerge tool.
    """

    import argparse
    import json

    import jsonmerge

    ARGP = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawTextHelpFormatter,
    )
    ARGP.add_argument('files', nargs='+', help='Json Input Files')
    ARGP.add_argument('--merge-strategy', '-X', help='Root node merge strategy')

    def main(argp=None):
        if argp is None:
            argp = ARGP.parse_args()

        schema = dict()
        if argp.schema:
            with open(argp.schema) as file_handle:
                schema = json.load(file_handle)

        result = {}
        for file in argp.files:
            with open(file) as file_handle:
                result = jsonmerge.merge(result, json.load(file_handle), schema)

        print(json.dumps(result, indent=4))


    if __name__ == '__main__':
        main()

With

  • an entrypoint defined in the setup.sh
  • the ability to apply a merge strategy to the root node
  • ability to load a schema file as well?

That would be great.

@avian2
Copy link
Owner

avian2 commented Jul 19, 2016

Hi. If you can develop this feature and add tests and documentation, I would be happy to accept a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant