Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 29, 2009, 11:59:29 PM (16 years ago)
Author:
rgrieder
Message:

#298: Improved usage dialogue creation and the information itself.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core4/src/core/CommandLine.cc

    r3250 r3255  
    2929#include "CommandLine.h"
    3030
     31#include <sstream>
    3132#include <boost/filesystem.hpp>
    3233
     
    231232        {
    232233            COUT(0) << "Could not parse command line (including additional files): " << ex.what() << std::endl;
    233             COUT(0) << "Usage:" << std::endl << "orxonox " << CommandLine::getUsageInformation() << std::endl;
     234            COUT(0) << CommandLine::getUsageInformation() << std::endl;
    234235            throw GeneralException("");
    235236        }
     
    272273    std::string CommandLine::getUsageInformation()
    273274    {
    274         CommandLine* inst = &_getInstance();
    275         std::string infoStr;
    276         for (std::map<std::string, CommandLineArgument*>::const_iterator it = inst->cmdLineArgs_.begin();
    277             it != inst->cmdLineArgs_.end(); ++it)
    278         {
    279             infoStr += "[--" + it->second->getName() + " " + it->second->getInformation() + "] ";
    280         }
    281         return infoStr;
     275        CommandLine& inst = _getInstance();
     276        std::ostringstream infoStr;
     277
     278        // determine maximum name size
     279        size_t maxNameSize = 0;
     280        for (std::map<std::string, CommandLineArgument*>::const_iterator it = inst.cmdLineArgs_.begin();
     281            it != inst.cmdLineArgs_.end(); ++it)
     282        {
     283            maxNameSize = std::max(it->second->getName().size(), maxNameSize);
     284        }
     285
     286        infoStr << "Usage: orxonox [options]" << std::endl;
     287        infoStr << "Available options:" << std::endl;
     288
     289        for (std::map<std::string, CommandLineArgument*>::const_iterator it = inst.cmdLineArgs_.begin();
     290            it != inst.cmdLineArgs_.end(); ++it)
     291        {
     292            if (it->second->getShortcut() != "")
     293                infoStr << " [-" << it->second->getShortcut() << "] ";
     294            else
     295                infoStr << "      ";
     296            infoStr << "--" << it->second->getName() << " ";
     297            if (it->second->getValue().getType() != MT_bool)
     298                infoStr << "ARG ";
     299            else
     300                infoStr << "    ";
     301            // fill with the necessary amount of blanks
     302            infoStr << std::string(maxNameSize - it->second->getName().size(), ' ');
     303            infoStr << ": " << it->second->getInformation();
     304            infoStr << std::endl;
     305        }
     306        return infoStr.str();
    282307    }
    283308
Note: See TracChangeset for help on using the changeset viewer.