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

Function main

src/cli/main.cpp:35–379  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33#include <vector>
34
35int main(int argc, char* argv[]) {
36
37 constexpr auto rubySpecificOptionsGroupName = "Ruby Options";
38 constexpr auto pythonSpecificOptionsGroupName = "Python Options";
39
40 // constexpr auto executeGroupName = "Script Execution";
41 constexpr auto versionGroupname = "Version Info";
42
43 int result = 0;
44
45 std::vector<std::string> args(argv, std::next(argv, static_cast<std::ptrdiff_t>(argc)));
46 // fmt::print("Original arguments: {}\n", args);
47 std::for_each(args.begin(), args.end(), [](auto& s) {
48 openstudio::ascii_trim(s);
49 // Windows cmd.exe treats single quotes as regular chars so we strip them if found (cf #4779 and #4834)
50 if (s.starts_with('\'') && s.ends_with('\'')) {
51 s.erase(std::prev(s.end()));
52 s.erase(s.begin());
53 }
54 });
55 // fmt::print("Cleaned arguments: {}\n", args);
56 // erase the first element, which is the name of the program
57 const std::string programName = std::move(args.front());
58 args.erase(args.begin());
59
60 const bool is_classic = !args.empty() && (args[0] == "classic");
61
62 if (is_classic) {
63 // The "classic" cli implementation will not be expecting the first arg
64 // to be the word classic so we need to remove the first arg
65 args.erase(args.begin());
66 } else {
67 // Replace backward slashes with forward slashes... cf #4856
68 std::for_each(args.begin(), args.end(), [](auto& s) { boost::replace_all(s, "\\", "\\\\"); });
69 }
70
71 // ScriptEngineInstance will delay load the engines
72 openstudio::ScriptEngineInstance rubyEngine("rubyengine", args);
73 openstudio::ScriptEngineInstance pythonEngine("pythonengine", args);
74
75 if (is_classic) {
76 fmt::print(fmt::fg(fmt::color::orange),
77 "┌{0:─^{2}}┐\n"
78 "│{1: ^{2}}│\n"
79 "└{0:─^{2}}┘",
80 "", "The `classic` command is deprecated and will be removed in a future release", 80);
81 fmt::print("\n");
82 result = openstudio::rubyCLI(rubyEngine);
83 } else {
84 CLI::App app{"openstudio"};
85 app.name(programName);
86
87 // Preprocess the arguments, insert execute_xxx_script if a script is passed but the previous arg isn't the command.
88 // So you can ommit "execute_xxx_script" like historical behavior: `openstudio --include INCLUDE_DIR test.rb`
89 if (std::none_of(args.begin(), args.end(), [](const auto& arg) { return (arg == "execute_ruby_script") || (arg == "execute_python_script"); })) {
90 auto it = std::find_if(args.begin(), args.end(), [](const auto& arg) { return arg.ends_with(".rb") || arg.ends_with(".py"); });
91 if (it != args.end()) {
92 if (it->ends_with(".rb")) {

Callers

nothing calls this directly

Calls 15

ascii_trimFunction · 0.85
rubyCLIFunction · 0.85
executeRubyScriptCommandFunction · 0.85
executeRubyReplFunction · 0.85
executePythonReplFunction · 0.85
executeGemListCommandFunction · 0.85
executePipListCommandFunction · 0.85
setupRunOptionsFunction · 0.85
runModelUpdateCommandFunction · 0.85
reverseFunction · 0.85
beginMethod · 0.80

Tested by

no test coverage detected