Skip to content

Commit 5a6a200

Browse files
committed
Move help text into ArgGet
1 parent 0dfc9f0 commit 5a6a200

File tree

9 files changed

+44
-46
lines changed

9 files changed

+44
-46
lines changed

lib/argget.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ friend class SubArgGet;
253253
ArgGet(const ArgGet&) = default;
254254
ArgGet& operator=(const ArgGet&) = default;
255255

256-
ArgGet(std::list<SwitchArgBase*> argDefs, std::list<PosArg*> posArgDefs = {})
257-
: _argDefs(std::move(argDefs)), _posArgDefs(std::move(posArgDefs))
256+
ArgGet(std::list<SwitchArgBase*> argDefs, std::list<PosArg*> posArgDefs = {}, std::string help = "")
257+
: _argDefs(std::move(argDefs)), _posArgDefs(std::move(posArgDefs)), _help(std::move(help))
258258
{}
259259

260260
bool get_args(int argc, char** argv)
@@ -365,6 +365,10 @@ friend class SubArgGet;
365365
}
366366
help << std::endl;
367367
help << _argDefHelp(_argDefs);
368+
if(!_help.empty())
369+
{
370+
help << std::endl << _help << std::endl;
371+
}
368372
return help.str();
369373
}
370374

@@ -389,6 +393,7 @@ friend class SubArgGet;
389393
std::string _name;
390394
std::list<SwitchArgBase*> _argDefs;
391395
std::list<PosArg*> _posArgDefs;
396+
std::string _help;
392397
std::string _errMsg;
393398

394399
};
@@ -400,17 +405,17 @@ class SubArgGet
400405
SubArgGet(const SubArgGet&) = delete;
401406
SubArgGet& operator=(const SubArgGet&) = delete;
402407

403-
using SubArgs = std::list<std::pair<std::string,std::pair<std::list<SwitchArgBase*>,std::list<PosArg*>>>>;
408+
using SubArgs = std::list<std::pair<std::string,const ArgGet &>>;
404409

405410
SubArgGet(const SubArgs& subArgs) : SubArgGet({}, subArgs)
406411
{}
407412
SubArgGet(std::list<SwitchArgBase*> commonArgDefs, const SubArgs& subArgs)
408413
: _commonArgDefs(std::move(commonArgDefs))
409414
{
410-
for(const auto& [subCommand, args] : subArgs)
415+
for(const auto& [subCommand, argGet] : subArgs)
411416
{
412417
_order.emplace_back(subCommand);
413-
_subCommands[subCommand] = ArgGet(args.first, args.second);
418+
_subCommands[subCommand] = argGet;
414419
}
415420
}
416421

utils/baselinify_main.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
#include "baselinify.h"
55
#include "binfile.h"
66

7-
#define HELPTEXT "Use \"-\" as filename for stdin/stdout."
8-
97
inline void print_error(const std::string& hint, const std::string& argHelp)
108
{
11-
std::cerr << hint << std::endl << std::endl << argHelp << std::endl << HELPTEXT << std::endl;
9+
std::cerr << hint << std::endl << std::endl << argHelp << std::endl;
1210
}
1311

1412
int main(int argc, char** argv)
@@ -23,12 +21,13 @@ int main(int argc, char** argv)
2321
PosArg inArg(inFileName, "in-file");
2422
PosArg outArg(outFileName, "out-file prefix");
2523

26-
ArgGet args({&helpOpt}, {&inArg, &outArg});
24+
ArgGet args({&helpOpt}, {&inArg, &outArg},
25+
"Use \"-\" as filename for stdin/stdout.");
2726

2827
bool correctArgs = args.get_args(argc, argv);
2928
if(help)
3029
{
31-
std::cout << args.argHelp() << std::endl << HELPTEXT << std::endl;
30+
std::cout << args.argHelp() << std::endl;
3231
return 0;
3332
}
3433
else if(!correctArgs)

utils/bsplit.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
#include "binfile.h"
55
#include "bytestream.h"
66

7-
#define HELPTEXT "Negative numbers means \"all but\" number of bytes from the beginning/end."
8-
97
inline void print_error(const std::string& hint, const std::string& argHelp)
108
{
11-
std::cerr << hint << std::endl << std::endl << argHelp << std::endl << HELPTEXT << std::endl;
9+
std::cerr << hint << std::endl << std::endl << argHelp << std::endl;
1210
}
1311

