configirl CLI

configirl ships with built-in command line interface allows developer to easily integrate Python declartion config file with Shell Script or Command Line interface.

You can type these commands to get help info for you:

$ configirl -h
$ configirl read-json-value -h
$ configirl get-config-value -h
$ configirl import-config-value -h

read-json-value sub command

Example:

$ PROJECT_NAME="$(configirl read-json-value --path tests/config-final-for-python.json --field PROJECT_NAME)"

is equivalent to:

$ PROJECT_NAME="$(cat tests/config-final-for-python.json | jq '.PROJECT_NAME' -r)"

And it also supports json_path with dot notation.

However, configirl can read JSON file WITH COMMENTS like:

// some comments
{
    "PROJECT_NAME": "my_project" // some comments
}

get-config-value sub command

configirl get-config-value allows you to import a config declaration python module, construct a new config object and returns the value in specific field. The common usage is to reference the return value of a custom python function. Note, the module has to be importable in your current environment.

Example:

The python declaration file:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# -*- coding: utf-8 -*-

from configirl import ConfigClass, Constant, Derivable


class Config(ConfigClass):
    PROJECT_NAME = Constant(default="my_devops")
    PROJECT_NAME_SLUG = Derivable()

    @PROJECT_NAME_SLUG.getter
    def get_PROJECT_NAME_SLUG(self):
        return self.PROJECT_NAME.get_value().replace("_", "-")

    STAGE = Constant(default="dev")

    ENVIRONMENT_NAME = Derivable()

    @ENVIRONMENT_NAME.getter
    def get_ENVIRONMENT_NAME(self):
        return "{}-{}".format(self.PROJECT_NAME_SLUG.get_value(), self.STAGE.get_value())

    def is_prod_runtime(self):
        return False

    _version = "0.0.1"

Invoke the command:

$ ENVIRONMENT_NAME="$(configirl read-json-value --path tests/config-final-for-python.json --field PROJECT_NAME)"
get-config-value --module configirl.tests.config.Config --field "ENVIRONMENT_NAME"

This command is equivalent to:

# -*- coding: utf-8 -*-
# content of test.py

from configirl.tests.config import Config

config = Config()
print(config.ENVIRONMENT_NAME.get_value())
$ ENVIRONMENT_NAME="$(python test.py)"

import-config-value sub command

configirl import-config-value is similar to get-config-value. The only difference is that it doesn’t requires to be able to import globally. You can spe

allows you to import a config declaration python module, construct a new config object and returns the value in specific field. The common usage is to reference the return value of a custom python function. Note, the module has to be importable in your current environment.

Example:

The python declaration file:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# -*- coding: utf-8 -*-

from configirl import ConfigClass, Constant, Derivable


class Config(ConfigClass):
    PROJECT_NAME = Constant(default="my_devops")
    PROJECT_NAME_SLUG = Derivable()

    @PROJECT_NAME_SLUG.getter
    def get_PROJECT_NAME_SLUG(self):
        return self.PROJECT_NAME.get_value().replace("_", "-")

    STAGE = Constant(default="dev")

    ENVIRONMENT_NAME = Derivable()

    @ENVIRONMENT_NAME.getter
    def get_ENVIRONMENT_NAME(self):
        return "{}-{}".format(self.PROJECT_NAME_SLUG.get_value(), self.STAGE.get_value())

    def is_prod_runtime(self):
        return False

    _version = "0.0.1"

Invoke the command:

$ ENVIRONMENT_NAME="$(configirl import-config-value --sys_path /path-to/configirl-project --module configirl.tests.config.Config --field "ENVIRONMENT_NAME")"