Open excel file automatically when generated
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "main/modelRegister.h"
|
||||
#include "common/Paths.h"
|
||||
#include "common/Colors.h"
|
||||
#include "common/Utils.h"
|
||||
#include "best/BestResults.h"
|
||||
#include "common/DotEnv.h"
|
||||
#include "config_platform.h"
|
||||
@@ -80,6 +81,11 @@ int main(int argc, char** argv)
|
||||
std::cout << Colors::GREEN() << fileName << " created!" << Colors::RESET() << std::endl;
|
||||
results.reportSingle(excel);
|
||||
}
|
||||
if (excel) {
|
||||
auto fileName = results.getExcelFileName();
|
||||
std::cout << "Opening " << fileName << std::endl;
|
||||
platform::openFile(fileName);
|
||||
}
|
||||
std::cout << Colors::RESET();
|
||||
return 0;
|
||||
}
|
||||
|
@@ -8,6 +8,7 @@
|
||||
#include "common/Paths.h"
|
||||
#include "common/Colors.h"
|
||||
#include "common/Datasets.h"
|
||||
#include "common/Utils.h"
|
||||
#include "reports/DatasetsExcel.h"
|
||||
#include "reports/DatasetsConsole.h"
|
||||
#include "results/ResultsDatasetConsole.h"
|
||||
@@ -24,9 +25,13 @@ void list_datasets(argparse::ArgumentParser& program)
|
||||
std::cout << report.getOutput();
|
||||
if (excel) {
|
||||
auto data = report.getData();
|
||||
auto report = platform::DatasetsExcel();
|
||||
report.report(data);
|
||||
std::cout << std::endl << Colors::GREEN() << "Output saved in " << report.getFileName() << std::endl;
|
||||
auto ereport = new platform::DatasetsExcel();
|
||||
ereport->report(data);
|
||||
std::cout << std::endl << Colors::GREEN() << "Output saved in " << ereport->getFileName() << std::endl;
|
||||
auto fileName = ereport->getExcelFileName();
|
||||
delete ereport;
|
||||
std::cout << "Opening " << fileName << std::endl;
|
||||
platform::openFile(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,9 +47,13 @@ void list_results(argparse::ArgumentParser& program)
|
||||
std::cout << report.getOutput();
|
||||
if (excel) {
|
||||
auto data = report.getData();
|
||||
auto report = platform::ResultsDatasetExcel();
|
||||
report.report(data);
|
||||
std::cout << std::endl << Colors::GREEN() << "Output saved in " << report.getFileName() << std::endl;
|
||||
auto ereport = new platform::ResultsDatasetExcel();
|
||||
ereport->report(data);
|
||||
std::cout << std::endl << Colors::GREEN() << "Output saved in " << ereport->getFileName() << std::endl;
|
||||
auto fileName = ereport->getExcelFileName();
|
||||
delete ereport;
|
||||
std::cout << "Opening " << fileName << std::endl;
|
||||
platform::openFile(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
|
||||
#include <utility>
|
||||
#include <iostream>
|
||||
#include <sys/ioctl.h>
|
||||
#include <utility>
|
||||
#include <unistd.h>
|
||||
#include "common/Paths.h"
|
||||
#include <argparse/argparse.hpp>
|
||||
#include "manage/ManageScreen.h"
|
||||
@@ -53,65 +53,7 @@ void handleResize(int sig)
|
||||
manager->updateSize(rows, cols);
|
||||
}
|
||||
|
||||
void openFile(const std::string& fileName)
|
||||
{
|
||||
// #ifdef __APPLE__
|
||||
// // macOS uses the "open" command
|
||||
// std::string command = "open";
|
||||
// #elif defined(__linux__)
|
||||
// // Linux typically uses "xdg-open"
|
||||
// std::string command = "xdg-open";
|
||||
// #else
|
||||
// // For other OSes, do nothing or handle differently
|
||||
// std::cerr << "Unsupported platform." << std::endl;
|
||||
// return;
|
||||
// #endif
|
||||
// execlp(command.c_str(), command.c_str(), fileName.c_str(), NULL);
|
||||
#ifdef __APPLE__
|
||||
const char* tool = "/usr/bin/open";
|
||||
#elif defined(__linux__)
|
||||
const char* tool = "/usr/bin/xdg-open";
|
||||
#else
|
||||
std::cerr << "Unsupported platform." << std::endl;
|
||||
return;
|
||||
#endif
|
||||
|
||||
// We'll build an argv array for execve:
|
||||
std::vector<char*> argv;
|
||||
argv.push_back(const_cast<char*>(tool)); // argv[0]
|
||||
argv.push_back(const_cast<char*>(fileName.c_str())); // argv[1]
|
||||
argv.push_back(nullptr);
|
||||
|
||||
// Make a new environment array, skipping BASH_FUNC_ variables
|
||||
std::vector<std::string> filteredEnv;
|
||||
for (char** env = environ; *env != nullptr; ++env) {
|
||||
// *env is a string like "NAME=VALUE"
|
||||
// We want to skip those starting with "BASH_FUNC_"
|
||||
if (strncmp(*env, "BASH_FUNC_", 10) == 0) {
|
||||
// skip it
|
||||
continue;
|
||||
}
|
||||
filteredEnv.push_back(*env);
|
||||
}
|
||||
|
||||
// Convert filteredEnv into a char* array
|
||||
std::vector<char*> envp;
|
||||
for (auto& var : filteredEnv) {
|
||||
envp.push_back(const_cast<char*>(var.c_str()));
|
||||
}
|
||||
envp.push_back(nullptr);
|
||||
|
||||
// Now call execve with the cleaned environment
|
||||
// NOTE: You may need a full path to the tool if it's not in PATH, or use which() logic
|
||||
// For now, let's assume "open" or "xdg-open" is found in the default PATH:
|
||||
execve(tool, argv.data(), envp.data());
|
||||
|
||||
// If we reach here, execve failed
|
||||
perror("execve failed");
|
||||
// This would terminate your current process if it's not in a child
|
||||
// Usually you'd do something like:
|
||||
_exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
@@ -137,7 +79,7 @@ int main(int argc, char** argv)
|
||||
delete manager;
|
||||
if (!fileName.empty()) {
|
||||
std::cout << "Opening " << fileName << std::endl;
|
||||
openFile(fileName);
|
||||
platform::openFile(fileName);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user