You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There's actually two requests here, but given the overlap I thought it suitable to just raise a single issue:
Introduce a new type of plugin, condition plugins, that provide named, configurable conditions written in Python
Introduce a new directive accepting: condition(s) to evaluate and a list of tasks/actions to execute when true
Motivation
There are currently 3 plugins linked from the official documentation that provide a condition and a container of tasks to be executed based on the outcome (if, ifarch, ifplatform). Dotbot users have already adopted this type of plugin so the interest is clearly there.
The most flexible (and similar to this request) is the if plugin which takes a single shell command. Personally, there are at least a couple other conditions that I'd like to share with the community that aren't well suited to a shell one-liner.
Notably, all three of the plugins also share the same issue. They don't propagate defaults from the parent context (and scope any new defaults set to the child context).
I think it would be great to provide improved support for this pattern in the core dotbot project itself.
Examples
First, you can see below a couple options for a hypothetical new directive. I don't actually have a strong preference here. Whatever we think is least likely to conflict with a custom plugin name.
Next you can see a few variants of the condition. I actually think it makes sense to support all of these.
# For a string, it is interpreted as a shell command (providing consistency with the link directive's current if option)
- cond:
if: "command -v ansible"then:
- shell:
- 'echo "I found ansible in $PATH"'# For a dict, use each key to find the corresponding Condition plugin and pass the value as arguments
- cond:
if:
tty: trueplatform: 'arch'then:
- shell:
- 'echo "I am running in a TTY on ArchLinux!"'# An array is also supported for the same reasons as with dotbot tasks/actions.# It allows repeating a condition multiple times.
- cond:
if:
- decrypted: "./config/file/a"
- decrypted: "./config/file/b"
- 'command -v "program_requiring_sensitive_config"'then:
- shell:
- 'echo "I have everything i need to configure <program_requiring_sensitive_config>."'
I'm envisioning the condition plugins following the same pattern as those providing directives. A new test runner class would take the full condition and delegate to the appropriate condition plugins for evaluation.
Unlike Allow if on tasks #225 the only potential for collision would be the single new directive. Behavior of tasks/actions remains the same as it is today.
The if attribute in the current link plugin could also make use of the above conditions. As described above it would be backwards compatible.
Why not just implement this as a new plugin? Configuring dotbot/dotbot-plugins as submodules seems to complicate import resolution. It's much easier if the new Condition abstract base class is in the dotbot repository itself. I'm fairly new to python, so maybe there's a pattern I'm missing that would actually make this easier.
The text was updated successfully, but these errors were encountered:
@gnfzdz, the condition/if/then/else constructs are extremely readable, and having Python-based condition providers is the correct -- and portable -- way to address this. I run dotbot across multiple operating systems and shell environments; shelling out to an unknown shell to run a string blindly simply doesn't work.
There's actually two requests here, but given the overlap I thought it suitable to just raise a single issue:
Motivation
There are currently 3 plugins linked from the official documentation that provide a condition and a container of tasks to be executed based on the outcome (if, ifarch, ifplatform). Dotbot users have already adopted this type of plugin so the interest is clearly there.
The most flexible (and similar to this request) is the if plugin which takes a single shell command. Personally, there are at least a couple other conditions that I'd like to share with the community that aren't well suited to a shell one-liner.
Notably, all three of the plugins also share the same issue. They don't propagate defaults from the parent context (and scope any new defaults set to the child context).
I think it would be great to provide improved support for this pattern in the core dotbot project itself.
Examples
First, you can see below a couple options for a hypothetical new directive. I don't actually have a strong preference here. Whatever we think is least likely to conflict with a custom plugin name.
Next you can see a few variants of the condition. I actually think it makes sense to support all of these.
I'm envisioning the condition plugins following the same pattern as those providing directives. A new test runner class would take the full condition and delegate to the appropriate condition plugins for evaluation.
Other thoughts
if
on tasks #225 the only potential for collision would be the single new directive. Behavior of tasks/actions remains the same as it is today.The text was updated successfully, but these errors were encountered: