diff options
author | jmmv <jmmv@FreeBSD.org> | 2014-02-14 14:41:25 +0000 |
---|---|---|
committer | jmmv <jmmv@FreeBSD.org> | 2014-02-14 14:41:25 +0000 |
commit | a817576754c6af0869b83f2f3efc4659963962a1 (patch) | |
tree | a986bed64ee725de3eb52c5f0838f6c59b8aa7d9 /atf-c++/detail/application.cpp | |
parent | b849e3606cf0dc725ff02712cd92907131c0188c (diff) | |
download | FreeBSD-src-a817576754c6af0869b83f2f3efc4659963962a1.zip FreeBSD-src-a817576754c6af0869b83f2f3efc4659963962a1.tar.gz |
Import atf-0.19:
Experimental version released on February 7th, 2014.
This is the last release to bundle the code for the deprecated tools.
The next release will drop their code and will stop worrying about
backwards compatibility between the ATF libraries and what the old tools
may or may not support.
If you still require the old tools for some reason, grab a copy of the
'tools' directory now. The code in this directory is standalone and
does not depend on any internal details of atf-c++ any longer.
* Various fixes and improvements to support running as part of the FreeBSD
test suite.
* Project hosting moved from Google Code (as a subproject of Kyua) to
GitHub (as a first-class project). The main reason for the change is
the suppression of binary downloads in Google Code on Jan 15th, 2014.
See https://github.com/jmmv/atf/
* Removed builtin help from atf-sh(1) and atf-check(1) for simplicity
reasons. In other words, their -h option is gone.
* Moved the code of the deprecated tools into a 'tools' directory and
completely decoupled their code from the internals of atf-c++. The
reason for this is to painlessly allow a third-party to maintain a
copy of these tools after we delete them because upcoming changes to
atf-c++ would break the stale tools.
Diffstat (limited to 'atf-c++/detail/application.cpp')
-rw-r--r-- | atf-c++/detail/application.cpp | 115 |
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; |