Class: CLI::Mastermind::ArgParse

Inherits:
Object
  • Object
show all
Defined in:
lib/cli/mastermind/arg_parse.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#patternObject (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_argumentsObject (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

Returns:

  • (Boolean)


59
60
61
# File 'lib/cli/mastermind/arg_parse.rb', line 59

def ask?
  @ask
end

#display_plans?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/cli/mastermind/arg_parse.rb', line 43

def display_plans?
  !@pattern.nil?
end

#display_ui?Boolean

Returns:

  • (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|
    expand_argument(config, argument)
  end

  @plan_arguments = @alias_arguments + @plan_arguments

  @mastermind_arguments.flatten!
  nil # prevent @mastermind_arguments from leaking
end

#dump_config?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/cli/mastermind/arg_parse.rb', line 63

def dump_config?
  @show_config
end

#get_next_plan_nameObject



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

Returns:

  • (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

#parserObject



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.banner = '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

Returns:

  • (Boolean)


67
68
69
# File 'lib/cli/mastermind/arg_parse.rb', line 67

def resolve_callable_attributes?
  @call_blocks
end