|
3 | 3 | # Implements the strings:generate task. |
4 | 4 | namespace :strings do |
5 | 5 | desc 'Generate Puppet documentation with YARD.' |
6 | | - task :generate, :patterns, :debug, :backtrace, :markup, :json, :yard_args do |t, args| |
| 6 | + task :generate, [:patterns, :debug, :backtrace, :markup, :json, :markdown, :yard_args] do |t, args| |
7 | 7 | patterns = args[:patterns] |
8 | 8 | patterns = patterns.split if patterns |
9 | 9 | patterns ||= PuppetStrings::DEFAULT_SEARCH_PATTERNS |
|
14 | 14 | markup: args[:markup] || 'markdown', |
15 | 15 | } |
16 | 16 |
|
17 | | - # rubocop:disable Style/PreferredHashMethods |
18 | | - # `args` is a Rake::TaskArguments and has no key? method |
19 | | - options[:json] = args[:json] if args.has_key? :json |
| 17 | + raise("Error: Both JSON and Markdown output have been selected. Please select one.") if args[:json] == 'true' && args[:markdown] == 'true' |
| 18 | + |
| 19 | + # rubocop:disable Style/PreferredHashMethods |
| 20 | + # Because of Ruby, true and false from the args are both strings and both true. Here, |
| 21 | + # when the arg is set to false (or empty), set it to real false, else real true. Then, |
| 22 | + # if the arg is set simply to 'true', assume default behavior is expected and set the path |
| 23 | + # to nil to elicit that, else set to the path given. |
| 24 | + # @param [Hash] args from the Rake task cli |
| 25 | + # @param [Hash] options to send to the generate function |
| 26 | + # @param [Symbol] possible format option |
| 27 | + # @return nil |
| 28 | + def parse_format_option(args, options, format) |
| 29 | + if args.has_key? format |
| 30 | + options[format] = args[format] == 'false' || args[format].empty? ? false : true |
| 31 | + if options[format] |
| 32 | + options[:path] = args[format] == 'true' ? nil : args[format] |
| 33 | + end |
| 34 | + end |
| 35 | + end |
| 36 | + |
| 37 | + [:json,:markdown].each { |format| parse_format_option(args, options, format) } |
| 38 | + |
| 39 | + warn('yard_args behavior is a little dodgy, use at your own risk') if args[:yard_args] |
20 | 40 | options[:yard_args] = args[:yard_args].split if args.has_key? :yard_args |
21 | | - # rubocop:enable Style/PreferredHashMethods |
22 | 41 |
|
23 | 42 | PuppetStrings.generate(patterns, options) |
24 | 43 | end |
|
0 commit comments