Skip to main content

Consistent CLI config file modifier

Project description

Cocof

Build Status

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: 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 and JSON.

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]  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.

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 ]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cocof-1.0.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

cocof-1.0.0-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file cocof-1.0.0.tar.gz.

File metadata

  • Download URL: cocof-1.0.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for cocof-1.0.0.tar.gz
Algorithm Hash digest
SHA256 89b7b8a6d686a1234179f8377df2c2565a00ab202fbb29c60003b990c2bf9c7f
MD5 962c2fb8cdf83cbbd5959ee1489b1af0
BLAKE2b-256 e360b764d931051244e7ea0043963bfca988b7c112b787f4f2784a173ad70cd5

See more details on using hashes here.

File details

Details for the file cocof-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: cocof-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for cocof-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d411739370761eb119459b4073c416a96333a6359e5af4dc4232e22ea3f8b0f9
MD5 aba37f0d71140faefc2927182779019f
BLAKE2b-256 a8d6ceda73731e1dfa0d77ebafd757a48f9e516339beaaf0b38b4d2b1282697a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page