Use new argument parser API
This commit is contained in:
parent
f5a6c9a23b
commit
4c71054cfd
|
@ -116,8 +116,12 @@ set(ICON_FILES
|
|||
resources/icons/hicolor/scalable/apps/${META_PROJECT_NAME}.svg
|
||||
)
|
||||
|
||||
set(DOC_FILES
|
||||
README.md
|
||||
)
|
||||
|
||||
# find c++utilities
|
||||
find_package(c++utilities 3.3.0 REQUIRED)
|
||||
find_package(c++utilities 4.0.0 REQUIRED)
|
||||
use_cpp_utilities()
|
||||
|
||||
# find qtutilities
|
||||
|
|
|
@ -30,19 +30,21 @@ int main(int argc, char *argv[])
|
|||
ArgumentParser parser;
|
||||
QT_CONFIG_ARGUMENTS qtConfigArgs;
|
||||
HelpArgument helpArg(parser);
|
||||
Argument noConfirmArg("no-confirm", "n", "start downloading without confirmation");
|
||||
Argument noConfirmArg("no-confirm", 'n', "start downloading without confirmation");
|
||||
noConfirmArg.setCombinable(true);
|
||||
Argument downloadArg("download", "d", "downloads the specified data");
|
||||
downloadArg.setValueNames({"URL1", "URL2", "URL3"});
|
||||
downloadArg.setRequiredValueCount(-1);
|
||||
Argument urlsArg("urls", 'u', "specifies the URLs to download");
|
||||
urlsArg.setRequiredValueCount(-1);
|
||||
urlsArg.setValueNames({"URL1", "URL2", "URL3"});
|
||||
urlsArg.setImplicit(true);
|
||||
Argument downloadArg("download", 'd', "downloads the specified data");
|
||||
downloadArg.setDenotesOperation(true);
|
||||
downloadArg.setSecondaryArguments({&noConfirmArg});
|
||||
downloadArg.setCallback(bind(Cli::download, argc, argv, _1, cref(noConfirmArg)));
|
||||
downloadArg.setSubArguments({&urlsArg, &noConfirmArg});
|
||||
downloadArg.setCallback(bind(Cli::download, argc, argv, _1, cref(urlsArg), cref(noConfirmArg)));
|
||||
parser.setMainArguments({&qtConfigArgs.qtWidgetsGuiArg(), &downloadArg, &helpArg});
|
||||
// parse arguments
|
||||
try {
|
||||
parser.parseArgs(argc, argv);
|
||||
} catch (Failure &ex) {
|
||||
} catch (const Failure &ex) {
|
||||
CMD_UTILS_START_CONSOLE;
|
||||
cout << "Unable to parse arguments. " << ex.what() << "\nSee --help for available commands." << endl;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ using namespace Network;
|
|||
|
||||
namespace Cli {
|
||||
|
||||
void download(int argc, char *argv[], const StringVector ¶meterValues, const Argument &noConfirmArg)
|
||||
void download(int argc, char *argv[], const std::vector<const char *> &, const Argument &urlsArg, const Argument &noConfirmArg)
|
||||
{
|
||||
CMD_UTILS_START_CONSOLE;
|
||||
// init Qt
|
||||
|
@ -29,14 +29,14 @@ void download(int argc, char *argv[], const StringVector ¶meterValues, const
|
|||
QObject rootObj;
|
||||
// instantiate downloads
|
||||
QList<Download *> downloads;
|
||||
downloads.reserve(parameterValues.size());
|
||||
downloads.reserve(urlsArg.values().size());
|
||||
QVariant currentTargetDirectory;
|
||||
QVariant currentTargetName;
|
||||
enum {
|
||||
Auto, HttpUrl, YoutubeUrl, YoutubeId, GroovesharkId
|
||||
} currentDownloadType = Auto;
|
||||
size_t specifiedDownloads = 0;
|
||||
for(const auto &val : parameterValues) {
|
||||
for(const auto &val : urlsArg.values()) {
|
||||
// check whether value denotes target directory or download type
|
||||
auto parts = splitString<vector<string> >(val, "=", EmptyPartsTreat::Keep, 2);
|
||||
if(parts.size() >= 2) {
|
||||
|
|
|
@ -2,18 +2,14 @@
|
|||
#define CLI_MAINFEATURES_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace ApplicationUtilities {
|
||||
|
||||
typedef std::vector<std::string> StringVector;
|
||||
class Argument;
|
||||
|
||||
}
|
||||
|
||||
namespace Cli {
|
||||
|
||||
void download(int argc, char *argv[], const ApplicationUtilities::StringVector ¶meterValues, const ApplicationUtilities::Argument &noConfirmArg);
|
||||
void download(int argc, char *argv[], const std::vector<const char *> ¶meterValues, const ApplicationUtilities::Argument &urlsArg, const ApplicationUtilities::Argument &noConfirmArg);
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue