Module: GitProc::GitProcessOptions

Defined in:
lib/git-process/git_process_options.rb

Constant Summary collapse

DEBUG =
false

Instance Method Summary collapse

Instance Method Details

#descriptionObject



76
77
78
# File 'lib/git-process/git_process_options.rb', line 76

def description
  'Default description'
end

#empty_argv_ok?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/git-process/git_process_options.rb', line 81

def empty_argv_ok?
  true
end

#extend_opts(parser) ⇒ Object

noinspection RubyUnusedLocalVariable



87
88
89
# File 'lib/git-process/git_process_options.rb', line 87

def extend_opts(parser)
  # extension point - does nothing by default
end

#parse_cli(filename, argv) ⇒ Object



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
# File 'lib/git-process/git_process_options.rb', line 24

def parse_cli(filename, argv)
  parser = Trollop::Parser.new
  parser.version "#{filename} #{GitProc::Version::STRING}"

  parser.banner "#{summary}\n\n"
  parser.banner "\nUsage:\n    #{usage(filename)}\n\nWhere [options] are:"

  extend_opts(parser)
  standard_opts(parser)

  parser.banner "\n#{description}"

  opts = Trollop::with_standard_exception_handling parser do
    raise Trollop::HelpNeeded if ARGV.empty? and !empty_argv_ok?
    parser.parse argv
  end

  opts[:info] = false if opts[:verbose] || opts[:quiet]
  opts[:info] = true if opts[:info_given]

  post_parse(opts, argv)

  if DEBUG
    puts "\n\n#{opts.map { |k, v| "#{k}:#{v}" }.join(', ')}"
    puts "\nargs: #{argv.join(', ')}"
  end

  opts
end

#post_parse(opts, argv) ⇒ Object

noinspection RubyUnusedLocalVariable



93
94
95
# File 'lib/git-process/git_process_options.rb', line 93

def post_parse(opts, argv)
  # extension point - does nothing by default
end

#standard_opts(parser) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'lib/git-process/git_process_options.rb', line 55

def standard_opts(parser)
  parser.opt :info, 'Informational messages; show the major things this is doing', :default => true, :short => :none
  parser.opt :quiet, 'Quiet messages; only show errors', :short => :q
  parser.opt :verbose, 'Verbose messages; show lots of details on what this is doing', :short => :v
  parser.opt :version, "Print version (#{GitProc::Version::STRING}) and exit", :short => :none
  parser.opt :help, 'Show this message', :short => :h

  parser.conflicts :verbose, :info, :quiet
end

#summaryObject



66
67
68
# File 'lib/git-process/git_process_options.rb', line 66

def summary
  'Default summary'
end

#usage(filename) ⇒ Object



71
72
73
# File 'lib/git-process/git_process_options.rb', line 71

def usage(filename)
  "#{filename} [options]"
end