Options#print_options: tell don't ask
This commit is contained in:
parent
1fac4efe47
commit
5bb4d51b96
|
@ -1,10 +1,10 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require_relative "../octo_fetcher"
|
require "github_changelog_generator/octo_fetcher"
|
||||||
require_relative "generator_generation"
|
require "github_changelog_generator/generator/generator_generation"
|
||||||
require_relative "generator_fetcher"
|
require "github_changelog_generator/generator/generator_fetcher"
|
||||||
require_relative "generator_processor"
|
require "github_changelog_generator/generator/generator_processor"
|
||||||
require_relative "generator_tags"
|
require "github_changelog_generator/generator/generator_tags"
|
||||||
|
|
||||||
module GitHubChangelogGenerator
|
module GitHubChangelogGenerator
|
||||||
# Default error for ChangelogGenerator
|
# Default error for ChangelogGenerator
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "delegate"
|
require "delegate"
|
||||||
|
require "github_changelog_generator/helper"
|
||||||
|
|
||||||
module GitHubChangelogGenerator
|
module GitHubChangelogGenerator
|
||||||
# This class wraps Options, and knows a list of known options. Others options
|
# This class wraps Options, and knows a list of known options. Others options
|
||||||
# will raise exceptions.
|
# will raise exceptions.
|
||||||
|
@ -90,12 +92,27 @@ module GitHubChangelogGenerator
|
||||||
self[:require].each { |f| require f }
|
self[:require].each { |f| require f }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Pretty-prints a censored options hash, if :verbose.
|
||||||
|
def print_options
|
||||||
|
return unless self[:verbose]
|
||||||
|
Helper.log.info "Using these options:"
|
||||||
|
pp(censored_values)
|
||||||
|
puts ""
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def values
|
def values
|
||||||
__getobj__
|
__getobj__
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns a censored options hash.
|
||||||
|
#
|
||||||
|
# @return [Hash] The GitHub `:token` key is censored in the output.
|
||||||
|
def censored_values
|
||||||
|
values.clone.tap { |opts| opts[:token] = opts[:token].nil? ? "No token used" : "hidden value" }
|
||||||
|
end
|
||||||
|
|
||||||
def unsupported_options
|
def unsupported_options
|
||||||
values.keys - KNOWN_OPTIONS
|
values.keys - KNOWN_OPTIONS
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
|
|
||||||
require "optparse"
|
require "optparse"
|
||||||
require "pp"
|
require "pp"
|
||||||
require_relative "version"
|
require "github_changelog_generator/version"
|
||||||
require_relative "helper"
|
require "github_changelog_generator/helper"
|
||||||
|
|
||||||
module GitHubChangelogGenerator
|
module GitHubChangelogGenerator
|
||||||
class Parser
|
class Parser
|
||||||
|
@ -22,30 +22,17 @@ module GitHubChangelogGenerator
|
||||||
|
|
||||||
abort(parser.banner) unless options[:user] && options[:project]
|
abort(parser.banner) unless options[:user] && options[:project]
|
||||||
|
|
||||||
print_options(options)
|
options.print_options
|
||||||
|
|
||||||
options
|
options
|
||||||
end
|
end
|
||||||
|
|
||||||
# Pretty-print the parsed options.
|
|
||||||
#
|
|
||||||
# The GitHub `:token` key is censored in the output.
|
|
||||||
#
|
|
||||||
# @param options [Options] The options to display
|
|
||||||
# @option options [Boolean] :verbose If false this method does nothing
|
|
||||||
def self.print_options(options)
|
|
||||||
return unless options[:verbose]
|
|
||||||
|
|
||||||
Helper.log.info "Using these options:"
|
|
||||||
pp(options.clone.tap { |opts| opts[:token] = opts[:token].nil? ? "No token used" : "hidden value" })
|
|
||||||
puts ""
|
|
||||||
end
|
|
||||||
|
|
||||||
# Setup parsing options
|
# Setup parsing options
|
||||||
#
|
#
|
||||||
# @param options [Options]
|
# @param options [Options]
|
||||||
|
# @return [OptionParser]
|
||||||
def self.setup_parser(options)
|
def self.setup_parser(options)
|
||||||
parser = OptionParser.new do |opts| # rubocop:disable Metrics/BlockLength
|
OptionParser.new do |opts| # rubocop:disable Metrics/BlockLength
|
||||||
opts.banner = "Usage: github_changelog_generator [options]"
|
opts.banner = "Usage: github_changelog_generator [options]"
|
||||||
opts.on("-u", "--user [USER]", "Username of the owner of target GitHub repo") do |last|
|
opts.on("-u", "--user [USER]", "Username of the owner of target GitHub repo") do |last|
|
||||||
options[:user] = last
|
options[:user] = last
|
||||||
|
@ -197,7 +184,6 @@ module GitHubChangelogGenerator
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
parser
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# @return [Options] Default options
|
# @return [Options] Default options
|
||||||
|
|
Loading…
Reference in New Issue
Block a user