mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-04-30 04:33:53 +00:00
Travis improvements and updates (#28)
* Adding check for style * Adding reformats * Fix syntax error in travis * Support clang-format 3.9 * Adding clang-tidy check
This commit is contained in:
parent
b88f1f2ac7
commit
54114d0948
17
.ci/check_style.sh
Executable file
17
.ci/check_style.sh
Executable file
@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env sh
|
||||
set -evx
|
||||
|
||||
clang-format --version
|
||||
|
||||
git ls-files -- '*.cpp' '*.hpp' | xargs clang-format -i -style=file
|
||||
|
||||
git diff --exit-code --color
|
||||
|
||||
mkdir build || true
|
||||
cd build
|
||||
CXX_FLAGS="-Werror -Wall -Wextra -pedantic -std=c++11" cmake .. -DCLANG_TIDY_FIX=ON
|
||||
cmake --build .
|
||||
|
||||
git diff --exit-code --color
|
||||
|
||||
set +evx
|
@ -9,6 +9,8 @@ if [ "$CXX" = "g++" ] ; then
|
||||
else
|
||||
ln -s `which clang-$COMPILER` clang
|
||||
ln -s `which clang++-$COMPILER` clang++
|
||||
ln -s `which clang-format-$COMPILER` clang-format
|
||||
ln -s `which clang-tidy-$COMPILER` clang-tidy
|
||||
fi
|
||||
|
||||
export PATH="${DEPS_DIR}/extrabin":$PATH
|
||||
|
@ -6,3 +6,5 @@ cd build
|
||||
cmake .. -DCLI_SINGLE_FILE_TESTS=ON -DCMAKE_BUILD_TYPE=Debug
|
||||
cmake --build . -- -j2
|
||||
ctest --output-on-failure
|
||||
|
||||
set +evx
|
||||
|
35
.travis.yml
35
.travis.yml
@ -13,9 +13,16 @@ matrix:
|
||||
- compiler: clang
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- llvm-toolchain-precise-3.5
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- clang-3.9
|
||||
- clang-format-3.9
|
||||
- clang-tidy-3.9
|
||||
env:
|
||||
- COMPILER=3.9
|
||||
- CHECK_STYLE=yes
|
||||
- compiler: clang
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.5
|
||||
env:
|
||||
@ -37,8 +44,6 @@ matrix:
|
||||
- compiler: gcc
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- g++-4.7
|
||||
env:
|
||||
@ -48,19 +53,21 @@ matrix:
|
||||
install:
|
||||
- python -c 'import sys; print(sys.version_info[:])'
|
||||
- DEPS_DIR="${TRAVIS_BUILD_DIR}/deps"
|
||||
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then cd $TRAVIS_BUILD_DIR && . .ci/prepare_altern.sh
|
||||
; fi
|
||||
- if [ "$TRAVIS_OS_NAME" = "linux" ] ; then cd $TRAVIS_BUILD_DIR && . .ci/build_cmake.sh
|
||||
; fi
|
||||
- if [ "$TRAVIS_OS_NAME" = "linux" ] ; then cd $TRAVIS_BUILD_DIR && . .ci/build_doxygen.sh
|
||||
; fi
|
||||
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then cd $TRAVIS_BUILD_DIR && . .ci/prepare_altern.sh ; fi
|
||||
- if [ "$TRAVIS_OS_NAME" = "linux" ] ; then cd $TRAVIS_BUILD_DIR && . .ci/build_cmake.sh ; fi
|
||||
- if [ "$TRAVIS_OS_NAME" = "linux" ] ; then cd $TRAVIS_BUILD_DIR && . .ci/build_doxygen.sh ; fi
|
||||
- if [ -n "$COVERALLS" ] ; then cd $TRAVIS_BUILD_DIR && . .ci/build_lcov.sh ; fi
|
||||
- cd "${DEPS_DIR}"
|
||||
- if [ "$(python -c 'import sys; print(sys.version_info[0])')" = "2" ] ; then pip
|
||||
install --user pathlib; fi
|
||||
- if [ "$(python -c 'import sys; print(sys.version_info[0])')" = "2" ] ; then pip install --user pathlib ; fi
|
||||
script:
|
||||
- cd "${TRAVIS_BUILD_DIR}"
|
||||
- .ci/travis.sh
|
||||
- |
|
||||
if [ -n "$CHECK_STYLE" ]
|
||||
then
|
||||
.ci/check_style.sh
|
||||
else
|
||||
.ci/travis.sh
|
||||
fi
|
||||
after_success:
|
||||
- if [ -n "$COVERALLS" ] ; then cd $TRAVIS_BUILD_DIR && .ci/run_codecov.sh ; fi
|
||||
- echo "${TRAVIS_BRANCH}"
|
||||
|
@ -1,10 +1,6 @@
|
||||
#include <CLI/CLI.hpp>
|
||||
|
||||
enum Level : std::int32_t {
|
||||
High,
|
||||
Medium,
|
||||
Low
|
||||
};
|
||||
enum Level : std::int32_t { High, Medium, Low };
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
CLI::App app;
|
||||
@ -20,4 +16,3 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -6,8 +6,7 @@ int main(int argc, char **argv) {
|
||||
app.prefix_command();
|
||||
|
||||
std::vector<int> vals;
|
||||
app.add_option("--vals,-v", vals)
|
||||
->expected(1);
|
||||
app.add_option("--vals,-v", vals)->expected(1);
|
||||
|
||||
std::vector<std::string> more_comms;
|
||||
try {
|
||||
|
@ -226,8 +226,6 @@ class App {
|
||||
throw OptionAlreadyAdded(myopt.get_name());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// Add option for non-vectors (duplicate copy needed without defaulted to avoid `iostream << value`)
|
||||
template <typename T, enable_if_t<!is_vector<T>::value, detail::enabler> = detail::dummy>
|
||||
Option *add_option(std::string name,
|
||||
@ -1068,10 +1066,8 @@ class App {
|
||||
size_t _count_remaining_required_positionals() const {
|
||||
size_t retval = 0;
|
||||
for(const Option_p &opt : options_)
|
||||
if(opt->get_positional()
|
||||
&& opt->get_required()
|
||||
&& opt->get_expected() > 0
|
||||
&& static_cast<int>(opt->count()) < opt->get_expected())
|
||||
if(opt->get_positional() && opt->get_required() && opt->get_expected() > 0 &&
|
||||
static_cast<int>(opt->count()) < opt->get_expected())
|
||||
retval = static_cast<size_t>(opt->get_expected()) - opt->count();
|
||||
|
||||
return retval;
|
||||
@ -1106,7 +1102,6 @@ class App {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// Parse a subcommand, modify args and continue
|
||||
|
@ -433,7 +433,6 @@ class Option {
|
||||
/// Set the default value string representation
|
||||
void set_default_val(std::string val) { defaultval_ = val; }
|
||||
|
||||
|
||||
/// Set the type name displayed on this option
|
||||
void set_type_name(std::string val) { typeval_ = val; }
|
||||
|
||||
|
@ -75,9 +75,8 @@ constexpr const char *type_name() {
|
||||
// Lexical cast
|
||||
|
||||
/// Integers / enums
|
||||
template <typename T, enable_if_t<std::is_integral<T>::value
|
||||
|| std::is_enum<T>::value
|
||||
, detail::enabler> = detail::dummy>
|
||||
template <typename T,
|
||||
enable_if_t<std::is_integral<T>::value || std::is_enum<T>::value, detail::enabler> = detail::dummy>
|
||||
bool lexical_cast(std::string input, T &output) {
|
||||
try {
|
||||
output = static_cast<T>(std::stoll(input));
|
||||
@ -103,11 +102,9 @@ bool lexical_cast(std::string input, T &output) {
|
||||
}
|
||||
|
||||
/// String and similar
|
||||
template <
|
||||
typename T,
|
||||
enable_if_t<!std::is_floating_point<T>::value
|
||||
&& !std::is_integral<T>::value
|
||||
&& !std::is_enum<T>::value, detail::enabler> = detail::dummy>
|
||||
template <typename T,
|
||||
enable_if_t<!std::is_floating_point<T>::value && !std::is_integral<T>::value && !std::is_enum<T>::value,
|
||||
detail::enabler> = detail::dummy>
|
||||
bool lexical_cast(std::string input, T &output) {
|
||||
output = input;
|
||||
return true;
|
||||
|
@ -204,11 +204,7 @@ TEST_F(TApp, DefaultOpts) {
|
||||
}
|
||||
|
||||
TEST_F(TApp, EnumTest) {
|
||||
enum Level : std::int32_t {
|
||||
High,
|
||||
Medium,
|
||||
Low
|
||||
};
|
||||
enum Level : std::int32_t { High, Medium, Low };
|
||||
Level level = Level::Low;
|
||||
app.add_option("--level", level);
|
||||
|
||||
@ -218,11 +214,7 @@ TEST_F(TApp, EnumTest) {
|
||||
}
|
||||
|
||||
TEST_F(TApp, NewEnumTest) {
|
||||
enum class Level2 : std::int32_t {
|
||||
High,
|
||||
Medium,
|
||||
Low
|
||||
};
|
||||
enum class Level2 : std::int32_t { High, Medium, Low };
|
||||
Level2 level = Level2::Low;
|
||||
app.add_option("--level", level);
|
||||
|
||||
@ -231,7 +223,6 @@ TEST_F(TApp, NewEnumTest) {
|
||||
EXPECT_EQ(level, Level2::Medium);
|
||||
}
|
||||
|
||||
|
||||
TEST_F(TApp, RequiredFlags) {
|
||||
app.add_flag("-a")->required();
|
||||
app.add_flag("-b")->mandatory(); // Alternate term
|
||||
@ -440,7 +431,6 @@ TEST_F(TApp, InSetWithDefault) {
|
||||
EXPECT_THROW(run(), CLI::ConversionError);
|
||||
}
|
||||
|
||||
|
||||
TEST_F(TApp, InCaselessSetWithDefault) {
|
||||
|
||||
std::string choice = "one";
|
||||
@ -532,7 +522,6 @@ TEST_F(TApp, VectorFixedString) {
|
||||
EXPECT_EQ(answer, strvec);
|
||||
}
|
||||
|
||||
|
||||
TEST_F(TApp, VectorDefaultedFixedString) {
|
||||
std::vector<std::string> strvec{"one"};
|
||||
std::vector<std::string> answer{"mystring", "mystring2", "mystring3"};
|
||||
|
@ -316,7 +316,6 @@ TEST_F(TApp, PrefixProgram) {
|
||||
auto ret_args = run();
|
||||
|
||||
EXPECT_EQ(ret_args, std::vector<std::string>({"--mine", "--simple", "other"}));
|
||||
|
||||
}
|
||||
|
||||
struct SubcommandProgram : public TApp {
|
||||
|
Loading…
x
Reference in New Issue
Block a user