Class: Vcs::OptParse

Inherits:
Object
  • Object
show all
Defined in:
lib/vcs/opt_parse.rb

Constant Summary collapse

@@option_parser =
OptionParser.new do |o|
   o.banner = "Usage: vcs [options] <file>*"
  o.separator ''
   o.on('-c', '--vcs TYPE', VcsApp.all_vcs, 'Set your vcs') do |aVcs|
    Vcs.default = aVcs
  end
   o.on('-l', '--vcs-list', 'List all vcs') do |aVcs|
    STDERR.puts 'Vcs list:'
    VcsApp.all_vcs.each { |n| STDERR.puts "  - #{n}" }
    exit
  end
   o.on('--mk-alias', 'Put the result of this command in your .zshrc or .bashrc') do
    VcsApp.all_vcs.each do |n|
      n = n.to_s.downcase
      next if n == 'prcs'
      if VcsApp.path.executable?
        puts "alias #{n}=#{VcsApp.path}-#{n} ;"
      else
        puts "alias #{n}=vcs-#{n} ;"
      end
    end
    exit
  end
   o.on('-C', '--[no-]check', 'Check your vcs configuration') do |check|
    if check
      Vcs.new('vcs').call_conf_checkers
      exit
    end
  end
   o.on('-d', '--debug LEVEL', 'Set debug level') do |severity|
    logger.level = Logger.const_get(severity.upcase)
  end
   o.on_tail('-h', '--help', 'Show this message') do |test|
    STDERR.puts o
    STDERR.puts "\n\nReport bugs to <[email protected]>."
    exit
  end
   o.on_tail('--version', 'Show version') do
    STDOUT.puts "Vcs version: #{Vcs::Version.major_minor} (#{Vcs::Version.tag.pretty_string})"
    exit
  end
 end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOptParse

Returns a new instance of OptParse.



13
14
15
# File 'lib/vcs/opt_parse.rb', line 13

def initialize
  @option_parser = @@option_parser.dup
end

Instance Attribute Details

#option_parserObject (readonly)

Returns the value of attribute option_parser.



11
12
13
# File 'lib/vcs/opt_parse.rb', line 11

def option_parser
  @option_parser
end

Instance Method Details

#parse(argv) ⇒ Object



21
22
23
# File 'lib/vcs/opt_parse.rb', line 21

def parse ( argv )
  @option_parser.parse argv
end

#parse!(argv) ⇒ Object



17
18
19
# File 'lib/vcs/opt_parse.rb', line 17

def parse! ( argv )
  @option_parser.parse! argv
end

#to_sObject



25
26
27
# File 'lib/vcs/opt_parse.rb', line 25

def to_s
  @option_parser.to_s
end