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
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.
-
.autoload_masterplan(plan_file_path) ⇒ Object
Allows utilities wrapping Mastermind to specify planfiles that should be automatically loaded.
-
.base_path=(base_path) ⇒ Object
Allows utilities wrapping Mastermind to specify that only plans under a particular path should be loaded.
-
.base_plan=(base_plan) ⇒ Object
Allows utilities wrapping Mastermind to specify a top level plan without having to monkey with the incomming arguments.
-
.configuration ⇒ Object
Expose the configuration loaded during
execute
. -
.execute(cli_args = ARGV) ⇒ Object
Process incoming options and take an appropriate action.
- .gem_version ⇒ Object
- .plans ⇒ Object
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.
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/cli/mastermind.rb', line 105 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 |
.autoload_masterplan(plan_file_path) ⇒ Object
Allows utilities wrapping Mastermind to specify planfiles that should be automatically loaded. Plans loaded this way are loaded after all other planfiles and so should only be used to set default values.
40 41 42 43 44 45 46 |
# File 'lib/cli/mastermind.rb', line 40 def autoload_masterplan(plan_file_path) path = Pathname.new plan_file_path raise Error, "`#{plan_file_path}` is not an absolute path" unless path.absolute? raise Error, "`#{plan_file_path}` does not exist or is not a file" unless path.file? @autoloads ||= [] @autoloads << plan_file_path end |
.base_path=(base_path) ⇒ Object
Allows utilities wrapping Mastermind to specify that only plans under a particular path should be loaded.
27 28 29 |
# File 'lib/cli/mastermind.rb', line 27 def base_path=(base_path) @base_path = base_path end |
.base_plan=(base_plan) ⇒ Object
Allows utilities wrapping Mastermind to specify a top level plan without having to monkey with the incomming arguments.
33 34 35 |
# File 'lib/cli/mastermind.rb', line 33 def base_plan=(base_plan) @base_plan = base_plan end |
.configuration ⇒ Object
Expose the configuration loaded during execute
.
21 22 23 |
# File 'lib/cli/mastermind.rb', line 21 def configuration @config ||= spinner('Loading configuration') { Configuration.new @base_path } end |
.execute(cli_args = ARGV) ⇒ Object
Process incoming options and take an appropriate action. This is normally called by the mastermind executable.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/cli/mastermind.rb', line 50 def execute(cli_args=ARGV) @arguments = ArgParse.new(cli_args) enable_ui if @arguments.display_ui? frame('Mastermind') do if @autoloads && @autoloads.any? @autoloads.each { |masterplan| configuration.load_masterplan masterplan } end 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 |