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)


40
41
42
# File 'lib/cli/mastermind/arg_parse.rb', line 40

def ask?
  @ask
end

#display_plans?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/cli/mastermind/arg_parse.rb', line 24

def display_plans?
  !@pattern.nil?
end

#display_ui?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/cli/mastermind/arg_parse.rb', line 36

def display_ui?
  @display_ui
end

#dump_config?Boolean

Returns:

  • (Boolean)


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

def dump_config?
  @show_config
end

#get_next_plan_nameObject



32
33
34
# File 'lib/cli/mastermind/arg_parse.rb', line 32

def get_next_plan_name
  @mastermind_arguments.shift
end

#has_additional_plan_names?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/cli/mastermind/arg_parse.rb', line 28

def has_additional_plan_names?
  @mastermind_arguments.any?
end

#parserObject



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
# File 'lib/cli/mastermind/arg_parse.rb', line 52

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)


48
49
50
# File 'lib/cli/mastermind/arg_parse.rb', line 48

def resolve_callable_attributes?
  @call_blocks
end