abantos / bolt

A task automation tool (similart to grunt) for Python
MIT License
15 stars 8 forks source link

Provide Command Line Switch to Bolt to Pass Context Properties and Values to the Execution Context #77

Open CurroRodriguez opened 7 years ago

CurroRodriguez commented 7 years ago

Story

As a task implementer, I want to allow my users to provide custom values to the execution context that I can retrieve, so I can customize behavior dynamically and not through a boltfile.py

Description

The idea here is to provide a mechanism through the parameters to bolt, so users can pass custom parameters dynamically instead of "hard-coding" them in the configuration file. As an example, someone can invoke Bolt the following way:

bolt -c my_property=my_value the-task

In this case, the executed task will be the-task and a property my_property will be added to the context object with the value my_value.

This functionality depends on the implementation of Issue #75

Some Thought About This

This feature occurred to me while using bolt with another project where certain things had to happen outside of bolt, and then some information had to be passed in to a bolt task. Initially, it sounded like a good idea, but the reality is Bolt provides a great configuration-as-code mechanism, which gives a lot of flexibility. For my particular problem, and since this functionality was not implemented, I decided that whatever had to happen will set an environment variable in the system where bolt will execute and the boltfile.py will read that environment variable and set the specific configuration value accordingly. Here is an example of what I did:

# Not showing the entire boltfile.

external_value = os.environ.get('MYENVVAR')

config {
    'my-task': {
        'setting': external_value
    }
}

The nice thing about this solution is that the value I needed becomes part of the configuration and not the context, which in my particular case makes total sense. Otherwise, I will have to put some logic in the task to get the value from the config, and then override it with the value in the context object if existed.

Having said that, I'll keep this issue because someone might come up with a good scenario to do this.

CurroRodriguez commented 7 years ago

Issue #77: Provide Command Line Switch to Bolt to Pass Context Properties and Values to the Execution Context