Module: ARGVEXT::MemoryCore

Defined in:
lib/argv/cms.rb

Instance Method Summary collapse

Instance Method Details

#add_help_msg(msg, *keys) ⇒ Object Also known as: add_help

Raises:

  • (ArgumentError)


5
6
7
8
9
10
# File 'lib/argv/cms.rb', line 5

def add_help_msg(msg,*keys)
  raise(ArgumentError,'invalid Message, must be String like object') unless msg.class <= String
  raise(ArgumentError,'invalid options given for this message, must be String like') if keys.any?{|e| !(e.class <= String) }
  __helper_msg_obj__.push [msg,keys.sort{|a,b| b.length <=> a.length }]
  return nil
end

#help_msg(basic_help_msg = true) ⇒ Object Also known as: show_help

> Basic help message is a boolean input, if false, there will be no basic options made like ‘-h’ ‘–help’



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/argv/cms.rb', line 22

def help_msg(basic_help_msg=true)
  init_basic_help_msg if !!basic_help_msg
  unless ::ARGV.options.select{ |e| __helper_flags__.include?(e) }.empty?

    tmp_ary= []
    __helper_msg_obj__.each do |ary|
      tmp_ary.push(ary[0])
      ary[1].each{|e| tmp_ary.push( ( e.to_s.length == 1 ? "-#{e}" : "--#{e}" ) )}
      tmp_ary.push('')
    end

    tmp_ary.each{ |element| element.include?('--') ? element.gsub!('--',"\t--") : element.gsub!('-',"\t -")}
    puts '',tmp_ary.join("\n"),''
    Process.exit!

  end
  return nil
end

#init_basic_help_msgObject



12
13
14
15
16
17
18
# File 'lib/argv/cms.rb', line 12

def init_basic_help_msg
  unless @init_done
    __helper_flags__.push *%W[ helper help h ]
    self.add_help_msg 'This will show you the help msg (this)',*__helper_flags__
    @init_done = true
  end
end