29 void print_help(
const std::string& program,
bool two_files) {
32 <<
" " << program <<
" [-h | --help ] "
33 << (two_files ?
"SRC_FILE SRC_TREE [DEST_FILE DEST_TREE]" :
"FILE TREE") <<
"\n"
36 <<
" -h, --help : print this help and exit\n"
41 <<
" SRC_FILE : source file from-which to read HDTree (and write if no DEST_FILE)\n"
42 <<
" SRC_TREE : source tree from-which to read (and write if no DEST_TREE)\n"
43 <<
" DEST_FILE : destination file to write to (optional but needs DEST_TREE as well)\n"
44 <<
" DEST_TREE : destination tree to write to (optional but needs DEST_FILE as well)\n";
47 <<
" FILE : file to access for interacting with HDTree\n"
48 <<
" TREE : name of tree in that file to interact with\n";
50 std::cout << std::endl;
63 std::string& filename, std::string& treename) {
64 std::string program{argv[0]};
65 std::vector<std::string> positionals;
66 for (
int i_arg{1}; i_arg < argc; ++i_arg) {
67 std::string arg{argv[i_arg]};
68 if (arg ==
"-h" or arg ==
"--help") {
72 positionals.emplace_back(arg);
76 if (positionals.size() == 0) {
82 if (positionals.size() != 2) {
83 std::cerr <<
" ERROR: " << program <<
" requires two arguments: FILE TREE" << std::endl;
87 filename = positionals.at(0);
88 treename = positionals.at(1);
102 std::pair<std::string,std::string>& src, std::pair<std::string,std::string>& dest) {
103 std::string program{argv[0]};
104 std::vector<std::string> positionals;
105 for (
int i_arg{1}; i_arg < argc; ++i_arg) {
106 std::string arg{argv[i_arg]};
107 if (arg ==
"-h" or arg ==
"--help") {
111 positionals.emplace_back(arg);
115 if (positionals.size() == 0) {
121 if (positionals.size() != 2 and positionals.size() != 4) {
122 std::cerr <<
" ERROR: " << program <<
" requires two or four arguments." << std::endl;
126 src.first = positionals.at(0);
127 src.second = positionals.at(1);
128 if (positionals.size() > 2) {
129 dest.first = positionals.at(2);
130 dest.second = positionals.at(3);
namespace holding utility functions for example programs
Definition: examples.h:21
int parse_single_file_args(int argc, char **argv, std::string &filename, std::string &treename)
single file command line parser
Definition: examples.h:62
void print_help(const std::string &program, bool two_files)
print help for the single file command line parser
Definition: examples.h:29
int parse_two_file_args(int argc, char **argv, std::pair< std::string, std::string > &src, std::pair< std::string, std::string > &dest)
potentially two file command line parser
Definition: examples.h:101