Coder Social home page Coder Social logo

lbconf's Introduction

lbconf

Command line utility for reading and writing JSON configuration files

Installation

Install using composer:

$ composer require learningbird/lbconf

Setup

Create an .lbconf meta-configuration file in your project root:

Example:

{
    "read": [
        "configurations/default.json"
    ],
    "write": "configurations/override.json"
}

File paths are relative to the location of the meta-config file.

The files in BOTH the read and write sections are read and merged, and the file in the write section is written to when using the set command.

Dynamic Configuration

For more dynamic configurations, an .lbconf.php file can be used. This file must return an array that has the same format as the .lbconf JSON file.

return [
    'read'  => glob('configurations/default/*.json),
    'write' => 'configurations/override.json',
];

Usage

The general usage pattern is:

lbconf <action> <key> [value]

Where <action> is one of: -g|--get, -s|--set, -d|--del, -k|--keys. If only a key is provided, the action is assumed to be --get, and can be omitted. If both a key and a value are provided, the action is assumed to be --set, and can be omitted.

Example:

$ lbconf --get database.host # Outputs "localhost"
$ lbconf database.host # Identical to above

$ lbconf --set database.host 127.0.0.1 # Sets database.host to  "127.0.0.1"
$ lbconf database.host 127.0.0.1 # Identical to above

-g|--get

Retrieve configuration values.

$ lbconf --get database
$ lbconf -g database # Short form
$ lbconf database # Implicit "--get" form

# Output:
# {
#     "host": "localhost,
#     "port": 3306,
#     "username": "prod-user"
# }

Traverse objects by passing dot-separated keys:

$ lbconf --get database.host # Outputs "localhost"

-s|--set

Set configuration values. Values will be written to the file specified by the write key in the .lbconf meta-configuration file.

$ lbconf --set database.username dev-user
$ lbconf -s database.username dev-user # Short form
$ lbconf database.username dev-user # Implicit "--set" form

Types will be inferred, unless explicitly specified:

$ lbconf --set database.port 3306 # Value is cast to int
$ lbconf --set database.port 3306 --type string # Value remains as string

-d|--del

Delete overriding configuration values:

$ lbconf --del database.username
$ lbconf -d database.username # Short form

Note that the key must exist in the write file for the deletion to be permitted. There is no way to delete a key that only exists in the read file. The only alternative is to set it to null, or some such value.

-k|--keys

Retrieve configuration value keys:

$ lbconf --keys database
$ lbconf -k database # Short form

# Output:
# [
#     "host",
#     "port",
#     "username"
# ]

Misc

Keys beginning with dashes

By default, a command argument that begins with a - is interpreted as an option. To avoid this behaviour, if a configuration key begins with a -, you can use -- to separate the command options from the arguments:

$ lbconf --get -- --get # Outputs value for key "--get"
$ lbconf --set -- --key value # Sets the value for "--key" to "value"

lbconf's People

Watchers

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