1 // 2 // Copyright (C) 2001-2013 Graeme Walker <graeme_walker@users.sourceforge.net> 3 // 4 // This program is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with this program. If not, see <http://www.gnu.org/licenses/>. 16 // === 17 /// 18 /// \file commandline.h 19 /// 20 21 #ifndef G_MAIN_COMMAND_LINE_H 22 #define G_MAIN_COMMAND_LINE_H 23 24 #include "gdef.h" 25 #include "gsmtp.h" 26 #include "garg.h" 27 #include "configuration.h" 28 #include "output.h" 29 #include "gstrings.h" 30 #include <string> 31 32 /// \namespace Main 33 namespace Main 34 { 35 class CommandLine ; 36 class CommandLineImp ; 37 } 38 39 /// \class Main::CommandLine 40 /// A class which deals with the command-line interface 41 /// to the process, both input and output. The input side is mostly 42 /// done by providing a Configuration object via the cfg() method. 43 /// 44 class Main::CommandLine 45 { 46 public: 47 static std::string switchSpec( bool is_windows ) ; 48 ///< Returns an o/s-specific G::GetOpt switch specification string. 49 50 CommandLine( Main::Output & output , const G::Arg & arg , const std::string & spec , 51 const std::string & version , const std::string & capabilities ) ; 52 ///< Constructor. 53 54 ~CommandLine() ; 55 ///< Destructor. 56 57 Configuration cfg() const ; 58 ///< Returns a Configuration object. 59 60 bool contains( const std::string & switch_ ) const ; 61 ///< Returns true if the command line contained the give switch. 62 63 bool contains( const char * switch_ ) const ; 64 ///< Returns true if the command line contained the give switch. 65 66 std::string value( const std::string & switch_ ) const ; 67 ///< Returns the given switch's string value. 68 69 std::string value( const char * switch_ ) const ; 70 ///< Returns the given switch's string value. 71 72 unsigned int value( const std::string & switch_ , unsigned int default_ ) const ; 73 ///< Returns the given switch's integer value. 74 75 unsigned int value( const char * switch_ , unsigned int default_ ) const ; 76 ///< Returns the given switch's integer value. 77 78 G::Strings value( const std::string & switch_ , const std::string & separators ) const ; 79 ///< Returns the given switch's list-of-string value. 80 81 G::Strings value( const char * switch_ , const char * separators ) const ; 82 ///< Returns the given switch's list-of-string value. 83 84 G::Arg::size_type argc() const ; 85 ///< Returns the number of non-switch arguments on the command line. 86 87 bool hasUsageErrors() const ; 88 ///< Returns true if the command line has usage errors (eg. invalid switch). 89 90 bool hasSemanticError() const ; 91 ///< Returns true if the command line has logical errors (eg. conflicting switches). 92 93 void showHelp( bool error_stream = false ) const ; 94 ///< Writes help text. 95 96 void showUsageErrors( bool error_stream = true ) const ; 97 ///< Writes the usage errors. 98 99 void showSemanticError( bool error_stream = true ) const ; 100 ///< Writes the logic errors. 101 102 void logSemanticWarnings() const ; 103 ///< Emits warnings about conflicting switches. 104 105 void showArgcError( bool error_stream = true ) const ; 106 ///< Writes a too-many-arguments error message. 107 108 void showNoop( bool error_stream = false ) const ; 109 ///< Writes a nothing-to-do message. 110 111 void showError( const std::string & reason , bool error_stream = true ) const ; 112 ///< Writes a failed message. 113 114 void showVersion( bool error_stream = false ) const ; 115 ///< Writes the version number. 116 117 void showBanner( bool error_stream = false , const std::string & = std::string() ) const ; 118 ///< Writes a startup banner. 119 120 void showCopyright( bool error_stream = false , const std::string & = std::string() ) const ; 121 ///< Writes a copyright message. 122 123 void showCapabilities( bool error_stream = false , const std::string & = std::string() ) const ; 124 ///< Writes a capability line. 125 126 private: 127 CommandLine( const CommandLine & ) ; // not implemented 128 void operator=( const CommandLine & ) ; // not implemented 129 130 private: 131 CommandLineImp * m_imp ; 132 } ; 133 134 #endif 135