-
Notifications
You must be signed in to change notification settings - Fork 1
Wrapping Mastermind
Wrapping Mastermind was designed to be straightforward and simple to do. To accomplish this, Mastermind exposes two static configuration options on the CLI::Mastermind
object. Additionally, Mastermind automatically reads in the command line arguments when execute
is called.
#!/usr/bin/env ruby
require 'cli/mastermind'
require 'your_gem'
# This will set base_path to the root of your gem, assuming your executable is one directory down.
CLI::Mastermind.base_path = File.expand_path('..', __dir__)
# Assuming you've wrapped your tasks in a plot with the same name as the gem
CLI::Mastermind.base_plan = 'your_gem'
# Automatically load a masterplan from your gem
# This file will load _after_ all other masterplans
CLI::Mastermind.autoload_masterplan File.expand_path(File.join('..', 'lib', 'masterplan'), __dir__)
# Start Mastermind
CLI::Mastermind.execute
This script demonstrates all the options available to you outside of Masterplans and Plan files.
Starts Mastermind. This will do everything that normally happens when Mastermind is run from its executable.
You must call this method after setting your base path and plan for them to have effect.
Sets the base path used when discovering Planfiles. Base path checking happens when plan files are added to the configuration object. So, only Planfiles that reside under your base path will be queued for loading. This means you can use configuration printing (-C
) to test that your base path correctly finds your plans.
It's good practice to nest your actions underneath a plot to isolate your tasks from any others the user may have installed. However, this can cause problems if you want to wrap Mastermind in your own executable. This option allows you to specify a base plan that Mastermind will automatically select when it starts plan selection.
It should be noted that this selection is not effected by alias expansion. You must use the actual name of the plan when specifying the base plan; aliases will not work.
Queue a masterplan to be loaded after all other masterplans. If the path you give isn't absolute or doesn't point to a file, an exception will be raised.
Handy if you want to set default values for configuration options or setup internal configuration. Be careful using this to set up internal configuration as you may conflict with settings from other masterplans. If you have some configuration that absolutely must be set up a certain way, it probably shouldn't be in your masterplan.