Skip to content

Commit

Permalink
feat: add validate command
Browse files Browse the repository at this point in the history
  • Loading branch information
ronaldtse committed Apr 24, 2024
1 parent 968a856 commit 4a391f2
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions lib/expressir/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,60 @@ def format(path)
end
end

no_commands do
def _validate_schema(path)
repository = Expressir::Express::Parser.from_file(path)
repository.schemas.inject([]) do |acc, schema|
acc << schema.id unless schema.version&.value
acc
end
rescue StandardError => e
# pp e
nil
end
end

desc "validate *PATH", "validate EXPRESS schema located at PATH"
def validate(*paths)
no_version = []
no_valid = []

paths.each do |path|
x = Pathname.new(path).realpath.relative_path_from(Dir.pwd)
puts "Validating #{x}"
ret = _validate_schema(path)

if ret.nil?
no_valid << "Failed to parse: #{x}"
next
end

if ret.size
ret.each do |schema_id|
no_version << "Missing version string: schema `#{schema_id}` | #{x}"
end
end
end

if !no_valid.empty?
puts "#{"*" * 20} RESULTS: FAILED TO PARSE #{"*" * 20}"
no_valid.each do |msg|
puts msg
end
end

if !no_version.empty?
puts "#{"*" * 20} RESULTS: MISSING VERSION STRING #{"*" * 20}"
no_version.each do |msg|
puts msg
end
end

if no_valid.size || no_version.size
exit 1
end
end

desc "version", "Expressir Version"
def version
say(Expressir::VERSION)
Expand Down

0 comments on commit 4a391f2

Please sign in to comment.