-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Easier usage as library - parseExchanges does not require to be last …
…anymore
- Loading branch information
Showing
13 changed files
with
134 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#pragma once | ||
|
||
#include <filesystem> | ||
#include <iostream> | ||
#include <span> | ||
#include <utility> | ||
|
||
#include "cct_vector.hpp" | ||
#include "coincenteroptions.hpp" | ||
#include "commandlineoptionsparseriterator.hpp" | ||
|
||
namespace cct { | ||
template <class ParserType> | ||
auto ParseOptions(ParserType &parser, int argc, const char *argv[]) { | ||
auto programName = std::filesystem::path(argv[0]).filename().string(); | ||
|
||
std::span<const char *> allArguments(argv, argc); | ||
|
||
// skip first argument which is program name | ||
CommandLineOptionsParserIterator parserIt(parser, allArguments.last(allArguments.size() - 1U)); | ||
|
||
using OptValueType = ParserType::value_type; | ||
OptValueType globalOptions; | ||
|
||
vector<OptValueType> parsedOptions; | ||
|
||
// Support for command line multiple commands. Only full name flags are supported for multi command line commands. | ||
while (parserIt.hasNext()) { | ||
auto groupedArguments = parserIt.next(); | ||
|
||
auto groupParsedOptions = parser.parse(groupedArguments); | ||
globalOptions.mergeGlobalWith(groupParsedOptions); | ||
|
||
if (groupedArguments.empty()) { | ||
groupParsedOptions.help = true; | ||
} | ||
if (groupParsedOptions.help) { | ||
parser.displayHelp(programName, std::cout); | ||
} else if (groupParsedOptions.version) { | ||
CoincenterCmdLineOptions::PrintVersion(programName, std::cout); | ||
} else { | ||
// Only store commands if they are not 'help' nor 'version' | ||
parsedOptions.push_back(std::move(groupParsedOptions)); | ||
} | ||
} | ||
|
||
// Apply global options to all parsed options containing commands | ||
for (auto &groupParsedOptions : parsedOptions) { | ||
groupParsedOptions.mergeGlobalWith(globalOptions); | ||
} | ||
|
||
return parsedOptions; | ||
} | ||
} // namespace cct |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.