X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fcore%2Fgetopt.cpp;h=0f8886ad746a542e3a40b36ed8e7c2ddcd0c1e19;hp=e42ceb2143fb28265277c534af6c536878f16a03;hb=20c897ece781e18ba54c41fd68e232ce566a938d;hpb=b54e273fec47af51792955143e84417b638ad2b7 diff --git a/source/core/getopt.cpp b/source/core/getopt.cpp index e42ceb2..0f8886a 100644 --- a/source/core/getopt.cpp +++ b/source/core/getopt.cpp @@ -105,7 +105,7 @@ void GetOpt::operator()(unsigned argc, const char *const *argv) else args_raw.push_back(argv[i++]); } - + for(; iget_short()) + for(OptionList::const_iterator i=opts.begin(); i!=opts.end(); ++i) { - result += format("-%c", (*i)->get_short()); + result += " ["; + if((*i)->get_short()) + { + result += format("-%c", (*i)->get_short()); + if(!(*i)->get_long().empty()) + result += '|'; + else if((*i)->get_arg_type()==OPTIONAL_ARG) + result += format("[%s]", (*i)->get_metavar()); + else if((*i)->get_arg_type()==REQUIRED_ARG) + result += format(" %s", (*i)->get_metavar()); + } if(!(*i)->get_long().empty()) - result += '|'; - else if((*i)->get_arg_type()==OPTIONAL_ARG) - result += format("[%s]", (*i)->get_metavar()); - else if((*i)->get_arg_type()==REQUIRED_ARG) - result += format(" %s", (*i)->get_metavar()); - } - if(!(*i)->get_long().empty()) - { - result += format("--%s", (*i)->get_long()); + { + result += format("--%s", (*i)->get_long()); - if((*i)->get_arg_type()==OPTIONAL_ARG) - result += format("[=%s]", (*i)->get_metavar()); - else if((*i)->get_arg_type()==REQUIRED_ARG) - result += format("=%s", (*i)->get_metavar()); + if((*i)->get_arg_type()==OPTIONAL_ARG) + result += format("[=%s]", (*i)->get_metavar()); + else if((*i)->get_arg_type()==REQUIRED_ARG) + result += format("=%s", (*i)->get_metavar()); + } + result += ']'; } - result += ']'; } for(ArgumentList::const_iterator i=args.begin(); i!=args.end(); ++i) @@ -304,12 +310,12 @@ string GetOpt::generate_help() const for(ArgumentList::const_iterator i=args.begin(); i!=args.end(); ++i, ++j) result += format(" %s%s%s\n", *j, string(maxw+2-j->size(), ' '), (*i)->get_help()); } - + return result; } -GetOpt::OptionImpl::OptionImpl(char s, const std::string &l, const Store &t, ArgType a): +GetOpt::OptionImpl::OptionImpl(char s, const string &l, const Store &t, ArgType a): shrt(s), lng(l), arg_type(a),