00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef PALUDIS_GUARD_ARGS_ARGS_HANDLER_HH
00021 #define PALUDIS_GUARD_ARGS_ARGS_HANDLER_HH 1
00022
00023 #include <paludis/args/args_section.hh>
00024 #include <paludis/args/args_group.hh>
00025 #include <paludis/util/instantiation_policy.hh>
00026 #include <paludis/util/private_implementation_pattern.hh>
00027 #include <paludis/util/options.hh>
00028 #include <paludis/util/sequence.hh>
00029 #include <tr1/memory>
00030 #include <iosfwd>
00031 #include <string>
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 namespace paludis
00044 {
00045 namespace args
00046 {
00047
00048 #include <paludis/args/args_handler-se.hh>
00049
00050 typedef Options<ArgsHandlerOption> ArgsHandlerOptions;
00051
00052
00053
00054
00055
00056
00057
00058 class PALUDIS_VISIBLE ArgsHandler :
00059 private InstantiationPolicy<ArgsHandler, instantiation_method::NonCopyableTag>,
00060 private PrivateImplementationPattern<ArgsHandler>
00061 {
00062 friend class ArgsSection;
00063 friend std::ostream & operator<< (std::ostream &, const ArgsHandler &);
00064
00065 protected:
00066
00067
00068
00069 void add_usage_line(const std::string & l);
00070
00071
00072
00073
00074 void add_environment_variable(const std::string & e, const std::string & desc);
00075
00076
00077
00078
00079 void add_example(const std::string & e, const std::string & desc);
00080
00081
00082
00083
00084 void add_note(const std::string &);
00085
00086
00087
00088
00089 void add_description_line(const std::string & l);
00090
00091
00092
00093
00094 void add(ArgsSection * const);
00095
00096
00097
00098
00099 void dump_to_stream(std::ostream & s) const;
00100
00101
00102
00103
00104 virtual void post_run();
00105
00106 public:
00107
00108
00109
00110 ArgsHandler();
00111
00112 virtual ~ArgsHandler();
00113
00114
00115
00116
00117
00118
00119 struct ParametersConstIteratorTag;
00120 typedef WrappedForwardIterator<ParametersConstIteratorTag, const std::string> ParametersConstIterator;
00121
00122 ParametersConstIterator begin_parameters() const;
00123
00124 ParametersConstIterator end_parameters() const;
00125
00126 bool empty() const;
00127
00128
00129
00130
00131
00132
00133 void add_option(ArgsOption * const, const std::string & long_name,
00134 const char short_name = '\0');
00135
00136
00137
00138
00139 void remove_option(const std::string & long_name, const char short_name = '\0');
00140
00141
00142
00143
00144
00145
00146
00147 virtual std::string app_name() const = 0;
00148
00149
00150
00151
00152 virtual std::string man_section() const
00153 {
00154 return "1";
00155 }
00156
00157
00158
00159
00160 virtual std::string app_synopsis() const = 0;
00161
00162
00163
00164
00165 virtual std::string app_description() const = 0;
00166
00167
00168
00169
00170
00171
00172 struct UsageLineConstIteratorTag;
00173 typedef WrappedForwardIterator<UsageLineConstIteratorTag, const std::string> UsageLineConstIterator;
00174
00175 UsageLineConstIterator begin_usage_lines() const;
00176
00177 UsageLineConstIterator end_usage_lines() const;
00178
00179
00180
00181
00182
00183
00184 struct EnvironmentLineConstIteratorTag;
00185 typedef WrappedForwardIterator<EnvironmentLineConstIteratorTag,
00186 const std::pair<std::string, std::string> > EnvironmentLineConstIterator;
00187
00188 EnvironmentLineConstIterator begin_environment_lines() const;
00189
00190 EnvironmentLineConstIterator end_environment_lines() const;
00191
00192
00193
00194
00195
00196
00197 struct ExamplesConstIteratorTag;
00198 typedef WrappedForwardIterator<ExamplesConstIteratorTag,
00199 const std::pair<std::string, std::string> > ExamplesConstIterator;
00200
00201 ExamplesConstIterator begin_examples() const;
00202
00203 ExamplesConstIterator end_examples() const;
00204
00205
00206
00207
00208
00209
00210 struct ArgsSectionsConstIteratorTag;
00211 typedef WrappedForwardIterator<ArgsSectionsConstIteratorTag, const ArgsSection> ArgsSectionsConstIterator;
00212
00213 ArgsSectionsConstIterator begin_args_sections() const;
00214 ArgsSectionsConstIterator end_args_sections() const;
00215
00216
00217
00218
00219
00220
00221 ArgsSection * main_options_section() PALUDIS_ATTRIBUTE((warn_unused_result));
00222
00223
00224
00225
00226
00227
00228 struct NotesIteratorTag;
00229 typedef WrappedForwardIterator<NotesIteratorTag, const std::string > NotesIterator;
00230
00231 NotesIterator begin_notes() const;
00232 NotesIterator end_notes() const;
00233
00234
00235
00236
00237
00238
00239 struct DescriptionLineConstIteratorTag;
00240 typedef WrappedForwardIterator<DescriptionLineConstIteratorTag, const std::string> DescriptionLineConstIterator;
00241
00242 DescriptionLineConstIterator begin_description_lines() const;
00243
00244 DescriptionLineConstIterator end_description_lines() const;
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256 void run(
00257 const int argc,
00258 const char * const * const argv,
00259 const std::string & client,
00260 const std::string & env_var,
00261 const std::string & env_prefix,
00262 const ArgsHandlerOptions & options = ArgsHandlerOptions());
00263
00264
00265
00266
00267
00268
00269
00270
00271 void run(
00272 const std::tr1::shared_ptr<const Sequence<std::string> > &,
00273 const std::string & client,
00274 const std::string & env_var,
00275 const std::string & env_prefix,
00276 const ArgsHandlerOptions & options = ArgsHandlerOptions());
00277 };
00278
00279
00280
00281
00282
00283
00284 std::ostream & operator<< (std::ostream &, const ArgsHandler &) PALUDIS_VISIBLE;
00285 }
00286 }
00287
00288 #endif