class PrChangelog::CLI
Used for the implementation of the exposed executable for this gem
Constants
- HELP_TEXT
Attributes
format[R]
from_reference[R]
strategy[R]
to_reference[R]
Public Class Methods
new(raw_args, releases = nil)
click to toggle source
# File lib/pr_changelog/cli.rb, line 42 def initialize(raw_args, releases = nil) args = Args.new(raw_args) raise HelpWanted if args.include_flags?('-h', '--help') @format = args.value_for('--format') || PrChangelog.config.default_format @strategy = args.value_for('--strategy') || PrChangelog.config.default_strategy @releases = releases || Releases.new @from_reference, @to_reference = args.last(2) @from_reference ||= @releases.last_release @to_reference ||= 'master' if args.include_flags?('-l', '--last-release') last_release_pair = @releases.last_release_pair raise CannotDetermineRelease if last_release_pair.length != 2 @from_reference, @to_reference = last_release_pair end return if @from_reference && @to_reference raise InvalidInputs end
Public Instance Methods
build_strategy()
click to toggle source
# File lib/pr_changelog/cli.rb, line 68 def build_strategy if strategy == 'merge' MergeCommitStrategy.new(from_reference, to_reference) elsif strategy == 'squash' SquashCommitStrategy.new(from_reference, to_reference) else raise "Strategy '#{strategy}' not recognized." end end
run()
click to toggle source
# File lib/pr_changelog/cli.rb, line 78 def run changes = NotReleasedChanges.new(build_strategy) puts "## Changes since #{from_reference} to #{to_reference} (#{strategy})\n\n" if format == 'pretty' puts changes.grouped_formatted_changelog else puts changes.formatted_changelog end end