lib/resme/cli/command_semantics.rb in resme-0.4.0 vs lib/resme/cli/command_semantics.rb in resme-0.5.0

- old
+ new

@@ -3,11 +3,10 @@ require "fileutils" require "date" require "yaml" require "erb" require "json" -require "kwalify" module Resme module CommandSemantics APPNAME = "resme" VERSION = Resme::VERSION @@ -91,28 +90,28 @@ # # APP SPECIFIC COMMANDS # def self.check(opts, argv) - path = File.join(File.dirname(__FILE__), "/../templates/schema.yml") - schema = Kwalify::Yaml.load_file(path) - - # create validator - validator = Kwalify::Validator.new(schema) - # load document - document = Kwalify::Yaml.load_file(argv[0]) - # validate - errors = validator.validate(document) - - # show errors - if errors && !errors.empty? - for e in errors - puts "[#{e.path}] #{e.message}" + begin + document = YAML.load_file(argv[0], permitted_classes: [Date]) + rescue Psych::SyntaxError => ex + puts "The file #{argv[0]} has an invalid structure." + puts ex.message + exit 1 + end + + begin + errors = ResumeStructureValidator.validate(document) + rescue Exception => ex + puts "The files #{argv[0]} does not validate" + ex.entries.each do |error| + puts "#{error[:full_path]}: #{error[:message]}" end - else - puts "The file #{argv[0]} validates." + exit 1 end + puts "The file #{argv[0]} has a valid structure." end def self.init(opts, argv) output = opts[:output] || "resume.yml" force = opts[:force] @@ -137,9 +136,15 @@ end puts "Sections included in #{argv.join(", ")}:" data.keys.each do |key| puts "- #{key}: #{(data[key] || []).size} entries" end + end + + def self.view(opts, argv) + format = opts[:template] == "europass" ? "xml" : opts[:template] + template = File.join(File.dirname(__FILE__), "/../templates/resume.#{format}.erb") + puts File.read template end def self.generate(opts, argv) format = opts[:to] == "europass" ? "xml" : opts[:to] output = opts[:output] || "resume-#{Date.today}.#{format}"