From 97b04c2595d7c8855bc5002d8a73e08bf90e9989 Mon Sep 17 00:00:00 2001 From: Philippe PITTOLI Date: Fri, 2 Aug 2019 17:59:33 +0200 Subject: [PATCH] .parse takes options (Hash(String,String)) --- src/spec.cr | 8 +++++++- test-specs.cr | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/spec.cr b/src/spec.cr index 804c528..8133ca9 100644 --- a/src/spec.cr +++ b/src/spec.cr @@ -349,7 +349,7 @@ class Specs has_bugs end - def self.parse(file_name : String) : Specs | Nil + def self.parse(file_name : String, options : Hash(String, String) | Nil = nil) : Specs | Nil begin content = File.read(file_name) content = content.rchop @@ -360,6 +360,12 @@ class Specs end specs = Specs.new + unless options.nil? + options.each do |opt, val| + specs.assignments[opt] = StringContainer.new val + end + end + tree = Pegasus::Generated.process(content) specs.parse_tree tree diff --git a/test-specs.cr b/test-specs.cr index bfb2af8..b7937e0 100644 --- a/test-specs.cr +++ b/test-specs.cr @@ -28,5 +28,8 @@ OptionParser.parse! do |parser| end -specs = Specs.parse recipe_file_name +options = Hash(String,String).new +options["someoptionexample"] = "option" + +specs = Specs.parse recipe_file_name, options pp! specs