commandline.h
Go to the documentation of this file.
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 // ===
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 
33 namespace Main
34 {
35  class CommandLine ;
36  class CommandLineImp ;
37 }
38 
45 {
46 public:
47  static std::string switchSpec( bool is_windows ) ;
49 
50  CommandLine( Main::Output & output , const G::Arg & arg , const std::string & spec ,
51  const std::string & version , const std::string & capabilities ) ;
53 
54  ~CommandLine() ;
56 
57  Configuration cfg() const ;
59 
60  bool contains( const std::string & switch_ ) const ;
62 
63  bool contains( const char * switch_ ) const ;
65 
66  std::string value( const std::string & switch_ ) const ;
68 
69  std::string value( const char * switch_ ) const ;
71 
72  unsigned int value( const std::string & switch_ , unsigned int default_ ) const ;
74 
75  unsigned int value( const char * switch_ , unsigned int default_ ) const ;
77 
78  G::Strings value( const std::string & switch_ , const std::string & separators ) const ;
80 
81  G::Strings value( const char * switch_ , const char * separators ) const ;
83 
84  G::Arg::size_type argc() const ;
86 
87  bool hasUsageErrors() const ;
89 
90  bool hasSemanticError() const ;
92 
93  void showHelp( bool error_stream = false ) const ;
95 
96  void showUsageErrors( bool error_stream = true ) const ;
98 
99  void showSemanticError( bool error_stream = true ) const ;
101 
102  void logSemanticWarnings() const ;
104 
105  void showArgcError( bool error_stream = true ) const ;
107 
108  void showNoop( bool error_stream = false ) const ;
110 
111  void showError( const std::string & reason , bool error_stream = true ) const ;
113 
114  void showVersion( bool error_stream = false ) const ;
116 
117  void showBanner( bool error_stream = false , const std::string & = std::string() ) const ;
119 
120  void showCopyright( bool error_stream = false , const std::string & = std::string() ) const ;
122 
123  void showCapabilities( bool error_stream = false , const std::string & = std::string() ) const ;
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
Application-level classes.
void showCopyright(bool error_stream=false, const std::string &=std::string()) const
Writes a copyright message.
Configuration cfg() const
Returns a Configuration object.
size_t size_type
Definition: garg.h:49
std::list< std::string > Strings
A std::list of std::strings.
Definition: gstrings.h:39
void showCapabilities(bool error_stream=false, const std::string &=std::string()) const
Writes a capability line.
void showError(const std::string &reason, bool error_stream=true) const
Writes a failed message.
A private implementation class used by Main::CommandLine.
CommandLine(Main::Output &output, const G::Arg &arg, const std::string &spec, const std::string &version, const std::string &capabilities)
Constructor.
~CommandLine()
Destructor.
void showBanner(bool error_stream=false, const std::string &=std::string()) const
Writes a startup banner.
An abstract interface for generating output on a command-line or a GUI.
Definition: output.h:38
void logSemanticWarnings() const
Emits warnings about conflicting switches.
bool hasSemanticError() const
Returns true if the command line has logical errors (eg. conflicting switches).
void showArgcError(bool error_stream=true) const
Writes a too-many-arguments error message.
std::string value(const std::string &switch_) const
Returns the given switch's string value.
bool contains(const std::string &switch_) const
Returns true if the command line contained the give switch.
A class which deals with the command-line interface to the process, both input and output...
Definition: commandline.h:44
void showVersion(bool error_stream=false) const
Writes the version number.
bool hasUsageErrors() const
Returns true if the command line has usage errors (eg. invalid switch).
void showUsageErrors(bool error_stream=true) const
Writes the usage errors.
A class which holds a represention of the argc/argv command line array, and supports simple command-l...
Definition: garg.h:46
void showHelp(bool error_stream=false) const
Writes help text.
void showNoop(bool error_stream=false) const
Writes a nothing-to-do message.
An interface for returning application configuration information.
Definition: configuration.h:45
static std::string switchSpec(bool is_windows)
Returns an o/s-specific G::GetOpt switch specification string.
void showSemanticError(bool error_stream=true) const
Writes the logic errors.
G::Arg::size_type argc() const
Returns the number of non-switch arguments on the command line.