Class: Changelog::OptionParser
- Inherits:
-
Object
- Object
- Changelog::OptionParser
- Defined in:
- lib/changelog/option_parser.rb
Overview
Class responsible for parsing options and detecting arguments passed for Changelogko.
Defined Under Namespace
Classes: Options
Class Method Summary collapse
- .help_option(opts) ⇒ Object
- .no_archive_option(opts, options) ⇒ Object
- .option_parser(options) ⇒ Object
- .parse(argv) ⇒ Object
- .release_option(opts, options) ⇒ Object
- .type_option(opts, options) ⇒ Object
- .types_option(opts) ⇒ Object
Class Method Details
.help_option(opts) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/changelog/option_parser.rb', line 59 def self.help_option(opts) opts.on('-h', '--help', 'Show help.') do $stdout.puts opts $stdout.puts 'Adding a .changelogko file in the root of the working directory will allow to automatically ' \ 'append the contents of the file as options to every `changelogko` (or `cko`) command. ' \ 'For example, assume the .changelogko file contains "--no-archive". ' \ 'For every changelogko command, it will automatically append --no-archive, ' \ 'as such: bundle exec changelogko -r --no-archive.' raise ProcessEnded end end |
.no_archive_option(opts, options) ⇒ Object
53 54 55 56 57 |
# File 'lib/changelog/option_parser.rb', line 53 def self.no_archive_option(opts, ) opts.on('-A', '--no-archive', 'Do not archive the release after creating it.') do .no_archive = true end end |
.option_parser(options) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/changelog/option_parser.rb', line 19 def self.option_parser() ::OptionParser.new do |opts| opts. = "Usage: (changelogko|cko) [options]\nOptions:\n" release_option(opts, ) type_option(opts, ) types_option(opts) no_archive_option(opts, ) help_option(opts) end end |
.parse(argv) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/changelog/option_parser.rb', line 7 def self.parse(argv) = Options.new parser = option_parser() argv = ['-h'] if argv.empty? parser.parse!(argv) .title = argv.join(' ').strip.squeeze(' ').tr("\r\n", '') unless .release end |
.release_option(opts, options) ⇒ Object
31 32 33 34 35 |
# File 'lib/changelog/option_parser.rb', line 31 def self.release_option(opts, ) opts.on('-r', '--release', 'Create release from unreleased directory.') do .release = true end end |
.type_option(opts, options) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/changelog/option_parser.rb', line 37 def self.type_option(opts, ) type_desc = 'Type of changelog. Use -T, --types to display all available types.' opts.on('-t', '--type [title]', String, type_desc) do |value| .type = value end end |
.types_option(opts) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/changelog/option_parser.rb', line 44 def self.types_option(opts) opts.on('-T', '--types', 'List available types.') do TYPES.each do |type| $stdout.puts "#{type.name}#{type.description}" end raise ProcessEnded end end |