Sha256: fc08c8c86da018dae079b984ce49b5fb0b4631e0c92ef953fcb45993aad88715

Contents?: true

Size: 1.88 KB

Versions: 2

Compression:

Stored size: 1.88 KB

Contents

# frozen_string_literal: true

require "tools/validator"

module Icarus
  module Mod
    module CLI
      # Sync CLI command definitions
      class Validate < SubcommandBase
        desc "modinfo", "Reads modinfo data from 'meta/modinfo/list' and Validates syntax of modfiles"
        def modinfo
          validate(:modinfo)
        end

        desc "proginfo", "Reads proginfo data from 'meta/proginfo/list' and Validates syntax of progfiles"
        def proginfo
          validate(:proginfo)
        end

        no_commands do
          def validate(type)
            exit_code = 0
            validator = Icarus::Mod::Tools::Validator.new(type)

            puts "Validating Entries..." if verbose?
            max_length = validator.array.map { |info| info.uniq_name.length }.max + 1

            # rubocop:disable Lint/FormatParameterMismatch
            validator.array.each do |info|
              print Paint[format("%s %-#{max_length}s", "Running validation steps on", info.uniq_name), :cyan, :bright] if verbose > 1

              info.valid?

              unless info.errors? || info.warnings?
                puts Paint["SUCCESS", :green, :bright] if verbose > 1
                next
              end

              if info.errors?
                exit_code = 1
                puts Paint["ERROR", :red, :bright] if verbose? && verbose > 1
                puts info.errors.map { |error| Paint["#{error} in #{info.uniq_name}", :red] }.join("\n")
                puts "\n" if verbose > 1
              end

              puts Paint["WARNING", :yellow, :bright] if info.warnings.any? && verbose > 1
              puts info.warnings.map { |warning| Paint["#{warning} in #{info.uniq_name}", :yellow] }.join("\n")
              puts "\n" if verbose > 1
            end
            # rubocop:enable Lint/FormatParameterMismatch

            exit exit_code
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
Icarus-Mod-Tools-1.8.2.1 lib/icarus/mod/cli/validate.rb
Icarus-Mod-Tools-1.8.2 lib/icarus/mod/cli/validate.rb