Class: Abide::CLI::SceValidatePuppetStrings

Inherits:
AbideCommand
  • Object
show all
Defined in:
lib/abide_dev_utils/cli/sce.rb

Constant Summary collapse

CMD_NAME =
'puppet-strings'
CMD_SHORT =
'Validates the Puppet Strings documentation'
CMD_LONG =
'Validates the Puppet Strings documentation'

Constants included from AbideDevUtils::Config

AbideDevUtils::Config::DEFAULT_PATH

Instance Method Summary collapse

Methods inherited from AbideCommand

#deprecated?, #on_after_add

Methods included from AbideDevUtils::Config

config_section, #config_section, fetch, #fetch, to_h, #to_h

Constructor Details

#initializeSceValidatePuppetStrings

Returns a new instance of SceValidatePuppetStrings.



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/abide_dev_utils/cli/sce.rb', line 225

def initialize
  super(CMD_NAME, CMD_SHORT, CMD_LONG, takes_commands: false)
  options.on('-v', '--verbose', 'Verbose output') do
    @data[:verbose] = true
  end
  options.on('-q', '--quiet', 'Quiet output') do
    @data[:quiet] = true
  end
  options.on('-f [FORMAT]', '--format [FORMAT]', 'Format for output (text, json, yaml)') do |f|
    @data[:format] = f
  end
  options.on('-o [FILE]', '--out-file [FILE]', 'Path to save the updated config file') do |o|
    @data[:out_file] = o
  end
  options.on('-s', '--strict', 'Exits with exit code 1 if there are any warnings') do
    @data[:strict] = true
  end
end

Instance Method Details

#executeObject



244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/abide_dev_utils/cli/sce.rb', line 244

def execute
  @data[:format] ||= 'text'
  AbideDevUtils::Validate.puppet_module_directory
  output = AbideDevUtils::Sce::Validate::Strings.validate(**@data)
  has_errors = false
  has_warnings = false
  output.each do |_, i|
    has_errors = true if i.any? { |j| j[:errors].any? }
    has_warnings = true if i.any? { |j| j[:warnings].any? }
  end
  AbideDevUtils::Output.send(
    @data[:format].to_sym,
    output,
    console: !@data[:quiet],
    file: @data[:out_file],
    stringify: true
  )
  exit 1 if has_errors || (has_warnings && @data[:strict])
end