Use std::filesystem in argumentparser.cpp
This commit is contained in:
parent
579199fa73
commit
1ad90eb770
|
@ -156,6 +156,10 @@ else ()
|
||||||
message(STATUS "Using std::fstream for NativeFileStream")
|
message(STATUS "Using std::fstream for NativeFileStream")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
# configure required libraries for std::filestream
|
||||||
|
message(STATUS "calling use_filesystem()")
|
||||||
|
use_standard_filesystem()
|
||||||
|
|
||||||
# configure forcing UTF-8 code page under Windows
|
# 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)
|
option(FORCE_UTF8_CODEPAGE "forces use of UTF-8 code page under Windows via ApplicationUtilities::startConsole()" OFF)
|
||||||
if (FORCE_UTF8_CODEPAGE)
|
if (FORCE_UTF8_CODEPAGE)
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <filesystem>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
@ -19,6 +20,7 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
|
using namespace std::literals;
|
||||||
using namespace ConversionUtilities;
|
using namespace ConversionUtilities;
|
||||||
using namespace EscapeCodes;
|
using namespace EscapeCodes;
|
||||||
using namespace IoUtilities;
|
using namespace IoUtilities;
|
||||||
|
@ -1515,38 +1517,42 @@ void ArgumentParser::printBashCompletion(int argc, const char *const *argv, unsi
|
||||||
}
|
}
|
||||||
|
|
||||||
// -> completion for files and dirs
|
// -> completion for files and dirs
|
||||||
DirectoryEntryType entryTypes = DirectoryEntryType::None;
|
if (completionInfo.completeFiles || completionInfo.completeDirs) {
|
||||||
if (completionInfo.completeFiles) {
|
using namespace std::filesystem;
|
||||||
entryTypes |= DirectoryEntryType::File;
|
const auto replace = "'"s, with = "'\"'\"'"s;
|
||||||
}
|
const auto useActualDir = argc && currentWordIndex <= completionInfo.lastSpecifiedArgIndex && opening;
|
||||||
if (completionInfo.completeDirs) {
|
const auto dirEntries = [&] {
|
||||||
entryTypes |= DirectoryEntryType::Directory;
|
directory_iterator i;
|
||||||
}
|
if (useActualDir) {
|
||||||
if (entryTypes != DirectoryEntryType::None) {
|
i = directory_iterator(actualDir);
|
||||||
const string replace("'"), with("'\"'\"'");
|
|
||||||
if (argc && currentWordIndex <= completionInfo.lastSpecifiedArgIndex && opening) {
|
|
||||||
list<string> entries = directoryEntries(actualDir.c_str(), entryTypes);
|
|
||||||
findAndReplace(actualDir, replace, with);
|
findAndReplace(actualDir, replace, with);
|
||||||
for (string &dirEntry : entries) {
|
} else {
|
||||||
if (!startsWith(dirEntry, actualFile)) {
|
i = directory_iterator(".");
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}();
|
||||||
|
for (const auto &dirEntry : dirEntries) {
|
||||||
|
if (!completionInfo.completeDirs && dirEntry.is_directory()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!completionInfo.completeFiles && !dirEntry.is_directory()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
auto dirEntryName = dirEntry.path().filename().string();
|
||||||
|
if (useActualDir) {
|
||||||
|
if (!startsWith(dirEntryName, actualFile)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
cout << '\'';
|
cout << '\'';
|
||||||
if (actualDir != ".") {
|
if (actualDir != ".") {
|
||||||
cout << actualDir;
|
cout << actualDir;
|
||||||
}
|
}
|
||||||
findAndReplace(dirEntry, replace, with);
|
|
||||||
cout << dirEntry << '\'' << ' ';
|
|
||||||
haveFileOrDirCompletions = true;
|
|
||||||
}
|
}
|
||||||
} else {
|
findAndReplace(dirEntryName, replace, with);
|
||||||
for (string &dirEntry : directoryEntries(".", entryTypes)) {
|
cout << dirEntryName << '\'' << ' ';
|
||||||
findAndReplace(dirEntry, replace, with);
|
|
||||||
cout << '\'' << dirEntry << '\'' << ' ';
|
|
||||||
haveFileOrDirCompletions = true;
|
haveFileOrDirCompletions = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
cout << ')';
|
cout << ')';
|
||||||
|
|
||||||
// ensure file or dir completions are formatted appropriately
|
// ensure file or dir completions are formatted appropriately
|
||||||
|
|
Loading…
Reference in New Issue