mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-04-30 04:33:53 +00:00
This mostly is cleanup, with fewer alternative methods and more standard syntax, avoiding the use of the namespace all the time. Validators are simpler and are added through `->check()`. Defaults are automatic, and can be specified with a final arg to the options. Expected arguments and required arguments are now accessed through a pointer to option. Option now can be checked as a bool to see if the argument was passed. Errors have better organisation.
43 lines
1.0 KiB
C++
43 lines
1.0 KiB
C++
#pragma once
|
|
|
|
// Distributed under the LGPL version 3.0 license. See accompanying
|
|
// file LICENSE or https://github.com/henryiii/CLI11 for details.
|
|
|
|
#include <string>
|
|
|
|
|
|
// C standard library
|
|
// Only needed for existence checking
|
|
// Could be swapped for filesystem in C++17
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
|
|
namespace CLI {
|
|
|
|
|
|
/// Check for an existing file
|
|
bool ExistingFile(std::string filename) {
|
|
// std::fstream f(name.c_str());
|
|
// return f.good();
|
|
// Fastest way according to http://stackoverflow.com/questions/12774207/fastest-way-to-check-if-a-file-exist-using-standard-c-c11-c
|
|
struct stat buffer;
|
|
return (stat(filename.c_str(), &buffer) == 0);
|
|
}
|
|
|
|
/// Check for an existing directory
|
|
bool ExistingDirectory(std::string filename) {
|
|
struct stat buffer;
|
|
if(stat(filename.c_str(), &buffer) == 0 && (buffer.st_mode & S_IFDIR) )
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
/// Check for a non-existing path
|
|
bool NonexistentPath(std::string filename) {
|
|
struct stat buffer;
|
|
return stat(filename.c_str(), &buffer) != 0;
|
|
}
|
|
|
|
|
|
}
|