summaryrefslogtreecommitdiffstats
path: root/atf-c++/detail/application.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'atf-c++/detail/application.cpp')
-rw-r--r--atf-c++/detail/application.cpp115
1 files changed, 11 insertions, 104 deletions
diff --git a/atf-c++/detail/application.cpp b/atf-c++/detail/application.cpp
index 878b010..454bc64 100644
--- a/atf-c++/detail/application.cpp
+++ b/atf-c++/detail/application.cpp
@@ -47,7 +47,6 @@ extern "C" {
#include "application.hpp"
#include "sanity.hpp"
-#include "ui.hpp"
#if !defined(HAVE_VSNPRINTF_IN_STD)
namespace std {
@@ -106,17 +105,12 @@ impl::option::operator<(const impl::option& o)
}
impl::app::app(const std::string& description,
- const std::string& manpage,
- const std::string& global_manpage,
- const bool use_ui) :
- m_hflag(false),
+ const std::string& manpage) :
m_argc(-1),
m_argv(NULL),
m_prog_name(NULL),
m_description(description),
- m_manpage(manpage),
- m_global_manpage(global_manpage),
- m_use_ui(use_ui)
+ m_manpage(manpage)
{
}
@@ -133,11 +127,7 @@ impl::app::inited(void)
impl::app::options_set
impl::app::options(void)
{
- options_set opts = specific_options();
- if (m_use_ui) {
- opts.insert(option('h', "", "Shows this help message"));
- }
- return opts;
+ return specific_options();
}
std::string
@@ -187,11 +177,6 @@ impl::app::process_options(void)
::opterr = 0;
while ((ch = ::getopt(m_argc, m_argv, optstr.c_str())) != -1) {
switch (ch) {
- case 'h':
- INV(m_use_ui);
- m_hflag = true;
- break;
-
case ':':
throw usage_error("Option -%c requires an argument.",
::optopt);
@@ -214,51 +199,6 @@ impl::app::process_options(void)
#endif
}
-void
-impl::app::usage(std::ostream& os)
-{
- PRE(inited());
-
- std::string args = specific_args();
- if (!args.empty())
- args = " " + args;
- os << ui::format_text_with_tag(std::string(m_prog_name) + " [options]" +
- args, "Usage: ", false) << "\n\n"
- << ui::format_text(m_description) << "\n\n";
-
- options_set opts = options();
- INV(!opts.empty());
- os << "Available options:\n";
- size_t coldesc = 0;
- for (options_set::const_iterator iter = opts.begin();
- iter != opts.end(); iter++) {
- const option& opt = (*iter);
-
- if (opt.m_argument.length() + 1 > coldesc)
- coldesc = opt.m_argument.length() + 1;
- }
- for (options_set::const_iterator iter = opts.begin();
- iter != opts.end(); iter++) {
- const option& opt = (*iter);
-
- std::string tag = std::string(" -") + opt.m_character;
- if (opt.m_argument.empty())
- tag += " ";
- else
- tag += " " + opt.m_argument + " ";
- os << ui::format_text_with_tag(opt.m_description, tag, false,
- coldesc + 10) << "\n";
- }
- os << "\n";
-
- std::string gmp;
- if (!m_global_manpage.empty())
- gmp = " and " + m_global_manpage;
- os << ui::format_text("For more details please see " + m_manpage +
- gmp + ".")
- << "\n";
-}
-
int
impl::app::run(int argc, char* const* argv)
{
@@ -290,55 +230,22 @@ impl::app::run(int argc, char* const* argv)
int errcode;
try {
- int oldargc = m_argc;
-
process_options();
-
- if (m_hflag) {
- INV(m_use_ui);
- if (oldargc != 2)
- throw usage_error("-h must be given alone.");
-
- usage(std::cout);
- errcode = EXIT_SUCCESS;
- } else
- errcode = main();
+ errcode = main();
} catch (const usage_error& e) {
- if (m_use_ui) {
- std::cerr << ui::format_error(m_prog_name, e.what()) << "\n"
- << ui::format_info(m_prog_name, std::string("Type `") +
- m_prog_name + " -h' for more details.")
- << "\n";
- } else {
- std::cerr << m_prog_name << ": ERROR: " << e.what() << "\n";
- std::cerr << m_prog_name << ": See " << m_manpage << " for usage "
- "details.\n";
- }
+ std::cerr << m_prog_name << ": ERROR: " << e.what() << "\n";
+ std::cerr << m_prog_name << ": See " << m_manpage << " for usage "
+ "details.\n";
errcode = EXIT_FAILURE;
} catch (const std::runtime_error& e) {
- if (m_use_ui) {
- std::cerr << ui::format_error(m_prog_name, std::string(e.what()))
- << "\n";
- } else {
- std::cerr << m_prog_name << ": ERROR: " << e.what() << "\n";
- }
+ std::cerr << m_prog_name << ": ERROR: " << e.what() << "\n";
errcode = EXIT_FAILURE;
} catch (const std::exception& e) {
- if (m_use_ui) {
- std::cerr << ui::format_error(m_prog_name, std::string("Caught "
- "unexpected error: ") + e.what() + "\n" + bug) << "\n";
- } else {
- std::cerr << m_prog_name << ": ERROR: Caught unexpected error: "
- << e.what() << "\n";
- }
+ std::cerr << m_prog_name << ": ERROR: Caught unexpected error: "
+ << e.what() << "\n";
errcode = EXIT_FAILURE;
} catch (...) {
- if (m_use_ui) {
- std::cerr << ui::format_error(m_prog_name, std::string("Caught "
- "unknown error\n") + bug) << "\n";
- } else {
- std::cerr << m_prog_name << ": ERROR: Caught unknown error\n";
- }
+ std::cerr << m_prog_name << ": ERROR: Caught unknown error\n";
errcode = EXIT_FAILURE;
}
return errcode;
OpenPOWER on IntegriCloud