From 8f358fe343b280e805fece44f6afc58d786f2e8c Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Wed, 2 Dec 2020 07:28:30 +0900 Subject: [PATCH] Remove util/argparse from this project --- include/poac/cmd/init.hpp | 1 - include/poac/cmd/new.hpp | 2 - include/poac/opts/build.hpp | 1 - include/poac/opts/graph.hpp | 1 - include/poac/opts/install.hpp | 1 - include/poac/opts/run.hpp | 1 - include/poac/opts/search.hpp | 1 - include/poac/opts/uninstall.hpp | 1 - include/poac/util.hpp | 1 - include/poac/util/argparse.hpp | 67 ---------------------------- tests/CMakeLists.txt | 1 - tests/argparse.cpp | 79 --------------------------------- 12 files changed, 157 deletions(-) delete mode 100644 include/poac/util/argparse.hpp delete mode 100644 tests/argparse.cpp diff --git a/include/poac/cmd/init.hpp b/include/poac/cmd/init.hpp index b7da1f437..23e027cf6 100644 --- a/include/poac/cmd/init.hpp +++ b/include/poac/cmd/init.hpp @@ -15,7 +15,6 @@ #include #include #include -#include #include namespace poac::cmd::init { diff --git a/include/poac/cmd/new.hpp b/include/poac/cmd/new.hpp index f8d818511..0a937a2d2 100644 --- a/include/poac/cmd/new.hpp +++ b/include/poac/cmd/new.hpp @@ -21,8 +21,6 @@ #include #include #include -#include -#include #include #include diff --git a/include/poac/opts/build.hpp b/include/poac/opts/build.hpp index 5e91dd277..77a1c31d4 100644 --- a/include/poac/opts/build.hpp +++ b/include/poac/opts/build.hpp @@ -9,7 +9,6 @@ #include #include #include -#include #include namespace poac::opts::build { diff --git a/include/poac/opts/graph.hpp b/include/poac/opts/graph.hpp index 6ce2d3251..fb17e127b 100644 --- a/include/poac/opts/graph.hpp +++ b/include/poac/opts/graph.hpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include diff --git a/include/poac/opts/install.hpp b/include/poac/opts/install.hpp index cdfc942b1..f814dc3f8 100644 --- a/include/poac/opts/install.hpp +++ b/include/poac/opts/install.hpp @@ -18,7 +18,6 @@ #include #include #include -#include #include namespace poac::opts::install { diff --git a/include/poac/opts/run.hpp b/include/poac/opts/run.hpp index 76eb3f71d..6d6c974ad 100644 --- a/include/poac/opts/run.hpp +++ b/include/poac/opts/run.hpp @@ -8,7 +8,6 @@ #include #include -#include namespace poac::opts::run { inline const clap::subcommand cli = diff --git a/include/poac/opts/search.hpp b/include/poac/opts/search.hpp index 9766f4fb1..e397f222f 100644 --- a/include/poac/opts/search.hpp +++ b/include/poac/opts/search.hpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include diff --git a/include/poac/opts/uninstall.hpp b/include/poac/opts/uninstall.hpp index feac93696..31dfa9b12 100644 --- a/include/poac/opts/uninstall.hpp +++ b/include/poac/opts/uninstall.hpp @@ -18,7 +18,6 @@ #include #include #include -#include #include namespace poac::opts::uninstall { diff --git a/include/poac/util.hpp b/include/poac/util.hpp index 94bc86627..a69b74884 100644 --- a/include/poac/util.hpp +++ b/include/poac/util.hpp @@ -1,7 +1,6 @@ #ifndef POAC_UTIL_HPP #define POAC_UTIL_HPP -#include #include #include #include diff --git a/include/poac/util/argparse.hpp b/include/poac/util/argparse.hpp deleted file mode 100644 index 44f31acc2..000000000 --- a/include/poac/util/argparse.hpp +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef POAC_UTIL_ARGPARSE_HPP -#define POAC_UTIL_ARGPARSE_HPP - -#include -#include -#include -#include -#include -#include - -#include - -namespace poac::util::argparse { - template - bool use(SinglePassRange& rng, T... args) { - const auto first = std::cbegin(rng); - const auto last = std::cend(rng); - return ((std::find(first, last, args) != last) || ...); - } - - // { arg1, arg2 }, arg2 -> { arg1 } - template - bool use_rm(SinglePassRange& rng, T... args) { - const auto first = std::begin(rng); - auto last = std::end(rng); - bool found = false; - for (const auto& a : types::tuple_to_array(std::tuple{ args... })) { - if (const auto itr = std::find(first, last, a); itr != last) { - rng.erase(itr); - last = std::end(rng); - found = true; - } - } - return found; - } - - // -o filename -> return filename - template - std::optional - use_get(SinglePassRange& rng, T arg) { - const auto first = std::cbegin(rng); - const auto last = std::cend(rng); - if (const auto result = std::find(first, last, arg); result != last) { - return *(result + 1); - } - else { - return std::nullopt; - } - } - // -o filename OR --output filename -> return filename - template - std::optional - use_get(SinglePassRange& rng, T arg1, T arg2) { - const auto first = std::cbegin(rng); - const auto last = std::cend(rng); - if (const auto result1 = std::find(first, last, arg1); result1 != last) { - return *(result1 + 1); - } - else if (const auto result2 = std::find(first, last, arg2); result2 != last) { - return *(result2 + 1); - } - else { - return std::nullopt; - } - } -} // end namespace -#endif // !POAC_UTIL_ARGPARSE_HPP diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 17016eab9..7b5d9e37f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,5 +1,4 @@ set(TEST_NAMES - argparse cfg config except diff --git a/tests/argparse.cpp b/tests/argparse.cpp deleted file mode 100644 index 726bce8e5..000000000 --- a/tests/argparse.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#define BOOST_TEST_MAIN -#include - -#include -#include - -#include - -// bool use(SinglePassRange& rng, T... args) -BOOST_AUTO_TEST_CASE( poac_util_argparse_use_test ) -{ - using poac::util::argparse::use; - - std::vector temp{ "-h", "--help", "--flag" }; - BOOST_CHECK( use(temp, "-h") ); - BOOST_CHECK( use(temp, "-h", "--help") ); - BOOST_CHECK( use(temp, "-h", "--help", "--no") ); - BOOST_CHECK( !use(temp, "-n", "--no") ); -} - -// bool use_rm(SinglePassRange& rng, T... args) -BOOST_AUTO_TEST_CASE( poac_util_argparse_use_rm_test ) -{ - using poac::util::argparse::use; - using poac::util::argparse::use_rm; - - std::vector temp{ "-h", "--help", "--flag" }; - BOOST_CHECK( use_rm(temp, "-h") ); - BOOST_CHECK( !use(temp, "-h") ); - BOOST_CHECK( use(temp, "--help") ); - BOOST_CHECK( use(temp, "--flag") ); - - temp = { "-h", "--help", "--flag" }; - BOOST_CHECK( use_rm(temp, "-h", "--help") ); - BOOST_CHECK( !use(temp, "-h", "--help") ); - BOOST_CHECK( use(temp, "--flag") ); - - temp = { "-h", "--help", "--flag" }; - BOOST_CHECK( !use_rm(temp, "-n", "--no") ); - BOOST_CHECK( use(temp, "-h", "--help", "--flag") ); -} - -// 1. std::optional use_get(SinglePassRange& rng, T arg) -// 2. std::optional use_get(SinglePassRange& rng, T arg1, T arg2) -BOOST_AUTO_TEST_CASE( poac_util_argparse_use_get_test ) -{ - using poac::util::argparse::use_get; - - std::vector temp{ "-o", "output.o", "--flag" }; - - // 1 - auto res = use_get(temp, "-o"); - BOOST_CHECK( res.has_value() ); - BOOST_CHECK( res.value() == "output.o" ); - - temp = { "-h", "--help", "--flag" }; - res = use_get(temp, "-o"); - BOOST_CHECK( !res.has_value() ); - - // 2 - temp = { "--output", "output.o", "--flag" }; - res = use_get(temp, "-o", "--output"); - BOOST_CHECK( res.has_value() ); - BOOST_CHECK( res.value() == "output.o" ); - - temp = { "--output", "output.o", "--flag" }; - res = use_get(temp, "--output", "-o"); - BOOST_CHECK( res.has_value() ); - BOOST_CHECK( res.value() == "output.o" ); - - temp = { "-o", "output.o", "--flag" }; - res = use_get(temp, "--no", "-o"); - BOOST_CHECK( res.has_value() ); - BOOST_CHECK( res.value() == "output.o" ); - - temp = { "-h", "--help", "--flag" }; - res = use_get(temp, "-o", "--output"); - BOOST_CHECK( !res.has_value() ); -}