Class: Abide::CLI::CemValidatePuppetStrings

Inherits:
AbideCommand
  • Object
show all
Defined in:
lib/abide_dev_utils/cli/cem.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 included from AbideDevUtils::Config

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

Constructor Details

#initializeCemValidatePuppetStrings

Returns a new instance of CemValidatePuppetStrings.



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/abide_dev_utils/cli/cem.rb', line 196

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



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/abide_dev_utils/cli/cem.rb', line 215

def execute
  @data[:format] ||= 'text'
  AbideDevUtils::Validate.puppet_module_directory
  output = AbideDevUtils::CEM::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