(maint) actually update rake task
This commit is contained in:
parent
567ee8aac9
commit
dde16375d0
|
@ -3,7 +3,7 @@ require 'puppet-strings'
|
||||||
# Implements the strings:generate task.
|
# Implements the strings:generate task.
|
||||||
namespace :strings do
|
namespace :strings do
|
||||||
desc 'Generate Puppet documentation with YARD.'
|
desc 'Generate Puppet documentation with YARD.'
|
||||||
task :generate, :patterns, :debug, :backtrace, :markup, :json, :markdown, :yard_args do |t, args|
|
task :generate, [:patterns, :debug, :backtrace, :markup, :json, :markdown, :yard_args] do |t, args|
|
||||||
patterns = args[:patterns]
|
patterns = args[:patterns]
|
||||||
patterns = patterns.split if patterns
|
patterns = patterns.split if patterns
|
||||||
patterns ||= PuppetStrings::DEFAULT_SEARCH_PATTERNS
|
patterns ||= PuppetStrings::DEFAULT_SEARCH_PATTERNS
|
||||||
|
@ -14,12 +14,30 @@ namespace :strings do
|
||||||
markup: args[:markup] || 'markdown',
|
markup: args[:markup] || 'markdown',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
raise("Error: Both JSON and Markdown output have been selected. Please select one.") if args[:json] == 'true' && args[:markdown] == 'true'
|
||||||
|
|
||||||
# rubocop:disable Style/PreferredHashMethods
|
# rubocop:disable Style/PreferredHashMethods
|
||||||
# `args` is a Rake::TaskArguments and has no key? method
|
# Because of Ruby, true and false from the args are both strings and both true. Here,
|
||||||
options[:json] = args[:json] if args.has_key? :json
|
# when the arg is set to false (or empty), set it to real false, else real true. Then,
|
||||||
options[:markdown] = args[:markdown] if args.has_key? :markdown
|
# if the arg is set simply to 'true', assume default behavior is expected and set the path
|
||||||
|
# to nil to elicit that, else set to the path given.
|
||||||
|
# @param [Hash] args from the Rake task cli
|
||||||
|
# @param [Hash] options to send to the generate function
|
||||||
|
# @param [Symbol] possible format option
|
||||||
|
# @return nil
|
||||||
|
def parse_format_option(args, options, format)
|
||||||
|
if args.has_key? format
|
||||||
|
options[format] = args[format] == 'false' || args[format].empty? ? false : true
|
||||||
|
if options[format]
|
||||||
|
options[:path] = args[format] == 'true' ? nil : args[format]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
[:json,:markdown].each { |format| parse_format_option(args, options, format) }
|
||||||
|
|
||||||
|
warn('yard_args behavior is a little dodgy, use at your own risk') if args[:yard_args]
|
||||||
options[:yard_args] = args[:yard_args].split if args.has_key? :yard_args
|
options[:yard_args] = args[:yard_args].split if args.has_key? :yard_args
|
||||||
# rubocop:enable Style/PreferredHashMethods
|
|
||||||
|
|
||||||
PuppetStrings.generate(patterns, options)
|
PuppetStrings.generate(patterns, options)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue