little improvement to command line help display

This commit is contained in:
csoler 2017-07-09 22:12:01 +02:00
parent 2c6f11e4eb
commit 3e3ee1a34b
2 changed files with 14 additions and 9 deletions

View file

@ -89,6 +89,7 @@
// #define GPG_DEBUG // #define GPG_DEBUG
// #define AUTHSSL_DEBUG // #define AUTHSSL_DEBUG
// #define FIM_DEBUG // #define FIM_DEBUG
// #define DEBUG_RSINIT
//std::map<std::string,std::vector<std::string> > RsInit::unsupported_keys ; //std::map<std::string,std::vector<std::string> > RsInit::unsupported_keys ;
@ -311,8 +312,10 @@ int RsInit::InitRetroShare(int argc, char **argv, bool /* strictCheck */)
argc = i; argc = i;
#endif #endif
#ifdef DEBUG_RSINIT
for(int i=0; i<argc; i++) for(int i=0; i<argc; i++)
printf("%d: %s\n", i, argv[i]); printf("%d: %s\n", i, argv[i]);
#endif
/* for static PThreads under windows... we need to init the library... */ /* for static PThreads under windows... we need to init the library... */
#ifdef PTW32_STATIC_LIB #ifdef PTW32_STATIC_LIB
@ -357,7 +360,7 @@ int RsInit::InitRetroShare(int argc, char **argv, bool /* strictCheck */)
>> parameter('i',"ip-address" ,rsInitConfig->inet ,"nnn.nnn.nnn.nnn", "Set IP address to use." ,false) >> parameter('i',"ip-address" ,rsInitConfig->inet ,"nnn.nnn.nnn.nnn", "Set IP address to use." ,false)
>> parameter('p',"port" ,rsInitConfig->port ,"port", "Set listenning port to use." ,false) >> parameter('p',"port" ,rsInitConfig->port ,"port", "Set listenning port to use." ,false)
>> parameter('c',"base-dir" ,opt_base_dir ,"directory", "Set base directory." ,false) >> parameter('c',"base-dir" ,opt_base_dir ,"directory", "Set base directory." ,false)
>> parameter('U',"user-id" ,prefUserString ,"ID", "[User Name/GPG id/SSL id] Sets Account to Use, Useful when Autologin is enabled",false) >> parameter('U',"user-id" ,prefUserString ,"ID", "[ocation Id] Sets Account to Use, Useful when Autologin is enabled.",false)
// by rshare 'r' "link" "Link" "Open RsLink with protocol retroshare://" // by rshare 'r' "link" "Link" "Open RsLink with protocol retroshare://"
// by rshare 'f' "rsfile" "RsFile" "Open RsFile like RsCollection" // by rshare 'f' "rsfile" "RsFile" "Open RsFile like RsCollection"
#ifdef LOCALNET_TESTING #ifdef LOCALNET_TESTING
@ -365,7 +368,7 @@ int RsInit::InitRetroShare(int argc, char **argv, bool /* strictCheck */)
#endif #endif
>> help('h',"help","Display this Help") ; >> help('h',"help","Display this Help") ;
as.defaultErrorHandling(true) ; as.defaultErrorHandling(true,true) ;
if(rsInitConfig->autoLogin) rsInitConfig->startMinimised = true ; if(rsInitConfig->autoLogin) rsInitConfig->startMinimised = true ;
if(rsInitConfig->outStderr) rsInitConfig->haveLogFile = false ; if(rsInitConfig->outStderr) rsInitConfig->haveLogFile = false ;
@ -472,7 +475,7 @@ int RsInit::InitRetroShare(int argc, char **argv, bool /* strictCheck */)
{ {
if (!rsAccounts->selectAccountByString(prefUserString)) if (!rsAccounts->selectAccountByString(prefUserString))
{ {
std::cerr << "Invalid User name/GPG id/SSL id: not found in list"; std::cerr << "Invalid User location id: not found in list";
std::cerr << std::endl; std::cerr << std::endl;
return RS_INIT_AUTH_FAILED ; return RS_INIT_AUTH_FAILED ;
} }

View file

@ -252,8 +252,8 @@ namespace
inline bool helpRequested() const; inline bool helpRequested() const;
inline bool isOk() const; inline bool isOk() const;
inline std::string errorLog() const; inline std::string errorLog() const;
inline std::string usage() const; inline std::string usage(bool skipCommandLine = false) const;
inline bool defaultErrorHandling(bool ignoreUnused=false) const; inline bool defaultErrorHandling(bool ignoreUnused=false,bool skipCommandLine=false) const;
static inline char uniqueLetter(); static inline char uniqueLetter();
protected: protected:
void parse(int argc,char** argv); void parse(int argc,char** argv);
@ -569,10 +569,12 @@ namespace
return helpRequested_; return helpRequested_;
} }
inline std::string inline std::string
argstream::usage() const argstream::usage(bool skipCommandLine) const
{ {
std::ostringstream os; std::ostringstream os;
os<<"usage: "<<progName_<<cmdLine_<<'\n';
if(!skipCommandLine)
os<<"usage: "<<progName_<<cmdLine_<<'\n';
unsigned int lmax = 0; unsigned int lmax = 0;
for (std::deque<help_entry>::const_iterator for (std::deque<help_entry>::const_iterator
iter = argHelps_.begin();iter != argHelps_.end();++iter) iter = argHelps_.begin();iter != argHelps_.end();++iter)
@ -820,11 +822,11 @@ namespace
return s; return s;
} }
inline bool inline bool
argstream::defaultErrorHandling(bool ignoreUnused) const argstream::defaultErrorHandling(bool ignoreUnused,bool skipCommandLine) const
{ {
if (helpRequested_) if (helpRequested_)
{ {
std::cout<<usage(); std::cout<<usage(skipCommandLine);
exit(1); exit(1);
} }
if (!isOk_) if (!isOk_)