1412
int main(int argc, char** argv)
@@ -27,12 +25,13 @@ int main(int argc, char** argv)
2725
PosArg outFileArg(outFileName, "output file");
2826

2927
ArgGet args({&helpOpt, &headOpt, &tailOpt},
30-
{&inFileArg, &outFileArg});
28+
{&inFileArg, &outFileArg},
29+
"Negative numbers means \"all but\" number of bytes from the beginning/end.");
3130

3231
bool correctArgs = args.get_args(argc, argv);
3332
if(help)
3433
{
35-
std::cout << args.argHelp() << std::endl << HELPTEXT << std::endl;
34+
std::cout << args.argHelp() << std::endl;
3635
return 0;
3736
}
3837
else if(!correctArgs)

utils/hexdump.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
#include "binfile.h"
66
#include "bytestream.h"
77

8-
#define HELPTEXT "Use \"-\" as filename for stdin."
9-
108
inline void print_error(const std::string& hint, const std::string& argHelp)
119
{
12-
std::cerr << hint << std::endl << std::endl << argHelp << std::endl << HELPTEXT << std::endl;
10+
std::cerr << hint << std::endl << std::endl << argHelp << std::endl;
1311
}
1412

1513
int main(int argc, char** argv)
@@ -22,12 +20,13 @@ int main(int argc, char** argv)
2220

2321
PosArg inArg(inFileName, "in-file");
2422

25-
ArgGet args({&helpOpt}, {&inArg});
23+
ArgGet args({&helpOpt}, {&inArg},
24+
"Use \"-\" as filename for stdin.");
2625

2726
bool correctArgs = args.get_args(argc, argv);
2827
if(help)
2928
{
30-
std::cout << args.argHelp() << std::endl << HELPTEXT << std::endl;
29+
std::cout << args.argHelp() << std::endl;
3130
return 0;
3231
}
3332
else if(!correctArgs)

utils/ippclient.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@
1212
#include "minimime.h"
1313
#include "uniquepointer.h"
1414

15-
#define HELPTEXT ""
16-
1715
inline void print_error(const std::string& hint, const std::string& argHelp)
1816
{
19-
std::cerr << hint << std::endl << std::endl << argHelp << std::endl << HELPTEXT << std::endl;
17+
std::cerr << hint << std::endl << std::endl << argHelp << std::endl;
2018
}
2119

2220
std::string print_colors(const List<std::string>& colors)
@@ -275,12 +273,14 @@ int main(int argc, char** argv)
275273
&mediaTypeOpt, &mediaSourceOpt, &outputBinOpt, &finishingsOpt,
276274
&marginOpt, &topMarginOpt, &bottomMarginOpt, &leftMarginOpt, &rightMarginOpt,
277275
&antiAliasOpt, &printJobIdOpt, &saveOpt},
278-
{&addrArg, &pdfArg}}}});
276+
{&addrArg, &pdfArg},
277+
"Use \"-\" as filename for stdin.\n"
278+
"Use the 'options' sub-command to get valid options for your particular printer."}}});
279279

280280
bool correctArgs = args.get_args(argc, argv);
281281
if(help)
282282
{
283-
std::cout << args.argHelp(args.subCommand()) << std::endl << HELPTEXT << std::endl;
283+
std::cout << args.argHelp(args.subCommand()) << std::endl;
284284
return 0;
285285
}
286286
else if(!correctArgs)

utils/ippdecode.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
#include "bytestream.h"
66
#include "ippmsg.h"
77

8-
#define HELPTEXT "Use \"-\" as filename for stdin."
9-
108
inline void print_error(const std::string& hint, const std::string& argHelp)
119
{
12-
std::cerr << hint << std::endl << std::endl << argHelp << std::endl << HELPTEXT << std::endl;
10+
std::cerr << hint << std::endl << std::endl << argHelp << std::endl;
1311
}
1412

1513
int main(int argc, char** argv)
@@ -22,12 +20,13 @@ int main(int argc, char** argv)
2220

2321
PosArg inArg(inFileName, "in-file");
2422

25-
ArgGet args({&helpOpt}, {&inArg});
23+
ArgGet args({&helpOpt}, {&inArg},
24+
"Use \"-\" as filename for stdin.");
2625

