added commandline utilities
This commit is contained in:
parent
3c395a955a
commit
f335c262b2
|
@ -0,0 +1,32 @@
|
|||
#include "commandlineutils.h"
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace ApplicationUtilities {
|
||||
|
||||
bool confirmPrompt(const char *message, Response defaultResponse)
|
||||
{
|
||||
cout << message;
|
||||
cout << ' ' << '[';
|
||||
cout << (defaultResponse == Response::Yes ? 'Y' : 'y');
|
||||
cout << '/' << (defaultResponse == Response::No ? 'N' : 'n');
|
||||
cout << ']' << ' ';
|
||||
cout.flush();
|
||||
for(string line; ;) {
|
||||
getline(cin, line);
|
||||
if(line == "y" || line == "Y" || (defaultResponse == Response::Yes && line.empty())) {
|
||||
return true;
|
||||
} else if(line == "n" || line == "N" || (defaultResponse == Response::No && line.empty())) {
|
||||
return false;
|
||||
} else {
|
||||
cout << "Please enter [y] or [n]: ";
|
||||
cout.flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ApplicationUtilities
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
#ifndef APPLICATIONUTILITIES_COMMANDLINEUTILS_H
|
||||
#define APPLICATIONUTILITIES_COMMANDLINEUTILS_H
|
||||
|
||||
#include "global.h"
|
||||
|
||||
namespace ApplicationUtilities {
|
||||
|
||||
enum class Response
|
||||
{
|
||||
None,
|
||||
Yes,
|
||||
No
|
||||
};
|
||||
|
||||
bool LIB_EXPORT confirmPrompt(const char *message, Response defaultResponse = Response::None);
|
||||
|
||||
} // namespace ApplicationUtilities
|
||||
|
||||
#endif // APPLICATIONUTILITIES_COMMANDLINEUTILS_H
|
|
@ -1,4 +1,5 @@
|
|||
projectname = c++utilities
|
||||
VERSION = 1.0.6
|
||||
|
||||
# include ../../common.pri when building as part of a subdirs project; otherwise include general.pri
|
||||
!include(../../common.pri) {
|
||||
|
@ -27,7 +28,8 @@ SOURCES += \
|
|||
application/fakeqtconfigarguments.cpp \
|
||||
io/ansiescapecodes.cpp \
|
||||
misc/random.cpp \
|
||||
io/bitreader.cpp
|
||||
io/bitreader.cpp \
|
||||
application/commandlineutils.cpp
|
||||
|
||||
HEADERS += \
|
||||
application/global.h \
|
||||
|
@ -51,7 +53,8 @@ HEADERS += \
|
|||
io/ansiescapecodes.h \
|
||||
misc/memory.h \
|
||||
misc/random.h \
|
||||
io/bitreader.h
|
||||
io/bitreader.h \
|
||||
application/commandlineutils.h
|
||||
|
||||
OTHER_FILES += \
|
||||
README.md \
|
||||
|
|
12
general.pri
12
general.pri
|
@ -12,7 +12,17 @@ unix {
|
|||
QMAKE_LFLAGS += "-Wl,--rpath=./"
|
||||
}
|
||||
# prefix
|
||||
targetprefix = .
|
||||
targetprefix = $$(TARGET_PREFIX)
|
||||
equals(targetprefix, "") {
|
||||
win32 {
|
||||
targetprefix = ../../..
|
||||
} else {
|
||||
targetprefix = ../..
|
||||
}
|
||||
}
|
||||
message("Using target prefix \"$${targetprefix}\".")
|
||||
# print install root
|
||||
message("Using install root \"$$(INSTALL_ROOT)\".")
|
||||
# target
|
||||
CONFIG(debug, debug|release) {
|
||||
TARGET = $$targetprefix/$${projectname}d
|
||||
|
|
Loading…
Reference in New Issue