File: arg_parse_doc.h

package info (click to toggle)
seqan2 2.3.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 222,320 kB
  • ctags: 40,872
  • sloc: cpp: 252,894; ansic: 86,805; python: 6,534; sh: 985; xml: 570; makefile: 236; awk: 51
file content (1056 lines) | stat: -rw-r--r-- 36,687 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
// ==========================================================================
//                 SeqAn - The Library for Sequence Analysis
// ==========================================================================
// Copyright (c) 2006-2016, Knut Reinert, FU Berlin
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of Knut Reinert or the FU Berlin nor the names of
//       its contributors may be used to endorse or promote products derived
//       from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
//
// ==========================================================================
// Author: Stephan Aiche <stephan.aiche@fu-berlin.de>
// ==========================================================================

#ifndef SEQAN_INCLUDE_SEQAN_ARG_PARSE_ARG_PARSE_DOC_H_
#define SEQAN_INCLUDE_SEQAN_ARG_PARSE_ARG_PARSE_DOC_H_

#include <seqan/arg_parse/tool_doc.h>
#include <seqan/arg_parse/argument_parser.h>

namespace seqan {

// ============================================================================
// Functions
// ============================================================================

// --------------------------------------------------------------------------
// Function getAppName()
// --------------------------------------------------------------------------

/*!
 * @fn ArgumentParser#getAppName
 * @brief Return program name of ArgumentParser.
 *
 * @signature TCharStringRef getAppName(parser);
 *
 * @param[in] parser The ArgumentParser to get the app name for.
 *
 * @return TCharStringRef The app name, const-ref to @link CharString @endlink.
 */

inline CharString const & getAppName(ArgumentParser const & parser)
{
    return getName(parser._toolDoc);
}

// ----------------------------------------------------------------------------
// Helper Function _parseAppName()
// ----------------------------------------------------------------------------

inline void _parseAppName(ArgumentParser & parser, std::string const & candidate)
{
    //IOREV _notio_ irrelevant for io-revision
    int i = length(candidate) - 1;

    for (; i >= 0; --i)
        if (candidate[i] == '\\' || candidate[i] == '/')
            break;

    setName(parser._toolDoc, candidate.substr(i + 1));
}

// ----------------------------------------------------------------------------
// Helper Function _addLine()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgumentParser#addLine
 * @brief Adds a line of text to the help output of the ArgumentParser.
 *
 * The line of text will be added to the block of the options.
 *
 * @signature void addLine(parser, line);
 *
 * @param[in,out] parser The ArgumentParser to add the line to.
 * @param[in]     line   The line of text to add, @link StringConcept @endlink of <tt>char</tt>.
 */

template <typename TString>
inline void addLine(ArgumentParser & me, TString const & line)
{
    addOption(me, ArgParseOption("", "", line));
}

// ----------------------------------------------------------------------------
// Function addSection()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgumentParser#addSection
 * @brief Begins a new section of the option block of the ArgumentParser help output.
 *
 * @signature void addSection(parser, title);
 *
 * @param[in,out] parser The ArgumentParser to add the line to.
 * @param[in]     title  The title to add, @link StringConcept @endlink of <tt>char</tt>.
 *
 * @code{.cpp}
 * ArgumentParser parser;
 *
 * [...] // init parser
 *
 * addSection(parser, "In-/Output-Options");
 * addOption("i", ... );
 * addOption("o", ... );
 *
 * addSection(parser, "Other Options");
 * addOption("x", ... );
 * @endcode
 */

template <typename TString>
inline void addSection(ArgumentParser & me, TString const & line)
{
    addLine(me, "");
    addLine(me, line);
}

// ----------------------------------------------------------------------------
// Function addUsageLine()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgumentParser#addUseLine
 * @brief Adds a line of text to the usage output of the ArgumentParser.
 *
 * @signature void addUsageLine(parser, line);
 *
 * @param[in,out] parser The ArgumentParser to add the line to.
 * @param[in]     line   The line to add, a <tt>std::string</tt>.
 */

inline void addUsageLine(ArgumentParser & me, std::string const & line)
{
    me._usageText.push_back(line);
}

// ----------------------------------------------------------------------------
// Helper Function _addUsage()
// ----------------------------------------------------------------------------

inline void _addUsage(ToolDoc & toolDoc, ArgumentParser const & me)
{
    for (unsigned i = 0; i < length(me._usageText); ++i)
    {
        std::string text = "\\fB";
        append(text, getAppName(me));
        append(text, "\\fP ");
        append(text, me._usageText[i]);
        addText(toolDoc, text, false);
    }
}

// ----------------------------------------------------------------------------
// Function addDescription()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgumentParser#addDescription
 * @brief Appends a description paragraph to the ArgumentParser documentation.
 *
 * @signature void addDescription(parser, description);
 *
 * @param[in,out] parser      The ArgumentParser to add the line to.
 * @param[in]     description The description text, a <tt>std::string</tt>.
 */

inline void addDescription(ArgumentParser & me, std::string const & description)
{
    me._description.push_back(description);
}

// ----------------------------------------------------------------------------
// Function setAppName()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgumentParser#setAppName
 * @brief Sets application name of ArgumentParser.
 *
 * @signature void setAppName(parser, name);
 *
 * @param[in,out] parser The ArgumentParser to set the name of.
 * @param[in]     name   The application name, <tt>std::string</tt>.
 */

inline void setAppName(ArgumentParser & me, std::string const & name)
{
    setName(me._toolDoc, name);
}

// ----------------------------------------------------------------------------
// Function setShortDescription()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgumentParser#setShortDescription
 * @brief Sets shortDescription of ArgumentParser.
 *
 * @signature void setShortDescription(parser, desc);
 *
 * @param[in,out] parser The ArgumentParser to set the short description of.
 * @param[in]     desc   The short description, <tt>std::string</tt>.
 */

inline void setShortDescription(ArgumentParser & me, std::string const & description)
{
    setShortDescription(me._toolDoc, description);
}

// ----------------------------------------------------------------------------
// Function getShortDescription()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgumentParser#getShortDescription
 * @brief Returns the short description.
 *
 * @signature CharString getShortDescription(parser);
 *
 * @param[in,out] parser The ArgumentParser to get short description for.
 *
 * @return CharString A @link CharString @endlink with the short description.
 */

inline CharString getShortDescription(ArgumentParser const & me)
{
    return getShortDescription(me._toolDoc);
}

// ----------------------------------------------------------------------------
// Function setUrl()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgumentParser#setUrl
 * @brief Sets url of ArgumentParser.
 *
 * @signature void setUrl(parser, url);
 *
 * @param[in,out] parser  The ArgumentParser to set the url of.
 * @param[in]     url     The url string to set, @link CharString @endlink.
 */

inline void setUrl(ArgumentParser & me, CharString const & urlString)
{
    setUrl(me._toolDoc, urlString);
}

// --------------------------------------------------------------------------
// Function getUrl()
// --------------------------------------------------------------------------

/*!
 * @fn ArgumentParser#getUrl
 * @brief Returns the url string.
 *
 * @signature TCharStringRef getUrl(parser);
 *
 * @param[in,out] parser The ArgumentParser to get the url string from.
 *
 * @return TCharString A const-ref to a @link CharString @endlink with the url string.
 */

inline CharString const & getUrl(ArgumentParser const & me)
{
    return getUrl(me._toolDoc);
}

// ----------------------------------------------------------------------------
// Function setVersion()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgumentParser#setVersion
 * @brief Sets version of ArgumentParser.
 *
 * @signature void setVersion(parser, version);
 *
 * @param[in,out] parser  The ArgumentParser to set the version of.
 * @param[in]     version The version string to set, <tt>std::string</tt>.
 */

inline void setVersion(ArgumentParser & me, std::string const & versionString)
{
    setVersion(me._toolDoc, versionString);
    if (!hasOption(me, "version"))
        addOption(me, ArgParseOption("", "version", "Display version information."));
}

// --------------------------------------------------------------------------
// Function getVersion()
// --------------------------------------------------------------------------

/*!
 * @fn ArgumentParser#getVersion
 * @brief Returns the version string.
 *
 * @signature TCharStringRef getVersion(parser);
 *
 * @param[in,out] parser The ArgumentParser to get the version string from.
 *
 * @return TCharString A const-ref to a @link CharString @endlink with the version string.
 */

inline CharString const & getVersion(ArgumentParser const & me)
{
    return getVersion(me._toolDoc);
}

// ----------------------------------------------------------------------------
// Function setShortCopyright()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgumentParser#setShortCopyright
 * @brief Sets short copyright of ArgumentParser.
 *
 * @signature void setShortCopyright(parser, short copyright);
 *
 * @param[in,out] parser  The ArgumentParser to set the short copyright of.
 * @param[in]     short copyright The short copyright string to set, <tt>std::string</tt>.
 */

inline void setShortCopyright(ArgumentParser & me, CharString const & shortCopyrightString)
{
    setShortCopyright(me._toolDoc, shortCopyrightString);
}

// --------------------------------------------------------------------------
// Function getShortCopyright()
// --------------------------------------------------------------------------

/*!
 * @fn ArgumentParser#getShortCopyright
 * @brief Returns the short copyright string.
 *
 * @signature TCharStringRef getShortCopyright(parser);
 *
 * @param[in,out] parser The ArgumentParser to get the short copyright string from.
 *
 * @return TCharString A const-ref to a @link CharString @endlink with the short copyright string.
 */

inline CharString const & getShortCopyright(ArgumentParser const & me)
{
    return getShortCopyright(me._toolDoc);
}

// ----------------------------------------------------------------------------
// Function setLongCopyright()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgumentParser#setLongCopyright
 * @brief Sets long copyright of ArgumentParser.
 *
 * @signature void setLongCopyright(parser, long copyright);
 *
 * @param[in,out] parser  The ArgumentParser to set the long copyright of.
 * @param[in]     long copyright The long copyright string to set, <tt>std::string</tt>.
 */

inline void setLongCopyright(ArgumentParser & me, CharString const & longCopyrightString)
{
    setLongCopyright(me._toolDoc, longCopyrightString);
    if (!hasOption(me, "copyright"))
        addOption(me, ArgParseOption("", "copyright", "Display long copyright information."));
}

// --------------------------------------------------------------------------
// Function getLongCopyright()
// --------------------------------------------------------------------------

/*!
 * @fn ArgumentParser#getLongCopyright
 * @brief Returns the long copyright string.
 *
 * @signature TCharStringRef getLongCopyright(parser);
 *
 * @param[in,out] parser The ArgumentParser to get the long copyright string from.
 *
 * @return TCharString A const-ref to a @link CharString @endlink with the long copyright string.
 */

inline CharString const & getLongCopyright(ArgumentParser const & me)
{
    return getLongCopyright(me._toolDoc);
}


// ----------------------------------------------------------------------------
// Function setCitation()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgumentParser#setCitation
 * @brief Sets citation of ArgumentParser.
 *
 * @signature void setCitation(parser, citation);
 *
 * @param[in,out] parser  The ArgumentParser to set the citation of.
 * @param[in]     citation The citation string to set, <tt>std::string</tt>.
 */

inline void setCitation(ArgumentParser & me, CharString const & citationString)
{
    setCitation(me._toolDoc, citationString);
}

// --------------------------------------------------------------------------
// Function getCitation()
// --------------------------------------------------------------------------

/*!
 * @fn ArgumentParser#getCitation
 * @brief Returns the citation string.
 *
 * @signature TCharStringRef getCitation(parser);
 *
 * @param[in,out] parser The ArgumentParser to get the citation string from.
 *
 * @return TCharString A const-ref to a @link CharString @endlink with the citation string.
 */

inline CharString const & getCitation(ArgumentParser const & me)
{
    return getCitation(me._toolDoc);
}

// --------------------------------------------------------------------------
// Function setCategory()
// --------------------------------------------------------------------------

/*!
 * @fn ArgumentParser#setCategory
 * @brief Sets category of ArgumentParser.
 *
 * @signature void setCategory(parser, category);
 *
 * @param[in,out] parser  The ArgumentParser to set the category of.
 * @param[in]     category The category to set, <tt>std::string</tt>.
 */

inline void setCategory(ArgumentParser & parser, CharString const & category)
{
    setCategory(parser._toolDoc, category);
}

// --------------------------------------------------------------------------
// Function getCategory()
// --------------------------------------------------------------------------

/*!
 * @fn ArgumentParser#getCategory
 * @brief Returns the category.
 *
 * @signature TCharStringRef getCategory(parser);
 *
 * @param[in,out] parser The ArgumentParser to get the category from.
 *
 * @return TCharString A const-ref to a @link CharString @endlink with the category.
 */

inline CharString const & getCategory(ArgumentParser const & parser)
{
    return getCategory(parser._toolDoc);
}

// ----------------------------------------------------------------------------
// Function setDate()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgumentParser#setDate
 * @brief Sets date string of ArgumentParser.
 *
 * @signature void setDate(parser, date);
 *
 * @param[in,out] parser The ArgumentParser to set the date string of.
 * @param[in]     date   The date string to set, <tt>std::string</tt>.
 */

inline void setDate(ArgumentParser & me, std::string const & date)
{
    setDate(me._toolDoc, date);
}

// ----------------------------------------------------------------------------
// Function addTextSection()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgumentParser#addTextSection
 * @brief Add a text section to the ArgumentParser.
 *
 * @signature void addTextSection(parser, title);
 *
 * @param[in,out] parser The ArgumentParser to add the text section title to.
 * @param[in]     title  The section title to add, <tt>std::string</tt>.
 */

inline void addTextSection(ArgumentParser & me, std::string const & title)
{
    addSection(me._toolDoc, title);
}

// ----------------------------------------------------------------------------
// Function addTextSubSection()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgumentParser#addTextSubSection
 * @brief Add a text sub section to the ArgumentParser.
 *
 * @signature void addTextSubSection(parser, title);
 *
 * @param[in,out] parser The ArgumentParser add the subsection title to of.
 * @param[in]     title  The sub section title to add, <tt>std::string</tt>.
 */

inline void addTextSubSection(ArgumentParser & me, std::string const & title)
{
    addSubSection(me._toolDoc, title);
}

// ----------------------------------------------------------------------------
// Function addText()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgumentParser#addText
 * @brief Add text to an ArgumentParser.
 *
 * @signature void addText(parser, text);
 *
 * @param[in,out] parser ArgumentParser to add text to.
 * @param[in]     text   The <tt>std::string</tt> to add to the parser.
 */

inline void addText(ArgumentParser & me, std::string const & text)
{
    addText(me._toolDoc, text);
}

// ----------------------------------------------------------------------------
// Function addListItem()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgumentParser#addListItem
 * @brief Appends a list item to the ArgumentParser
 *
 * @signature void addListItem(parser, item, description);
 *
 * @param[in,out] parser      The ArgumentParser to add the list item to.
 * @param[in]     item        The item to add, <tt>std::string</tt>.
 * @param[in]     description The item to add, <tt>std::string</tt>.
 */

inline void addListItem(ArgumentParser & me, std::string const & item, std::string const & description)
{
    addListItem(me._toolDoc, item, description);
}

// ----------------------------------------------------------------------------
// Function printShortHelp()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgumentParser#printShortHelp
 * @brief Prints a short help message for the parser to a stream.
 *
 * @signature void printShortHelp(parser, out);
 *
 * @param[in,out] parser The ArgumentParser to print help for.
 * @param[in,out] out    The <tt>std::ostream</tt> to print help to.
 */

inline void printShortHelp(ArgumentParser const & me, std::ostream & stream)
{
    // TODO: maybe we can get this a bit prettier
    ToolDoc shortDoc(me._toolDoc);
    clearEntries(shortDoc);

    _addUsage(shortDoc, me);

    std::stringstream shortHelp;
    shortHelp << "Try '" << getAppName(me) << " --help' for more information.\n";
    addText(shortDoc, shortHelp.str());

    print(stream, shortDoc, "txt");
}

inline void printShortHelp(ArgumentParser const & me)
{
    printShortHelp(me, std::cerr);
}

// ----------------------------------------------------------------------------
// Function printVersion()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgumentParser#printVersion
 * @brief Prints the version information of the parser to a stream.
 *
 * @signature void printVersion(parser, stream);
 *
 * @param[in,out] parser The ArgumenParser to print for.
 * @param[in,out] stream The <tt>std::ostream</tt> to print to.
 */

inline void printVersion(ArgumentParser const & me, std::ostream & stream)
{
    stream << getAppName(me) << " version: " << getVersion(me) << std::endl;
    stream << "SeqAn version: " << SEQAN_VERSION_MAJOR << '.' <<  SEQAN_VERSION_MINOR << '.'
           << SEQAN_VERSION_PATCH;
    if (SEQAN_VERSION_PRE_RELEASE != 0)
        stream << "-pre" << SEQAN_VERSION_PRE_RELEASE;
    stream << "\n";
}

inline void printVersion(ArgumentParser const & me)
{
    printVersion(me, std::cerr);
}

// ----------------------------------------------------------------------------
// Function printLongCopyright()
// ----------------------------------------------------------------------------

/*!
 * @fn ArgumentParser#printLongCopyright
 * @brief Prints the long copyright information of the parser to a stream.
 *
 * @signature void printLongCopyright(parser, stream);
 *
 * @param[in,out] parser The ArgumenParser to print for.
 * @param[in,out] stream The <tt>std::ostream</tt> to print to.
 */

inline void printLongCopyright(ArgumentParser const & me, std::ostream & stream)
{
    stream << "=============================================================================" << std::endl
           << "Copyright information for " << getAppName(me) << ":" << std::endl
           << "-----------------------------------------------------------------------------" << std::endl
           << me._toolDoc._longCopyright << std::endl << std::endl
           << "=============================================================================" << std::endl
           << "This program contains SeqAn code licensed under the following terms:" << std::endl
           << "-----------------------------------------------------------------------------" << std::endl
           << " Copyright (c) 2006-2015, Knut Reinert, FU Berlin" << std::endl
           << " All rights reserved." << std::endl
           << "" << std::endl
           << " Redistribution and use in source and binary forms, with or without" << std::endl
           << " modification, are permitted provided that the following conditions are met:" << std::endl
           << "" << std::endl
           << "     * Redistributions of source code must retain the above copyright" << std::endl
           << "       notice, this list of conditions and the following disclaimer." << std::endl
           << "     * Redistributions in binary form must reproduce the above copyright" << std::endl
           << "       notice, this list of conditions and the following disclaimer in the" << std::endl
           << "       documentation and/or other materials provided with the distribution." << std::endl
           << "     * Neither the name of Knut Reinert or the FU Berlin nor the names of" << std::endl
           << "       its contributors may be used to endorse or promote products derived" << std::endl
           << "       from this software without specific prior written permission." << std::endl
           << "" << std::endl
           << " THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"" << std::endl
           << " AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE" << std::endl
           << " IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE" << std::endl
           << " ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE" << std::endl
           << " FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL" << std::endl
           << " DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR" << std::endl
           << " SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER" << std::endl
           << " CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT" << std::endl
           << " LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY" << std::endl
           << " OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH" << std::endl
           << " DAMAGE." << std::endl;
}

inline void printLongCopyright(ArgumentParser const & me)
{
    printLongCopyright(me, std::cerr);
}

// ----------------------------------------------------------------------------
// Function _addNumericalRestriction()
// ----------------------------------------------------------------------------

inline void _addNumericalRestriction(std::string & text, ArgParseArgument const & arg)
{
    // expand min/max restrictions
    if (!empty(arg.minValue) || !empty(arg.maxValue))
    {
        append(text, " In range [");

        if (!empty(arg.minValue))
            append(text, arg.minValue);
        else
            append(text, "-inf");

        append(text, "..");

        if (!empty(arg.maxValue))
            append(text, arg.maxValue);
        else
            append(text, "inf");

        append(text, "].");
    }
}

// ----------------------------------------------------------------------------
// Function _expandList()
// ----------------------------------------------------------------------------

// expands the given vector as text in the form v1, v2, and v3, while respecting
// the size with respect to the used commas and "and"s
inline void _expandList(std::string & text, std::vector<std::string> const & list)
{
    for (std::vector<std::string>::size_type i = 0; i < list.size(); ++i)
    {
        if (i + 1 == list.size() && list.size() == 2u)
            append(text, " and ");
        else if (i + 1 == list.size()  && list.size() > 2u)
            append(text, ", and ");
        else if (i != 0)
            append(text, ", ");

        append(text, "\\fI");
        append(text, list[i]);
        append(text, "\\fP");

    }
}

// ----------------------------------------------------------------------------
// Function _addDefaultValues()
// ----------------------------------------------------------------------------

inline void _addDefaultValues(std::string & text, ArgParseArgument const & arg)
{
    if (!empty(arg.defaultValue))
    {
        append(text, " Default: ");
        _expandList(text, arg.defaultValue);
        append(text, ".");
    }
}

inline void _addDefaultValues(std::string & text, ArgParseOption const & arg)
{
    if (!isFlagOption(arg))
        _addDefaultValues(text, static_cast<ArgParseArgument>(arg));
}

// ----------------------------------------------------------------------------
// Function _seperateExtensionsForPrettyPrinting()
// ----------------------------------------------------------------------------

inline void _seperateExtensionsForPrettyPrinting(std::vector<std::string> & file_ext,
                                                 std::vector<std::string> & comp_ext,
                                                 std::vector<std::string> const & validValues)
{
    // seperate file extensions and compression extensions
    for (std::vector<std::string>::size_type i = 0; i < validValues.size(); ++i)
    {
        std::regex rgx("^(\\.)?([A-z0-9]+)(\\.)?([A-z0-9]+)?");
        std::smatch result;

        std::regex_search(validValues[i], result, rgx);

        if (!result[4].str().empty())
        {
            comp_ext.push_back(result[4].str());
            file_ext.push_back("." + result[2].str() + "[.*]");
        }
        else
        {
            file_ext.push_back("." + result[2].str());
        }
    }

    std::sort(file_ext.rbegin(), file_ext.rend()); // sort extensions in reverse order such that '.fa[.x]'
    std::sort(comp_ext.rbegin(), comp_ext.rend()); // comes before '.fa' and will be chosen by std::unique()

    comp_ext.erase(std::unique(comp_ext.begin(), comp_ext.end()), comp_ext.end()); // remove duplicates
    file_ext.erase(std::unique(file_ext.begin(), file_ext.end(),
                    [&](auto& lhs, auto& rhs)
                    {
                        return lhs.substr(0, lhs.find('[')) == rhs.substr(0, rhs.find('['));
                    }), file_ext.end());
}

// ----------------------------------------------------------------------------
// Function _addValidValuesRestrictions()
// ----------------------------------------------------------------------------

inline void _addValidValuesRestrictions(std::string & text, ArgParseArgument const & arg)
{
    if (!empty(arg.validValues))
    {
        if (isInputFileArgument(arg) || isOutputFileArgument(arg))
        {
            std::vector<std::string> file_extensions;
            std::vector<std::string> compresssion_extensions;

            _seperateExtensionsForPrettyPrinting(file_extensions, compresssion_extensions, arg.validValues);

            append(text, " Valid filetype");

            if (file_extensions.size() > 1)
                append(text, "s are: ");
            else
                append(text, " is: ");

            _expandList(text, file_extensions);

            if (compresssion_extensions.size() != 0)
            {
                append(text, ", where * is any of the following extensions: ");
                _expandList(text, compresssion_extensions);
                append(text, " for transparent (de)compression");
            }
        }
        else
        {
            append(text, " One of ");
            _expandList(text, arg.validValues);
        }

        append(text, ".");
    }
}

inline void _addValidValuesRestrictions(std::string & text, ArgParseOption const & opt)
{
    if (!isFlagOption(opt))
        _addValidValuesRestrictions(text, static_cast<ArgParseArgument>(opt));
}

// ----------------------------------------------------------------------------
// Function _addTypeAndListInfo()
// ----------------------------------------------------------------------------

inline void _addTypeAndListInfo(std::string & text, ArgParseArgument const & arg)
{
    std::string type = getArgumentTypeAsString(arg);
    for (auto & c: type)
         c = toupper(c);

    // Write arguments to term line -> only exception, boolean flags
    if (!empty(type))
    {
        append(text, " ");

        if (isListArgument(arg))
            append(text, "List of ");

        if (arg._numberOfValues != 1)
            append(text,  std::to_string(arg._numberOfValues) + " ");

        append(text, "\\fI");
        append(text, type);
        append(text, "\\fP");

        if (isListArgument(arg) || arg._numberOfValues != 1)
            append(text, "'s");
    }
}

// ----------------------------------------------------------------------------
// Function printHelp()
// ----------------------------------------------------------------------------

// TODO(holtgrew): Parameter order.

/*!
 * @fn ArgumentParser#printHelp
 * @brief Prints the help message for the parser.
 *
 * @signature void printHelp(parser, out, format, showAdvancedOptions);
 *
 * @param[in,out] parser                The ArgumentParser print the help for.
 * @param[out]    out                   The output stream to print to (<tt>std::ostream</tt>).
 * @param[in]     format                The format to print, one of "html", "man", and "txt".
 * @param[in]     showAdvancedOptions   Also show advanced options to user (default = false).
 */

inline void printHelp(ArgumentParser const & me,
                      std::ostream & stream,
                      CharString const & format,
                      bool const showAdvancedOptions)
{
    ToolDoc toolDoc(me._toolDoc);
    clearEntries(toolDoc);  // We will append me._toolDoc later.

    // Build synopsis section.
    addSection(toolDoc, "Synopsis");
    _addUsage(toolDoc, me);

    // Add description to tool documentation.
    addSection(toolDoc, "Description");
    for (unsigned i = 0; i < me._description.size(); ++i)
        addText(toolDoc, me._description[i]);

    // Add arguments to arguments section
    if (length(me.argumentList) != 0)
        addSection(toolDoc, "Required Arguments");

    for (unsigned i = 0; i < length(me.argumentList); ++i)
    {
        ArgParseArgument const & arg = me.argumentList[i];

        // Build list item term.
        std::string term;
        if (!empty(arg._argumentLabel))
        {
            std::regex space(" ");
            term = "\\fB";
            append(term, std::regex_replace(arg._argumentLabel, space,"_"));
            append(term, "\\fP");
        }
        else
        {
            term = "\\fBARGUMENT ";
            append(term, std::to_string(i));
            append(term, "\\fP");
        }

        // expand type, list and numValues information
        _addTypeAndListInfo(term, arg);

        std::string helpText = arg._helpText;

        // expand min/max restrictions
        _addNumericalRestriction(helpText, arg);

        // expand validValues restrictions
        _addValidValuesRestrictions(helpText, arg);

        // expand defaultValue
        _addDefaultValues(helpText, arg);

        // Add list item.
        addListItem(toolDoc, term, helpText);
    }

    // Add options to options section.
    if (length(me.optionMap) != 0)
        addSection(toolDoc, "Options");

    for (unsigned i = 0; i < length(me.optionMap); ++i)
    {
        ArgParseOption const & opt = me.optionMap[i];
        if (empty(opt.shortName) && empty(opt.longName))  // this is not an option but a text line
        {
            if (empty(opt._helpText))  // TODO(holtgrew): Should go away in future.
                continue;  // Skip empty lines.

            // Is command line parser section, maps to ToolDoc subsection.
            for (unsigned j = i + 1; j < length(me.optionMap); ++j)
            {
                ArgParseOption const & nextopt = me.optionMap[j];
                if (empty(nextopt.shortName) && empty(nextopt.longName))
                    break;
                // has visible children
                if (!isHidden(nextopt) && (!isAdvanced(nextopt) || showAdvancedOptions))
                {
                    std::string title = opt._helpText;
                    append(title, ":");
                    addSubSection(toolDoc, title);
                    break;
                }
            }
        }
        else if (!isHidden(opt) && (!isAdvanced(opt) || showAdvancedOptions))
        {
            // Build list item term.
            std::string term;
            if (!empty(opt.shortName))
            {
                term = "\\fB-";
                append(term, opt.shortName);
                append(term, "\\fP");
            }
            if (!empty(opt.shortName) && !empty(opt.longName))
                append(term, ", ");
            if (!empty(opt.longName))
            {
                append(term, "\\fB--");
                append(term, opt.longName);
                append(term, "\\fP");
            }

            // expand type, list and numValues information
            if (!opt._isFlag)
                _addTypeAndListInfo(term, opt);

            std::string helpText = opt._helpText;

            // expand min/max restrictions
            _addNumericalRestriction(helpText, opt);

            // expand validValues restrictions
            _addValidValuesRestrictions(helpText, opt);

            // expand defaultValue
            _addDefaultValues(helpText, opt);

            // Add list item.
            addListItem(toolDoc, term, helpText);
        }
    }

    append(toolDoc, me._toolDoc);
    print(stream, toolDoc, format);
}

inline void printHelp(ArgumentParser const & me, std::ostream & stream, CharString const & format)
{
    printHelp(me, stream, format, false);
}

inline void printHelp(ArgumentParser const & me, std::ostream & stream)
{
    printHelp(me, stream, "txt", false);
}

inline void printHelp(ArgumentParser const & me)
{
    printHelp(me, std::cerr, "txt", false);
}

}  // namespace seqan

#endif  // #ifndef SEQAN_INCLUDE_SEQAN_ARG_PARSE_ARG_PARSE_DOC_H_