Class: GitlogMD::ArgumentParser
- Inherits:
-
Object
- Object
- GitlogMD::ArgumentParser
- Defined in:
- lib/gitlog-md/argument_parser.rb
Constant Summary collapse
- DEFAULTS =
{ :output_file => 'HISTORY.md', :branch => 'master', :repo_dir => '.', }
Instance Method Summary collapse
-
#initialize ⇒ ArgumentParser
constructor
A new instance of ArgumentParser.
-
#parse(args = ARGV) ⇒ Hash
Parse an array of arguments into a Hash of options, use default values for unset arguments.
-
#usage ⇒ String
Generate a string representing the supported arguments.
Constructor Details
#initialize ⇒ ArgumentParser
Returns a new instance of ArgumentParser.
12 13 14 15 16 17 18 19 20 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 |
# File 'lib/gitlog-md/argument_parser.rb', line 12 def initialize = {} @optparse = OptionParser.new do | opts | # Set a banner opts. = "Usage: #{File.basename($0)} [options...]" opts.on "-o", "--output-file FILE", "File to write MarkDown output to", "(default #{DEFAULTS[:output_file]})" do |file| [:output_file] = file end opts.on "-b", "--branch BRANCH", "Branch to read git log history from", "(default #{DEFAULTS[:branch]})" do |file| [:branch] = file end opts.on "-r", "--repo-dir DIR", "Path to github repo", "(default #{DEFAULTS[:repo_dir]})" do |file| [:repo_dir] = file end opts.on("--version", "Report currently running version of GitlogMD" ) do [:version] = true end opts.on("--help", "Display this screen" ) do [:help] = true end end end |
Instance Method Details
#parse(args = ARGV) ⇒ Hash
Parse an array of arguments into a Hash of options, use default values for unset arguments
58 59 60 61 |
# File 'lib/gitlog-md/argument_parser.rb', line 58 def parse( args = ARGV ) @optparse.parse(args) DEFAULTS.merge() end |
#usage ⇒ String
Generate a string representing the supported arguments
70 71 72 |
# File 'lib/gitlog-md/argument_parser.rb', line 70 def usage @optparse.help end |