From 6d46876f5cb461afc664ae7ceec2ffb90e0497b0 Mon Sep 17 00:00:00 2001 From: Stephan van Veen Date: Sat, 25 May 2019 20:07:24 +0200 Subject: [PATCH] Do some cleanup in print_help --- include/argparse.hpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/include/argparse.hpp b/include/argparse.hpp index df33ccc..f338f58 100644 --- a/include/argparse.hpp +++ b/include/argparse.hpp @@ -381,26 +381,25 @@ class ArgumentParser { std::string print_help() { std::stringstream stream; stream << std::left; - stream << "Usage: " << mProgramName << " [options]"; + stream << "Usage: " << mProgramName << " [options] "; size_t tLongestArgumentLength = get_length_of_longest_argument(); - for (size_t i = 0; i < mPositionalArguments.size(); i++) { - auto tNames = mPositionalArguments[i]->mNames; - stream << (i == 0 ? " " : "") << tNames[0] << " "; + for (const auto& argument : mPositionalArguments) { + stream << argument->mNames.front() << " "; } stream << "\n\n"; if (!mPositionalArguments.empty()) stream << "Positional arguments:\n"; + for (const auto& mPositionalArgument : mPositionalArguments) { stream.width(tLongestArgumentLength); stream << *mPositionalArgument; } - if (!mOptionalArguments.empty() && !mPositionalArguments.empty()) - stream << "\nOptional arguments:\n"; - else if (!mOptionalArguments.empty()) - stream << "Optional arguments:\n"; + if (!mOptionalArguments.empty()) + stream << (mPositionalArguments.empty() ? "" : "\n") << "Optional arguments:\n"; + for (const auto & mOptionalArgument : mOptionalArguments) { stream.width(tLongestArgumentLength); stream << *mOptionalArgument;