Browse Source

Make use of std::filesystem optional

It is not available under Android yet and only used for
Bash completion. So make it optional to support Android by
disabling that part of the Bash completion which is not
useful under Android anyways.
sendfile
Martchus 3 years ago
parent
commit
1be20da35a
  1. 10
      CMakeLists.txt
  2. 7
      application/argumentparser.cpp
  3. 8
      tests/argumentparsertests.cpp

10
CMakeLists.txt

@ -160,8 +160,14 @@ else ()
message(STATUS "Using std::fstream for NativeFileStream")
endif ()
# configure required libraries for std::filestream
use_standard_filesystem()
# configure required libraries for std::filesystem
option(USE_STANDARD_FILESYSTEM "uses std::filesystem; if disabled Bash completion for files and directories is not working" ON)
if (USE_STANDARD_FILESYSTEM)
list(APPEND META_PRIVATE_COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_USE_STANDARD_FILESYSTEM)
use_standard_filesystem()
else ()
message(WARNING "The use of std::filesystem has been disabled. Bash completion for files and directories will not work.")
endif ()
# configure forcing UTF-8 code page under Windows
option(FORCE_UTF8_CODEPAGE "forces use of UTF-8 code page under Windows via ApplicationUtilities::startConsole()" OFF)

7
application/argumentparser.cpp

@ -12,12 +12,15 @@
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <filesystem>
#include <iostream>
#include <set>
#include <sstream>
#include <string>
#ifdef CPP_UTILITIES_USE_STANDARD_FILESYSTEM
#include <filesystem>
#endif
using namespace std;
using namespace std::placeholders;
using namespace std::literals;
@ -1484,6 +1487,7 @@ void ArgumentParser::printBashCompletion(int argc, const char *const *argv, unsi
}
// -> completion for files and dirs
#ifdef CPP_UTILITIES_USE_STANDARD_FILESYSTEM
if (completionInfo.completeFiles || completionInfo.completeDirs) {
using namespace std::filesystem;
const auto replace = "'"s, with = "'\"'\"'"s;
@ -1520,6 +1524,7 @@ void ArgumentParser::printBashCompletion(int argc, const char *const *argv, unsi
haveFileOrDirCompletions = true;
}
}
#endif
cout << ')';
// ensure file or dir completions are formatted appropriately

8
tests/argumentparsertests.cpp

@ -659,9 +659,13 @@ void ArgumentParserTests::testBashCompletion()
parser.resetArgs();
const char *const argv5[] = { "get", "--files", iniFilePath.c_str() };
{
#ifdef CPP_UTILITIES_USE_STANDARD_FILESYSTEM
// order for file names is not specified
const OutputCheck c("COMPREPLY=('" % mkvFilePath % " '\"'\"'with quote'\"'\"'.mkv' '" % iniFilePath + ".ini' ); compopt -o filenames\n",
"COMPREPLY=('" % iniFilePath % ".ini' '" % mkvFilePath + " '\"'\"'with quote'\"'\"'.mkv' ); compopt -o filenames\n");
#else
const OutputCheck c("COMPREPLY=()\n");
#endif
reader.reset(argv5, argv5 + 3).read();
parser.printBashCompletion(3, argv5, 2, reader);
}
@ -672,8 +676,12 @@ void ArgumentParserTests::testBashCompletion()
parser.resetArgs();
const char *const argv14[] = { "get", "--files", directoryPath.c_str() };
{
#ifdef CPP_UTILITIES_USE_STANDARD_FILESYSTEM
// order for file names is not specified
const OutputCheck c("COMPREPLY=('" % directoryPath + "subdir' ); compopt -o filenames\n");
#else
const OutputCheck c("COMPREPLY=()\n");
#endif
reader.reset(argv14, argv14 + 3).read();
parser.printBashCompletion(3, argv14, 2, reader);
}

Loading…
Cancel
Save