From f4efb4f3d4bf2a382158d1cd792c65cb8a71806f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Tue, 29 Nov 2016 02:01:23 +0100 Subject: [PATCH] Improved command-line interface. --- CHANGELOG.md | 1 + README.md | 2 +- apps/plasp-app/CMakeLists.txt | 2 +- apps/plasp-app/main.cpp | 29 +++++++++++++++-------------- doc/command-line-interface.md | 14 +++++++------- include/plasp/Language.h | 1 + include/plasp/utils/Logger.h | 2 +- src/plasp/Language.cpp | 1 + src/plasp/utils/Logger.cpp | 6 +++--- 9 files changed, 31 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d67e520..9e2cf08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Features: * extended PDDL support (`imply` expressions) +* improved command-line interface ## 3.0.3 (2016-09-02) diff --git a/README.md b/README.md index ca6278a..a48da59 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ $ clingo encodings/sequential-incremental.lp instance.lp ## Command-Line Interface ```bash -$ plasp [files] [options] +$ plasp [options] file... ``` `plasp` automatically detects the language of the input program. diff --git a/apps/plasp-app/CMakeLists.txt b/apps/plasp-app/CMakeLists.txt index b6a4ca9..fbc0b5f 100644 --- a/apps/plasp-app/CMakeLists.txt +++ b/apps/plasp-app/CMakeLists.txt @@ -20,4 +20,4 @@ set(libraries add_executable(${target} ${sources}) target_link_libraries(${target} ${libraries}) -set_target_properties(plasp_app PROPERTIES OUTPUT_NAME plasp) +set_target_properties(${target} PROPERTIES OUTPUT_NAME plasp) diff --git a/apps/plasp-app/main.cpp b/apps/plasp-app/main.cpp index f58f5f9..6ba5fec 100644 --- a/apps/plasp-app/main.cpp +++ b/apps/plasp-app/main.cpp @@ -18,12 +18,12 @@ int main(int argc, char **argv) po::options_description description("Allowed options"); description.add_options() - ("help,h", "Display this help message.") - ("version,v", "Display version information.") - ("input,i", po::value>(), "Specify the PDDL or SAS input file.") - ("language,l", po::value(), "Specify the input language (sas or pddl). Omit for automatic detection.") - ("warning-level", po::value()->default_value("normal"), "Specify whether to output warnings normally (normal), to treat them as critical errors (error), or to ignore them (ignore).") - ("color", po::value()->default_value("auto"), "Specify whether to colorize the output (always, never, or auto)."); + ("help,h", "Display this help message") + ("version,v", "Display version information") + ("input,i", po::value>(), "Input files (in PDDL or SAS format)") + ("language,l", po::value()->default_value("auto"), "Input language (pddl, sas, auto)") + ("warning-level", po::value()->default_value("show"), "Show warnings (show), treat them as errors (error), or ignore them (ignore)") + ("color", po::value()->default_value("auto"), "Colorize output (always, never, auto)"); po::positional_options_description positionalOptionsDescription; positionalOptionsDescription.add("input", -1); @@ -33,8 +33,8 @@ int main(int argc, char **argv) const auto printHelp = [&]() { - std::cout << "Usage: plasp [files] [options]" << std::endl; - std::cout << "Translate PDDL instances to ASP facts." << std::endl << std::endl; + std::cout << "Usage: plasp [options] file..." << std::endl; + std::cout << "Translate PDDL to ASP." << std::endl << std::endl; std::cout << description; }; @@ -76,8 +76,8 @@ int main(int argc, char **argv) logger.setWarningLevel(plasp::utils::Logger::WarningLevel::Error); else if (warningLevel == "ignore") logger.setWarningLevel(plasp::utils::Logger::WarningLevel::Ignore); - else if (warningLevel == "normal") - logger.setWarningLevel(plasp::utils::Logger::WarningLevel::Normal); + else if (warningLevel == "show") + logger.setWarningLevel(plasp::utils::Logger::WarningLevel::Show); else { logger.logError("unknown warning level “" + warningLevel + "”"); @@ -122,12 +122,13 @@ int main(int argc, char **argv) const auto detectLanguage = [&]() { - if (variablesMap.count("language") == 0) + const auto languageName = variablesMap["language"].as(); + const auto language = plasp::Language::fromString(languageName); + + if (language == plasp::Language::Type::Automatic) return plasp::detectLanguage(parser); - const auto languageName = variablesMap["language"].as(); - - return plasp::Language::fromString(languageName); + return language; }; const auto language = detectLanguage(); diff --git a/doc/command-line-interface.md b/doc/command-line-interface.md index 03f48b4..0ea57ca 100644 --- a/doc/command-line-interface.md +++ b/doc/command-line-interface.md @@ -1,18 +1,18 @@ # Command-Line Interface ```bash -$ plasp [files] [options] +$ plasp [options] file... ``` `plasp` automatically detects the language of the input files. Multiple files may be provided in an arbitrary order. -`[files]` may also be omitted, in which case the input is read from `std::cin`. +The `file...` arguments may also be omitted, in which case the input is read from `std::cin`. `plasp` supports the following options: -| **option** | **explanation** | -|-----------------------------------|-----------------------------------------------------------------------------------------------------------------------------------| -| `-l` [ `--language` ] | Specify the input language (`sas` or `pddl`). Omit for automatic detection. | -| `--warning-level` arg (=`normal`) | Specify whether to output warnings normally (`normal`), to treat them as critical errors (`error`), or to ignore them (`ignore`). | -| `--color` arg (=`auto`) | Specify whether to colorize the output (`always`, `never`, or `auto`). | +| **option** | **explanation** | +|------------|-----------------| +| `-l` [ `--language` ] arg (=`auto`) | Input language (`pddl`, `sas`, `auto`) | +| `--warning-level` arg (=`show`) | Show warnings (`show`), treat them as errors (`error`), or ignore them (`ignore`) | +| `--color` arg (=`auto`) | Colorize output (`always`, `never`, `auto`) | diff --git a/include/plasp/Language.h b/include/plasp/Language.h index 7769a0b..e41a1b2 100644 --- a/include/plasp/Language.h +++ b/include/plasp/Language.h @@ -18,6 +18,7 @@ class Language enum class Type { Unknown, + Automatic, PDDL, SAS }; diff --git a/include/plasp/utils/Logger.h b/include/plasp/utils/Logger.h index 3fed423..55754fc 100644 --- a/include/plasp/utils/Logger.h +++ b/include/plasp/utils/Logger.h @@ -23,7 +23,7 @@ class Logger public: enum class WarningLevel { - Normal, + Show, Error, Ignore }; diff --git a/src/plasp/Language.cpp b/src/plasp/Language.cpp index 6caaeb0..a8c35f2 100644 --- a/src/plasp/Language.cpp +++ b/src/plasp/Language.cpp @@ -17,6 +17,7 @@ using LanguageNames = boost::bimap; //////////////////////////////////////////////////////////////////////////////////////////////////// const LanguageNames languageNames = boost::assign::list_of + (Language::Type::Automatic, "auto") (Language::Type::PDDL, "pddl") (Language::Type::SAS, "sas") (Language::Type::Unknown, "unknown"); diff --git a/src/plasp/utils/Logger.cpp b/src/plasp/utils/Logger.cpp index ea0470f..26875a5 100644 --- a/src/plasp/utils/Logger.cpp +++ b/src/plasp/utils/Logger.cpp @@ -16,7 +16,7 @@ namespace utils Logger::Logger() : m_outputStream(StandardStream::Out), m_errorStream(StandardStream::Err), - m_warningLevel{Logger::WarningLevel::Normal} + m_warningLevel{Logger::WarningLevel::Show} { } @@ -47,7 +47,7 @@ Logger::Logger(Logger &&other) m_errorStream{std::move(other.m_errorStream)}, m_warningLevel{other.m_warningLevel} { - other.m_warningLevel = WarningLevel::Normal; + other.m_warningLevel = WarningLevel::Show; } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -58,7 +58,7 @@ Logger &Logger::operator=(Logger &&other) m_errorStream = std::move(other.m_errorStream); m_warningLevel = other.m_warningLevel; - other.m_warningLevel = WarningLevel::Normal; + other.m_warningLevel = WarningLevel::Show; return *this; }