Class: CLI::Mastermind::ArgParse
- Inherits:
-
Object
- Object
- CLI::Mastermind::ArgParse
- Defined in:
- lib/cli/mastermind/arg_parse.rb
Instance Attribute Summary collapse
-
#pattern ⇒ Object
readonly
When set, used to display available plans.
-
#plan_arguments ⇒ Object
readonly
Passed as-is into plans.
Instance Method Summary collapse
- #ask? ⇒ Boolean
- #display_plans? ⇒ Boolean
- #display_ui? ⇒ Boolean
- #do_command_expansion!(config) ⇒ Object
- #dump_config? ⇒ Boolean
- #get_next_plan_name ⇒ Object
- #has_additional_plan_names? ⇒ Boolean
-
#initialize(arguments = ARGV) ⇒ ArgParse
constructor
A new instance of ArgParse.
-
#insert_base_plan!(base_plan) ⇒ Object
Adds the given base plan to the beginning of the arguments array.
- #parser ⇒ Object
- #resolve_callable_attributes? ⇒ Boolean
Constructor Details
#initialize(arguments = ARGV) ⇒ ArgParse
Returns a new instance of ArgParse.
14 15 16 17 18 19 20 21 22 |
# File 'lib/cli/mastermind/arg_parse.rb', line 14 def initialize(arguments=ARGV) @initial_arguments = arguments @ask = true @display_ui = true @show_config = false @call_blocks = false parse_arguments end |
Instance Attribute Details
#pattern ⇒ Object (readonly)
When set, used to display available plans
6 7 8 |
# File 'lib/cli/mastermind/arg_parse.rb', line 6 def pattern @pattern end |
#plan_arguments ⇒ Object (readonly)
Passed as-is into plans
12 13 14 |
# File 'lib/cli/mastermind/arg_parse.rb', line 12 def plan_arguments @plan_arguments end |
Instance Method Details
#ask? ⇒ Boolean
59 60 61 |
# File 'lib/cli/mastermind/arg_parse.rb', line 59 def ask? @ask end |
#display_plans? ⇒ Boolean
43 44 45 |
# File 'lib/cli/mastermind/arg_parse.rb', line 43 def display_plans? !@pattern.nil? end |
#display_ui? ⇒ Boolean
55 56 57 |
# File 'lib/cli/mastermind/arg_parse.rb', line 55 def display_ui? @display_ui end |
#do_command_expansion!(config) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/cli/mastermind/arg_parse.rb', line 24 def do_command_expansion!(config) @alias_arguments = [] @mastermind_arguments.map! do |argument| (config, argument) end @plan_arguments = @alias_arguments + @plan_arguments @mastermind_arguments.flatten! nil # prevent @mastermind_arguments from leaking end |
#dump_config? ⇒ Boolean
63 64 65 |
# File 'lib/cli/mastermind/arg_parse.rb', line 63 def dump_config? @show_config end |
#get_next_plan_name ⇒ Object
51 52 53 |
# File 'lib/cli/mastermind/arg_parse.rb', line 51 def get_next_plan_name @mastermind_arguments.shift end |
#has_additional_plan_names? ⇒ Boolean
47 48 49 |
# File 'lib/cli/mastermind/arg_parse.rb', line 47 def has_additional_plan_names? @mastermind_arguments.any? end |
#insert_base_plan!(base_plan) ⇒ Object
Adds the given base plan to the beginning of the arguments array
38 39 40 41 |
# File 'lib/cli/mastermind/arg_parse.rb', line 38 def insert_base_plan!(base_plan) @mastermind_arguments.unshift base_plan nil # prevent @mastermind_arguments from leaking end |
#parser ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/cli/mastermind/arg_parse.rb', line 71 def parser @parser ||= OptionParser.new do |opt| opt. = 'Usage: mastermind [--help, -h] [--plans[ PATTERN], --tasks[ PATTERN], -T [PATTERN], -P [PATTERN] [PLAN[, PLAN[, ...]]] -- [PLAN ARGUMENTS]' opt.on('--help', '-h', 'Display this help') do puts opt exit end opt.on('-A', '--no-ask', "Don't ask before executing a plan") do @ask = false end opt.on('-U', '--no-fancy-ui', "Don't display the fancy UI") do @display_ui = false end opt.on('--plans [PATTERN]', '--tasks [PATTERN]', '-P', '-T', 'Display plans. Optional pattern is used to filter the returned plans.') do |pattern| @pattern = Regexp.new(pattern || '.') end opt.on('-C', '--show-configuration', 'Load configuration and print final values. Give multiple times to resolve lazy attributes as well.') do @call_blocks = @show_config @show_config = true end end end |
#resolve_callable_attributes? ⇒ Boolean
67 68 69 |
# File 'lib/cli/mastermind/arg_parse.rb', line 67 def resolve_callable_attributes? @call_blocks end |