Class: Morpheus::Cli::OptionParser

Inherits:
OptionParser
  • Object
show all
Defined in:
lib/morpheus/cli/option_parser.rb

Overview

an enhanced OptionParser not used yet, maybe ever =o

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

Returns the value of attribute footer.



10
11
12
# File 'lib/morpheus/cli/option_parser.rb', line 10

def footer
  @footer
end

#hidden_optionsObject

Array of option names to keep out of help message



13
14
15
# File 'lib/morpheus/cli/option_parser.rb', line 13

def hidden_options
  @hidden_options
end

Instance Method Details

#add_hidden_option(opt_name) ⇒ Object



58
59
60
61
62
63
64
65
66
67
# File 'lib/morpheus/cli/option_parser.rb', line 58

def add_hidden_option(opt_name)
  opt_array = [opt_name].flatten.compact
  @hidden_options ||= []
  opt_array.each do |val|
    if !@hidden_options.include?(val)
      @hidden_options << val
    end
  end
  @hidden_options
end

#full_help_messageObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/morpheus/cli/option_parser.rb', line 21

def full_help_message
  out = ""
  #out << original_to_s
  if banner
    out << "#{banner}".sub(/\n?\z/, "\n")
  end
  if !self.to_a.empty?
    #out << "Options:\n"
    # the default way..
    # out << summarize().join("")

    # super hacky, should be examining the option, not the fully formatted description
    my_summaries = summarize()
    summarize().each do |opt_description|
      is_hidden = (@hidden_options || []).find { |hidden_switch|
        # opt_description.include?("--#{hidden_switch}")
        if hidden_switch.start_with?("-")
          opt_description.to_s.strip.start_with?("#{hidden_switch} ")
        else
          opt_description.to_s.strip.start_with?("--#{hidden_switch} ")
        end
      }
      if !is_hidden
        out  << opt_description
      end
    end
  end
  if footer
    # nice_footer = footer.split("\n").collect {|line| "#{summary_indent}#{line}" }.join("\n")
    nice_footer = footer
    out << "\n"
    out << "#{nice_footer}".sub(/\n?\z/, "\n")
    # out << "\n"
  end
  out
end

#original_to_sObject



15
# File 'lib/morpheus/cli/option_parser.rb', line 15

alias :original_to_s :to_s

#to_sObject



17
18
19
# File 'lib/morpheus/cli/option_parser.rb', line 17

def to_s
  full_help_message
end