MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / setupMeasureUpdateOptions

Method setupMeasureUpdateOptions

src/cli/MeasureUpdateCommand.cpp:41–274  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39namespace cli {
40
41 void MeasureUpdateOptions::setupMeasureUpdateOptions(CLI::App* parentApp, ScriptEngineInstance& rubyEngine, ScriptEngineInstance& pythonEngine) {
42 /// Set up a subcommand and capture a shared_ptr to a struct that holds all its options.
43 /// The variables of the struct are bound to the CLI options.
44 /// We use a shared ptr so that the addresses of the variables remain for binding,
45 /// You could return the shared pointer if you wanted to access the values in main.
46
47 auto opt = std::make_shared<MeasureUpdateOptions>();
48
49 auto* measureCommand = parentApp->add_subcommand("measure", "Measure Commands");
50
51 // Positional
52 auto* directoryPathOpt = measureCommand->add_option("DIRECTORY", opt->directoryPath, "Directory containing the measure(s)")->option_text(" ");
53
54 // TODO: I'm trying to preserve historical behavior, but --update, --update_all, --start_server should all be subcommands instead since they are
55 // exclusive! At least start_server should, so that I can make directory required...
56 auto* updateOpt = measureCommand->add_flag("-u,--update", opt->update, "Update the measure.xml")->needs(directoryPathOpt);
57
58 auto* updateAllOpt = measureCommand->add_flag("-t,--update_all", opt->update_all, "Update all measures in a directory")
59 ->needs(directoryPathOpt)
60 ->excludes(updateOpt);
61
62 auto* computeArgsOpt =
63 measureCommand->add_option("-a,--compute_arguments", opt->compute_arguments_model, "Compute arguments for the given OSM or IDF")
64 ->option_text("MODEL")
65 ->needs(directoryPathOpt)
66 ->excludes(updateOpt, updateAllOpt);
67
68 measureCommand
69 ->add_flag("-r,--run_tests", opt->run_tests, "Run all tests recursively found in a directory, additional arguments are passed to minitest")
70 ->needs(directoryPathOpt)
71 ->excludes(updateOpt, updateAllOpt, computeArgsOpt);
72
73 [[maybe_unused]] auto* startServerOpt = measureCommand->add_option("-s,--start_server", opt->server_port, "Start a measure manager server")
74 ->option_text("PORT")
75 ->excludes(directoryPathOpt);
76
77 {
78 auto* newMeasureSubCommand = measureCommand->add_subcommand("new", "Create a new measure");
79
80 // TODO: this includes 'UtilityMeasure' which I don't think we want to include
81 std::vector<std::string> measureTypeNames;
82 {
83 const auto& m = openstudio::MeasureType::getNames();
84 std::transform(m.cbegin(), m.cend(), back_inserter(measureTypeNames), [](const auto& x) { return x.second; });
85 // fmt::print("measureTypeNames={}\n", measureTypeNames);
86 [[maybe_unused]] auto* measureTypeOpt =
87 newMeasureSubCommand
88 ->add_option("-t,--type", opt->newMeasureOpts.measureType,
89 fmt::format("Type of Measure [Default: '{}']: {}", opt->newMeasureOpts.measureType.valueName(), measureTypeNames))
90 ->option_text("measureType")
91 ->check(CLI::IsMember(measureTypeNames));
92 }
93
94 std::vector<std::string> measureLanguageNames;
95 {
96 const auto& m = openstudio::MeasureLanguage::getNames();
97 std::transform(m.cbegin(), m.cend(), back_inserter(measureLanguageNames), [](const auto& x) { return x.second; });
98 // fmt::print("measureLanguageNames={}\n", measureLanguageNames);

Callers

nothing calls this directly

Calls 15

cbeginMethod · 0.80
cendMethod · 0.80
valueNameMethod · 0.80
beginMethod · 0.80
groupMethod · 0.80
checkForUpdatesFilesMethod · 0.80
measureLanguageMethod · 0.80
toStringFunction · 0.50
BCLMeasureClass · 0.50
executeFunction · 0.50
requiredMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected