Sha256: bb3e01e44bb35a88bb7ce4c7daee8dacfbc8a797fd9045df39b83d8cf17fe2a4

Contents?: true

Size: 1.32 KB

Versions: 2

Compression:

Stored size: 1.32 KB

Contents

#!/usr/bin/env ruby

require 'prospectus'
require 'mercenary'

def run_file(params, file = nil)
  Prospectus.load_from_file({ file: file }.merge(params)).check
rescue RuntimeError
  puts "Failed parsing #{Dir.pwd}/#{file}"
  raise
end

def load_list(params)
  return run_file(params) if File.exist? '.prospectus'
  fail('No .prospectus/.prospectus.d found') unless Dir.exist? '.prospectus.d'
  files = Dir.glob('.prospectus.d/*')
  fail('No files in .prospectus.d') if files.empty?
  files.map { |x| run_file(params, x) }.flatten
end

Mercenary.program(:prospectus) do |p|
  p.version Prospectus::VERSION
  p.description 'Tool and DSL for checking expected vs actual state'
  p.syntax 'prospectus [options]'

  # rubocop:disable Metrics/LineLength
  p.option :directory, '-d DIR', '--directory DIR', 'Change to directory before loading'
  p.option :good_only, '-g', '--good', 'Show only items with good state'
  p.option :all, '-a', '--all', 'Show all items'
  p.option :json, '-j', '--json', 'Output results as json'
  # rubocop:enable Metrics/LineLength

  p.action do |_, options|
    options[:directory] ||= '.'
    Dir.chdir(options[:directory]) do
      results = load_list(options)
      if options[:json]
        puts results.to_json
      else
        results.each { |x| puts "#{x.name}: #{x.actual} / #{x.expected}" }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
prospectus-0.0.9 bin/prospectus
prospectus-0.0.8 bin/prospectus