2726
bool correctArgs = args.get_args(argc, argv);
2827
if(help)
2928
{
30-
std::cout << args.argHelp() << std::endl << HELPTEXT << std::endl;
29+
std::cout << args.argHelp() << std::endl;
3130
return 0;
3231
}
3332
else if(!correctArgs)

utils/pdf2printable_main.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@
99
#include "ppm2pwg.h"
1010
#include "stringutils.h"
1111

12-
#define HELPTEXT "Options from 'resolution' and onwards only affect raster output formats.\n" \
13-
"Use \"-\" as filename for stdin/stdout."
14-
1512
inline void print_error(const std::string& hint, const std::string& argHelp)
1613
{
17-
std::cerr << hint << std::endl << std::endl << argHelp << std::endl << HELPTEXT << std::endl;
14+
std::cerr << hint << std::endl << std::endl << argHelp << std::endl;
1815
}
1916

2017
int main(int argc, char** argv)
@@ -91,12 +88,14 @@ int main(int argc, char** argv)
9188
&resolutionXOpt, &resolutionYOpt, &duplexOpt, &tumbleOpt,
9289
&backXformOpt, &colorModeOpt, &qualityOpt, &antiAliasOpt,
9390
&mediaPositionOpt, &mediaTypeOpt},
94-
{&pdfArg, &outArg});
91+
{&pdfArg, &outArg},
92+
"Options from 'resolution' and onwards only affect raster output formats.\n"
93+
"Use \"-\" as filename for stdin/stdout.");
9594

9695
bool correctArgs = args.get_args(argc, argv);
9796
if(help)
9897
{
99-
std::cout << args.argHelp() << std::endl << HELPTEXT << std::endl;
98+
std::cout << args.argHelp() << std::endl;
10099
return 0;
101100
}
102101
else if(!correctArgs)

utils/ppm2pwg_main.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111
#include "ppm2pwg.h"
1212
#include "stringutils.h"
1313

14-
#define HELPTEXT "Use \"-\" as filename for stdin/stdout."
15-
1614
inline void print_error(const std::string& hint, const std::string& argHelp)
1715
{
18-
std::cerr << hint << std::endl << std::endl << argHelp << std::endl << HELPTEXT << std::endl;
16+
std::cerr << hint << std::endl << std::endl << argHelp << std::endl;
1917
}
2018

2119
inline void ignore_comments(std::istream& in)
@@ -81,12 +79,13 @@ int main(int argc, char** argv)
8179
&resolutionOpt, &resolutionXOpt, &resolutionYOpt,
8280
&duplexOpt, &tumbleOpt, &backXformOpt, &qualityOpt,
8381
&mediaPositionOpt, &mediaTypeOpt},
84-
{&inArg, &outArg});
82+
{&inArg, &outArg},
83+
"Use \"-\" as filename for stdin/stdout.");
8584

8685
bool correctArgs = args.get_args(argc, argv);
8786
if(help)
8887
{
89-
std::cout << args.argHelp() << std::endl << HELPTEXT << std::endl;
88+
std::cout << args.argHelp() << std::endl;
9089
return 0;
9190
}
9291
else if(!correctArgs)

utils/pwg2ppm_main.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
#include "pwgpghdr.h"
99
#include "urfpghdr.h"
1010

11-
#define HELPTEXT "Use \"-\" as filename for stdin."
12-
1311
inline void print_error(const std::string& hint, const std::string& argHelp)
1412
{
15-
std::cerr << hint << std::endl << std::endl << argHelp << std::endl << HELPTEXT << std::endl;
13+
std::cerr << hint << std::endl << std::endl << argHelp << std::endl;
1614
}
1715

1816
int main(int argc, char** argv)
@@ -30,12 +28,13 @@ int main(int argc, char** argv)
3028
PosArg outArg(outFilePrefix, "out-file prefix");
3129

3230
ArgGet args({&helpOpt, &verboseOpt},
33-
{&inArg, &outArg});
31+
{&inArg, &outArg},
32+
"Use \"-\" as filename for stdin.");
3433

3534
bool correctArgs = args.get_args(argc, argv);
3635
if(help)
3736
{
38-
std::cout << args.argHelp() << std::endl << HELPTEXT << std::endl;
37+
std::cout << args.argHelp() << std::endl;
3938
return 0;
4039
}
4140
else if(!correctArgs)

0 commit comments

Comments
 (0)