Skip to content
Snippets Groups Projects
Commit f9087b0d authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Change application default behavior and command line options

Pugs used to detect terminal execution type to position flags (color, pause on
error in debug mode).
Due to MPI compatibility no more detection is performed and by default
- output is colorized which can be disabled using '--no-color'
- pause or error is deactivated unless flag '-p' or '--pause-on-error' is used

Fix #5
parent 025627e6
No related branches found
No related tags found
1 merge request!18Change application default behavior and command line options
......@@ -10,25 +10,14 @@ ConsoleManager::isTerminal(std::ostream& os)
}
void
ConsoleManager::init(const std::string& colorize)
ConsoleManager::init(const bool& colorize)
{
pout() << "Console management: color ";
if (colorize == "auto") {
if (isTerminal(pout())) {
pout() << rang::style::bold << rang::fgB::green << "enabled" << rang::fg::reset << rang::style::reset;
} else {
pout() << "disabled";
}
pout() << " [auto]\n";
} else if (colorize == "yes") {
if (colorize) {
rang::setControlMode(rang::control::Force);
pout() << rang::style::bold << rang::fgB::green << "enabled" << rang::fg::reset << rang::style::reset;
pout() << " [" << rang::style::bold << rang::fgB::red << "forced" << rang::fg::reset << rang::style::reset << "]\n";
} else if (colorize == "no") {
rang::setControlMode(rang::control::Off);
pout() << "disabled [forced]\n";
pout() << rang::style::bold << rang::fgB::green << "enabled" << rang::fg::reset << rang::style::reset << '\n';
} else {
perr() << "Unknown colorize option: " << colorize << '\n';
std::exit(1);
rang::setControlMode(rang::control::Off);
pout() << "disabled\n";
}
}
......@@ -6,7 +6,7 @@
struct ConsoleManager
{
static bool isTerminal(std::ostream& os);
static void init(const std::string& colorize);
static void init(const bool& colorize);
};
#endif // CONSOLE_MANAGER_HPP
......@@ -21,9 +21,6 @@ initialize(int& argc, char* argv[])
{
parallel::Messenger::create(argc, argv);
long unsigned number = 10;
std::string filename;
pout() << "Pugs version: " << rang::style::bold << RevisionInfo::version() << rang::style::reset << '\n';
pout() << "-------------------- " << rang::fg::green << "git info" << rang::fg::reset << " -------------------------"
......@@ -45,29 +42,28 @@ initialize(int& argc, char* argv[])
pout() << "kokkos: " << rang::style::bold << BuildInfo::kokkosDevices() << rang::style::reset << '\n';
pout() << "mpi: " << rang::style::bold << BuildInfo::mpiLibrary() << rang::style::reset << '\n';
pout() << "-------------------------------------------------------\n";
std::string filename;
{
CLI::App app{"Pugs help"};
app.add_option("-n,--number", number, "Number of cells"); //->required();
app.add_option("filename,-f,--filename", filename,
"gmsh file"); //->required();
app.add_option("filename,-f,--filename", filename, "gmsh file");
int threads = -1;
app.add_option("--threads", threads, "Number of Kokkos threads")
->check(CLI::Range(1, std::numeric_limits<decltype(threads)>::max()));
std::string colorize = "auto";
app.add_set("--colorize", colorize, {"auto", "yes", "no"}, "Colorize console output", true);
bool enable_color = true;
app.add_flag("--color,!--no-color", enable_color, "Colorize console output [default: true]");
bool enable_fpe = true;
app.add_flag("--fpe,!--no-fpe", enable_fpe, "Trap floating point exceptions [default: true]");
bool disable_fpe = false;
app.add_flag("--no-fpe", disable_fpe, "Do not trap floating point exceptions");
bool disable_signals = false;
app.add_flag("--no-signal", disable_signals, "Do not catches signals");
bool enable_signals = true;
app.add_flag("--signal,!--no-signal", enable_signals, "Catches signals [default: true]");
std::string pause_on_error = "auto";
app.add_set("--pause-on-error", pause_on_error, {"auto", "yes", "no"}, "Pause for debugging on unexpected error",
true);
bool pause_on_error = false;
app.add_flag("-p,--pause-on-error", pause_on_error, "Pause for debugging on unexpected error [default: false]");
std::atexit([]() { pout() << rang::style::reset; });
try {
......@@ -78,10 +74,10 @@ initialize(int& argc, char* argv[])
std::exit(app.exit(e, pout(), perr()));
}
ConsoleManager::init(colorize);
FPEManager::init(not disable_fpe);
ConsoleManager::init(enable_color);
FPEManager::init(enable_fpe);
SignalManager::setPauseForDebug(pause_on_error);
SignalManager::init(not disable_signals);
SignalManager::init(enable_signals);
}
Kokkos::initialize(argc, argv);
......
......@@ -14,9 +14,10 @@
#include <Messenger.hpp>
std::string SignalManager::s_pause_on_error = "auto";
bool SignalManager::s_pause_on_error = false;
void
SignalManager::setPauseForDebug(const std::string& pause_on_error)
SignalManager::setPauseForDebug(const bool& pause_on_error)
{
s_pause_on_error = pause_on_error;
}
......@@ -45,7 +46,7 @@ void
SignalManager::pauseForDebug(const int& signal)
{
if (std::string(PUGS_BUILD_TYPE) != "Release") {
if (s_pause_on_error == "yes") {
if (s_pause_on_error) {
std::cerr << "\n======================================\n"
<< rang::style::reset << rang::fg::reset << rang::style::bold << "to attach gdb to this process run\n"
<< "\tgdb -pid " << rang::fg::red << getpid() << rang::fg::reset << '\n'
......
......@@ -6,13 +6,13 @@
struct SignalManager
{
private:
static std::string s_pause_on_error;
static bool s_pause_on_error;
static std::string signalName(const int& signal);
static void pauseForDebug(const int& signal);
static void handler(int signal);
public:
static void setPauseForDebug(const std::string& pause_on_error);
static void setPauseForDebug(const bool& pause_on_error);
static void init(const bool& enable);
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment