Module: CLI::Mastermind
- Extended by:
- UserInterface
- Defined in:
- lib/cli/mastermind.rb,
lib/cli/mastermind/plan.rb,
lib/cli/mastermind/errors.rb,
lib/cli/mastermind/loader.rb,
lib/cli/mastermind/version.rb,
lib/cli/mastermind/arg_parse.rb,
lib/cli/mastermind/parent_plan.rb,
lib/cli/mastermind/configuration.rb,
lib/cli/mastermind/executable_plan.rb,
lib/cli/mastermind/loader/planfile_loader.rb
Overview
The main Mastermind module handles initial setup, user interaction, and final plan execution
Defined Under Namespace
Modules: Plan, UserInterface, VERSION Classes: ArgParse, Configuration, Error, ExecutablePlan, InvalidDirectoryError, InvalidPlanError, Loader, MissingConfigurationError, ParentPlan, UnsupportedFileTypeError
Class Method Summary collapse
-
.[](*plan_stack) ⇒ Object
Look up a specific plan by its name.
-
.add_argument(*args, &block) ⇒ Void
Convenience method for ArgParse.add_option.
-
.autoload_masterplan(masterplan_path) ⇒ Void
Allows utilities wrapping Mastermind to specify masterplans that should be automatically loaded.
-
.base_path=(base_path) ⇒ Void
Allows utilities wrapping Mastermind to specify that only plans under a particular path should be loaded.
-
.base_plan=(base_plan) ⇒ Void
Allows utilities wrapping Mastermind to specify a top level plan without having to monkey with the incomming arguments.
-
.configuration ⇒ Configuration
Lazy-load configuration object.
-
.execute(cli_args = ARGV) ⇒ Void
Process incoming options and take an appropriate action.
- .gem_version ⇒ Object
-
.plans ⇒ ParentPlan
Lazy-load the plans to be used by Mastermind.
Methods included from UserInterface
ask, capture_command_output, concurrently, confirm, enable_ui, frame, select, spinner, stylize, titleize, ui_enabled?
Class Method Details
.[](*plan_stack) ⇒ Object
Look up a specific plan by its name
Because plans also implement this method in a compatible way, there are three ways this method could be used:
1. List of arguments
* Mastermind['name', 'of', 'plans']
2. Space separated string
* Mastermind['name of plans']
3. Hash-like access
* Mastermind['name']['of']['plans']
All will provide the same plan.
GOTCHA: Be careful if your plan name includes a space!
While it’s entirely valid to have a plan name that inlcudes a space, you should avoid them if you plan to look up your plan using this method.
Plans with spaces in the name can be looked up using only the first form of this method.
145 146 147 148 149 150 151 152 153 154 |
# File 'lib/cli/mastermind.rb', line 145 def [](*plan_stack) # Allow for a single space-separated string if plan_stack.size == 1 and plan_stack.first.is_a?(String) plan_stack = plan_stack.first.split(' ') end plan_stack.compact.reduce(plans) do |plan, plan_name| plan[plan_name] end end |
.add_argument(*args, &block) ⇒ Void
Convenience method for ArgParse.add_option
61 62 63 |
# File 'lib/cli/mastermind.rb', line 61 def add_argument(*args, &block) ArgParse.add_option(*args, &block) end |
.autoload_masterplan(masterplan_path) ⇒ Void
Allows utilities wrapping Mastermind to specify masterplans that should be automatically loaded. Masterplans loaded this way are loaded after all others and so should only be used to set default values.
Adding a new autoload after configuration has been initialized will immediately load the new masterplan.
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/cli/mastermind.rb', line 74 def autoload_masterplan(masterplan_path) path = Pathname.new masterplan_path raise Error, "`#{masterplan_path}` is not an absolute path" unless path.absolute? raise Error, "`#{masterplan_path}` does not exist or is not a file" unless path.file? @autoloads ||= [] @autoloads << masterplan_path # Don't use configuration method here to avoid loading configuration early @config.load_masterplan masterplan_path unless @config.nil? end |
.base_path=(base_path) ⇒ Void
Allows utilities wrapping Mastermind to specify that only plans under a particular path should be loaded.
41 42 43 |
# File 'lib/cli/mastermind.rb', line 41 def base_path=(base_path) @base_path = base_path end |
.base_plan=(base_plan) ⇒ Void
Allows utilities wrapping Mastermind to specify a top level plan without having to monkey with the incomming arguments.
50 51 52 |
# File 'lib/cli/mastermind.rb', line 50 def base_plan=(base_plan) @base_plan = base_plan end |
.configuration ⇒ Configuration
Lazy-load configuration object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/cli/mastermind.rb', line 24 def configuration @config ||= spinner('Loading configuration') do Configuration.new(@base_path).tap do |config| # Load any autoloads if @autoloads && @autoloads.any? @autoloads.each { |masterplan| config.load_masterplan masterplan } end end end end |
.execute(cli_args = ARGV) ⇒ Void
Process incoming options and take an appropriate action. This is normally called by the mastermind executable.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/cli/mastermind.rb', line 90 def execute(cli_args=ARGV) @arguments = ArgParse.new(cli_args) enable_ui if @arguments.display_ui? frame('Mastermind') do if @arguments.dump_config? do_print_configuration exit 0 end if @arguments.display_plans? do_filtered_plan_display exit 0 end process_plan_names do_interactive_plan_selection until executable_plan_selected? if user_is_sure? execute_plan! else puts 'aborted!' end end end |
.gem_version ⇒ Object
4 5 6 |
# File 'lib/cli/mastermind/version.rb', line 4 def self.gem_version Gem::Version.new VERSION::STRING end |
.plans ⇒ ParentPlan
Lazy-load the plans to be used by Mastermind
159 160 161 |
# File 'lib/cli/mastermind.rb', line 159 def plans @plans ||= spinner('Loading plans') { Loader.load_all configuration.plan_files } end |