Skip to content

Commit

Permalink
Merge pull request #5046 from NREL/5045-measure-update
Browse files Browse the repository at this point in the history
Fix #5045 - Fix typo in OSArgument::toJSON + improve reporting when README ERB generation fails
  • Loading branch information
jmarrec authored Dec 11, 2023
2 parents 55040fb + 9d6c194 commit 8772707
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
10 changes: 7 additions & 3 deletions ruby/bindings/InitRubyBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,13 @@ class RubyMeasureInfoBinding < OpenStudio::Measure::MeasureInfoBinding
readme_out_path = File.join(File.dirname(readme_in_path), File.basename(readme_in_path, File.extname(readme_in_path)))
readme_in = File.read(readme_in_path)
renderer = ERB.new(readme_in)
readme_out = renderer.result(get_binding())
rescue
info = OpenStudio::Measure::OSMeasureInfo.new(e.message)
b = get_binding()
readme_out = renderer.result(b)
rescue => e
exception_msg = "Failed to Render ERB file: #{e.class}: #{e.message}\nTraceback:\n"
exception_msg += e.backtrace.join("\n")
STDERR.puts exception_msg
# info = OpenStudio::Measure::OSMeasureInfo.new(exception_msg)
return false # @info
end
# write README.md file
Expand Down
6 changes: 5 additions & 1 deletion src/cli/MeasureManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,12 @@ openstudio::measure::OSMeasureInfo MeasureManager::getMeasureInfo(const openstud

// TODO: for ruby at least, need to try the arity... model was added later, at 3.0.0
const int numArgs = (*thisEngine)->numberOfArguments(measureScriptObject, "arguments");
fmt::print("numArgs={}\n", numArgs);
// fmt::print("numArgs={}\n", numArgs);
if (numArgs == 0) {
auto msg = fmt::format("Reporting Measure at '{}' is using the old format where the 'arguments' method does not take model. "
" Please consider updating this to `def arguments(model)`.",
scriptPath_->generic_string());
fmt::print("{}\n", msg);
if (measureLanguage == MeasureLanguage::Ruby) {
auto patchArgumentsCmd = fmt::format(R"ruby(
module {0}Extensions
Expand Down
8 changes: 5 additions & 3 deletions src/measure/OSArgument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1122,12 +1122,14 @@ namespace measure {
if (hasDefaultValue()) {
root["default_value"] = defaultValueAsString();
}
auto& choiceValues = root["choices_values"];
for (auto& choice : m_choices) {
auto& choiceValues = root["choice_values"];
choiceValues = Json::arrayValue; // Without this line, it's "null" (/nil in Ruby) if m_choices is empty, while old CLI had it as `[]`
for (const auto& choice : m_choices) {
choiceValues.append(choice);
}
auto& choiceDisplayNames = root["choice_display_names"];
for (auto& choice : m_choiceDisplayNames) {
choiceDisplayNames = Json::arrayValue;
for (const auto& choice : m_choiceDisplayNames) {
choiceDisplayNames.append(choice);
}

Expand Down

0 comments on commit 8772707

Please sign in to comment.