diff --git a/examples/cpp/external_data_loader/main.cpp b/examples/cpp/external_data_loader/main.cpp index adddc44269c2f..052edab156f20 100644 --- a/examples/cpp/external_data_loader/main.cpp +++ b/examples/cpp/external_data_loader/main.cpp @@ -4,30 +4,7 @@ #include #include - -static const char* USAGE = R"( -This is an example executable data-loader plugin for the Rerun Viewer. -Any executable on your `$PATH` with a name that starts with `rerun-loader-` will be treated as an -external data-loader. - -This particular one will log C++ source code files as markdown documents, and return a -special exit code to indicate that it doesn't support anything else. - -To try it out, compile it and place it in your $PATH as `rerun-loader-cpp-file`, then open a C++ source -file with Rerun (`rerun file.cpp`). - -USAGE: - rerun-loader-cpp-file [OPTIONS] FILEPATH - -FLAGS: - -h, --help Prints help information - -OPTIONS: - --recording-id RECORDING_ID ID of the shared recording - -ARGS: - -)"; +#include int main(int argc, char* argv[]) { // The Rerun Viewer will always pass these two pieces of information: @@ -56,11 +33,45 @@ int main(int argc, char* argv[]) { } } - if (filepath.empty()) { - std::cerr << USAGE << std::endl; - return 1; + // if (filepath.empty()) { + // std::cerr << USAGE << std::endl; + // return 1; + // } + + cxxopts::Options options( + "rerun-loader-cpp-file", + R"( +This is an example executable data-loader plugin for the Rerun Viewer. +Any executable on your `$PATH` with a name that starts with `rerun-loader-` will be treated as an +external data-loader. + +This particular one will log C++ source code files as markdown documents, and return a +special exit code to indicate that it doesn't support anything else. + +To try it out, compile it and place it in your $PATH as `rerun-loader-cpp-file`, then open a C++ source +file with Rerun (`rerun file.cpp`). +)" + ); + + // clang-format off + options.add_options() + ("h,help", "Print usage") + ("from-contents", "Log the contents of the file directly (files only -- not supported by external loaders)", cxxopts::value()->default_value("false")) + ("filepath", "The filepath to be loaded and logged", cxxopts::value()) + ; + // clang-format on + + options.parse_positional({"filepath"}); + + auto args = options.parse(argc, argv); + + if (args.count("help")) { + std::cout << options.help() << std::endl; + exit(0); } + std::cout << args << std::endl; + bool is_file = std::filesystem::is_regular_file(filepath); bool is_cpp_file = std::filesystem::path(filepath).extension().string() == ".cpp";