Skip to content

Writing Plan Files

Chris Hall edited this page Mar 8, 2019 · 8 revisions

By default, planfiles use a very simple DSL that will feel familiar to anyone that's ever used Rake. The biggest difference between Rake (and similar tools) and Mastermind is that Mastermind has no support for dependent tasks or parallel tasks. If your workflow requires either of those things, Mastermind is probably not the tool you want to use. Or, rather, not the only tool you want to use.

Example:

plot :calculator do

  description 'Add numbers together'
  plan :add do |args|
    puts args.map(&:to_i).reduce(&:+)
  end

  description 'Multiply numbers together'
  plan :mutliply do |args|
    puts args.map(&:to_i).reduce(&:*)
  end

  description 'Perform an arbitrary calculation'
  plan :calculate, Calculator::Calculate
  set_alias :calc
end

Planfile DSL

plot name &block

Alias: namespace

Creates a Plan that contains children with the given name. This is similar to the namespace command in a Rakefile. The Plans created inside the block are added as children of this Plan.


description text

Alias: desc

Provides a description for the next Plan created. Plans created with plot can also have descriptions.


plan name, [class] [&block]

Alias task

Creates a Plan with the given name.

If passed a class, that class must implement the Plan interface. The easiest way to do this is to include CLI::Mastermind::Plan::Interface in your class.

If passed a block, that block is used to create an instance of CLI::Masterplan::Plan with the block as its action.

In either case, when called, any plan arguments are passed to the action as an array with no processing done. You can process these arguments however you like from there.


set_alias alias_name

Creates an alias for the most recently defined plan. IMPORTANT: Planfile aliases are defined after user aliases and cannot override them. Alias expansion only occurs during argument processing and cannot be used when programmaticly executing a plan.

This is provided as a convenience for use-cases when a particular alias is already well defined, such as when transitioning from a different tool.

For most other cases, it's recommended that you not define aliases for you plans and allow users to define aliases as they see fit.

For more information, see Alias Expansion


configuration

Alias: config

Access the main configuration object. Since configuration loading happens prior to plan file loading, you can access the configuration object inside your plan files. This can be useful for dynamically building plans.

Clone this wiki locally