Giter Site home page Giter Site logo

cocof-py's Introduction

Cocof

Build Status PyPI version

Cocof, short for consistent config file, is a python module that allows the modification of different key-value config files on the comand line.

Most importantly: For YAML and TOML it It will keep line breaks and comments the same. So the file will look more or less like the original (depending on the operations on it of course).

Currently supported formats are TOML, YAML, JSON and PLIST.

Install

$ pip install cocof

Usage

$ cocof --help
Usage: cocof [OPTIONS] FILEPATH JSONPATCH

  Cocof runs the provided 'jsonpatch' modifications on the configuration
  file given with the 'filepath' argument. Use the '--format' option to tell
  the file format. If not given cocof will try to guess the file format
  based on the file extension. Use '-' as filepath for stdin, in which case
  the output goes to stdout and you must provide the format of the data via
  the '--format' option.

Options:
  -f, --format [toml|yaml|json|plist]
                                  The format of the file. Obligatory if
                                  filepath is '-' (stdin).
  --help                          Show this message and exit.

Cocof takes a file path and a JSON patch string as arguments. It then modifies the datastructure given by the file's content accordingly and writies it back to the same file (in-place editing). You can also tell cocof to read from stdin, in which case it will output it's result to stdout. TOML, YAML and JSON expect their content to be utf-8 encoded. PLIST expects either an utf-8 encoded xml content or binary content.

Examples

# example.toml
title = "Example"

[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00 # Inline comment

[database]
server = "192.168.1.1"
ports = [ 8001, 8001, 8002 ]

Using {"op": "add", "path": "/subtitle", "value": "Sub"} as modification yields:

$ cocof ./example.toml '[{"op": "add", "path": "/subtitle", "value": "Sub"}]'`
$ cat ./example.toml
# example.toml
title = "Example"
subtitle = "Sub"

[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00 # Inline comment

[database]
server = "192.168.1.1"
ports = [ 8001, 8001, 8002 ]

cocof-py's People

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.