DryChem 1.0.0
A generic, compile-time C++ toolbox with no dependencies for the modern computational chemistry project.
Loading...
Searching...
No Matches
commandLineParser.hpp
Go to the documentation of this file.
1// Copyright (c) 2020-2025 Cody R. Drisko. All rights reserved.
2// Licensed under the MIT License. See the LICENSE file in the project root for more information.
3//
4// Name: commandLineParser.hpp
5// Author: crdrisko
6// Date: 11/19/2020-14:13:01
7// Description:
8
9#ifndef COMMANDLINEPARSER_HPP
10#define COMMANDLINEPARSER_HPP
11
12#include <filesystem>
13#include <tuple>
14#include <utility>
15
16#include <common-utils/meta.hpp>
17
18#include "cmdLineOptions.hpp"
19
20namespace GetOpts
21{
22 namespace fs = std::filesystem;
23
24 template<typename... TArgs>
26 {
27 private:
28 fs::path programName;
29
30 std::tuple<TArgs...> options;
31
32 std::string generateUsage() const
33 {
34 std::string usageMessage;
35
36 usageMessage += "\nUSAGE: " + programName.stem().string() + " [-hv";
37
38 DryChem::apply_n<3>([&](auto... elem) { ((usageMessage += elem.generateUsage()), ...); }, options);
39
40 usageMessage += "] ";
41
42 DryChem::apply_n<1>(
43 [&](auto... elem) { ((usageMessage += elem.generateUsage() + " "), ...); }, DryChem::reverse(options));
44
45 return usageMessage;
46 }
47
48 public:
49 CommandLineParser(const TArgs&... Options) : options {Options...} {}
50
51 void setCommandLineOptions(int, const char** argv) { programName = std::string {argv[0]}; }
52
53 void printHelpMessage(const std::string& exampleUsage) const
54 {
55 std::cout << generateUsage() << "\n\n";
56 std::cout << " -h Prints help information about the " << programName.stem() << " program.\n";
57 std::cout << " -v Verbose mode. Defaults to false/off.\n";
58
59 DryChem::apply_n<3>([&](auto... elem) { ((std::cout << elem.getHelpMessage() << std::endl), ...); }, options);
60
61 std::cout << '\n';
62
63 DryChem::apply_n<1>(
64 [&](auto... elem) { ((std::cout << elem.getHelpMessage() << std::endl), ...); }, DryChem::reverse(options));
65
66 std::cout << "\nEXAMPLE: " << exampleUsage << "\n\n";
67 }
68 };
69} // namespace GetOpts
70
71#endif
std::string generateUsage() const
Definition commandLineParser.hpp:32
CommandLineParser(const TArgs &... Options)
Definition commandLineParser.hpp:49
void printHelpMessage(const std::string &exampleUsage) const
Definition commandLineParser.hpp:53
std::tuple< TArgs... > options
Definition commandLineParser.hpp:30
fs::path programName
Definition commandLineParser.hpp:28
void setCommandLineOptions(int, const char **argv)
Definition commandLineParser.hpp:51
Definition cmdLineOptions.hpp:22