Skip to content

Commit ff15c3b

Browse files
committed
Merge pull request #3 from aiche/prefix-support
[API,FEATURE] added additional input and output type prefix to arg_parse
2 parents f840b2f + 5048815 commit ff15c3b

4 files changed

Lines changed: 120 additions & 16 deletions

File tree

core/include/seqan/arg_parse/arg_parse_argument.h

Lines changed: 98 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,14 @@ class ArgParseArgument
151151
enum ArgumentType
152152
{
153153
// argument is
154-
STRING, // .. a string
155-
INTEGER, // .. an integer
156-
INT64, // .. a 64 bit integer
157-
DOUBLE, // .. a float
158-
INPUTFILE, // .. an inputfile (implicitly also a string)
159-
OUTPUTFILE // .. an outputfile (implicitly also a string)
154+
STRING, // .. a string
155+
INTEGER, // .. an integer
156+
INT64, // .. a 64 bit integer
157+
DOUBLE, // .. a float
158+
INPUTFILE, // .. an inputfile (implicitly also a string)
159+
OUTPUTFILE, // .. an outputfile (implicitly also a string)
160+
INPUTPREFIX, // .. an inputprefix (implicitly also a string)
161+
OUTPUTPREFIX // .. an outoutprefix (implicitly also a string)
160162
};
161163

162164

@@ -256,6 +258,14 @@ inline std::string _typeToString(ArgParseArgument const & me)
256258
typeName = "outputfile";
257259
break;
258260

261+
case ArgParseArgument::INPUTPREFIX:
262+
typeName = "inputprefix";
263+
break;
264+
265+
case ArgParseArgument::OUTPUTPREFIX:
266+
typeName = "outputprefix";
267+
break;
268+
259269
default:
260270
typeName = "unknown";
261271
break;
@@ -333,7 +343,9 @@ inline bool isStringArgument(ArgParseArgument const & me)
333343
{
334344
return (me._argumentType == ArgParseArgument::STRING) ||
335345
(me._argumentType == ArgParseArgument::INPUTFILE) ||
336-
(me._argumentType == ArgParseArgument::OUTPUTFILE);
346+
(me._argumentType == ArgParseArgument::OUTPUTFILE) ||
347+
(me._argumentType == ArgParseArgument::INPUTPREFIX) ||
348+
(me._argumentType == ArgParseArgument::OUTPUTPREFIX) ;
337349
}
338350

339351
// ----------------------------------------------------------------------------
@@ -425,7 +437,7 @@ inline bool isInt64Argument(ArgParseArgument const & me)
425437
..class:Class.ArgParseArgument
426438
..summary:Returns whether the argument is a double.
427439
..cat:Miscellaneous
428-
..signature:isListArgument(argument)
440+
..signature:isDoubleArgument(argument)
429441
..param.argument:The @Class.ArgParseArgument@ object.
430442
...type:Class.ArgParseArgument
431443
..returns:$true$ if the argument argument is a double argument.
@@ -445,7 +457,7 @@ inline bool isDoubleArgument(ArgParseArgument const & me)
445457
/*!
446458
* @fn ArgParseArgument#isInputFileArgument
447459
* @headerfile <seqan/arg_parse.h>
448-
* @brief Returns whether the argument is a input file integer.
460+
* @brief Returns whether the argument is a input file.
449461
*
450462
* @signature bool isInputFileArgument(arg);
451463
*
@@ -459,7 +471,7 @@ inline bool isDoubleArgument(ArgParseArgument const & me)
459471
..class:Class.ArgParseArgument
460472
..summary:Returns whether the argument is an input file.
461473
..cat:Miscellaneous
462-
..signature:isListArgument(argument)
474+
..signature:isOutputFileArgument(argument)
463475
..param.argument:The @Class.ArgParseArgument@ object.
464476
...type:Class.ArgParseArgument
465477
..returns:$true$ if the argument argument is an input file argument.
@@ -479,7 +491,7 @@ inline bool isInputFileArgument(ArgParseArgument const & me)
479491
/*!
480492
* @fn ArgParseArgument#isOutputFileArgument
481493
* @headerfile <seqan/arg_parse.h>
482-
* @brief Returns whether the argument is a output file integer.
494+
* @brief Returns whether the argument is a output file.
483495
*
484496
* @signature bool isOutputFileArgument(arg);
485497
*
@@ -493,7 +505,7 @@ inline bool isInputFileArgument(ArgParseArgument const & me)
493505
..class:Class.ArgParseArgument
494506
..summary:Returns whether the argument is an output file.
495507
..cat:Miscellaneous
496-
..signature:isListArgument(argument)
508+
..signature:isOutputFileArgument(argument)
497509
..param.argument:The @Class.ArgParseArgument@ object.
498510
...type:Class.ArgParseArgument
499511
...type:Class.ArgParseOption
@@ -507,6 +519,76 @@ inline bool isOutputFileArgument(ArgParseArgument const & me)
507519
return me._argumentType == ArgParseArgument::OUTPUTFILE;
508520
}
509521

522+
// ----------------------------------------------------------------------------
523+
// Function isOutputPrefixArgument()
524+
// ----------------------------------------------------------------------------
525+
526+
/*!
527+
* @fn ArgParseArgument#isOutputPrefixArgument
528+
* @headerfile <seqan/arg_parse.h>
529+
* @brief Returns whether the argument is an output prefix.
530+
*
531+
* @signature bool isOutputPrefixArgument(arg);
532+
*
533+
* @param arg The ArgParseArgument to query.
534+
*
535+
* @return bool <tt>true</tt> if it is an output prefix argument, <tt>false</tt> otherwise.
536+
*/
537+
538+
/**
539+
.Function.isOutputPrefixArgument
540+
..class:Class.ArgParseArgument
541+
..summary:Returns whether the argument is an output file.
542+
..cat:Miscellaneous
543+
..signature:isOutputPrefixArgument(argument)
544+
..param.argument:The @Class.ArgParseArgument@ object.
545+
...type:Class.ArgParseArgument
546+
...type:Class.ArgParseOption
547+
..returns:$true$ if the argument argument is an output file argument.
548+
..see:Memfunc.ArgParseArgument#ArgParseArgument.param.argumentType
549+
..include:seqan/arg_parse.h
550+
*/
551+
552+
inline bool isOutputPrefixArgument(ArgParseArgument const & me)
553+
{
554+
return me._argumentType == ArgParseArgument::OUTPUTPREFIX;
555+
}
556+
557+
// ----------------------------------------------------------------------------
558+
// Function isOutputFileArgument()
559+
// ----------------------------------------------------------------------------
560+
561+
/*!
562+
* @fn ArgParseArgument#isInputPrefixArgument
563+
* @headerfile <seqan/arg_parse.h>
564+
* @brief Returns whether the argument is an input prefix argument.
565+
*
566+
* @signature bool isInputPrefixArgument(arg);
567+
*
568+
* @param arg The ArgParseArgument to query.
569+
*
570+
* @return bool <tt>true</tt> if it is an input prefix argument, <tt>false</tt> otherwise.
571+
*/
572+
573+
/**
574+
.Function.isInputPrefixArgument
575+
..class:Class.ArgParseArgument
576+
..summary:Returns whether the argument is an output file.
577+
..cat:Miscellaneous
578+
..signature:isInputPrefixArgument(argument)
579+
..param.argument:The @Class.ArgParseArgument@ object.
580+
...type:Class.ArgParseArgument
581+
...type:Class.ArgParseOption
582+
..returns:$true$ if the argument argument is an input prefix argument.
583+
..see:Memfunc.ArgParseArgument#ArgParseArgument.param.argumentType
584+
..include:seqan/arg_parse.h
585+
*/
586+
587+
inline bool isInputPrefixArgument(ArgParseArgument const & me)
588+
{
589+
return me._argumentType == ArgParseArgument::INPUTPREFIX;
590+
}
591+
510592
// ----------------------------------------------------------------------------
511593
// Function getArgumentLabel()
512594
// ----------------------------------------------------------------------------
@@ -548,6 +630,8 @@ inline std::string const getArgumentLabel(ArgParseArgument const & me)
548630
std::string baseLabel = "";
549631
if (isInputFileArgument(me) || isOutputFileArgument(me))
550632
baseLabel = "FILE";
633+
else if (isInputPrefixArgument(me) || isOutputPrefixArgument(me))
634+
baseLabel = "PREFIX";
551635
else if (isStringArgument(me))
552636
baseLabel = "STR";
553637
else if (isIntegerArgument(me) || isDoubleArgument(me))
@@ -893,7 +977,8 @@ inline void _checkStringRestrictions(ArgParseArgument const & me, std::string va
893977
{
894978
typedef std::vector<std::string>::const_iterator TVectorIterator;
895979

896-
if (!empty(me.validValues))
980+
// we only check valid values for files and string arguments, but not for prefix arguments
981+
if (!empty(me.validValues) && !(isInputPrefixArgument(me) || isOutputPrefixArgument(me)))
897982
{
898983
bool isContained = false;
899984
for (TVectorIterator validValue = me.validValues.begin();

core/include/seqan/arg_parse/arg_parse_ctd_support.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ inline void
169169
_getRestrictions(std::vector<std::string> & restrictions, ArgParseArgument const & opt)
170170
{
171171
// we only extract non-file restrictions
172-
if (isOutputFileArgument(opt) || isInputFileArgument(opt))
172+
if (isOutputFileArgument(opt) || isInputFileArgument(opt) || isInputPrefixArgument(opt) || isOutputPrefixArgument(opt))
173173
return;
174174

175175
if (length(opt.validValues) != 0)
@@ -209,7 +209,7 @@ inline void
209209
_getSupportedFormats(std::vector<std::string> & supported_formats, ArgParseArgument const & opt)
210210
{
211211
// we check only file arguments
212-
if (!(isOutputFileArgument(opt) || isInputFileArgument(opt)))
212+
if (!(isOutputFileArgument(opt) || isInputFileArgument(opt) || isInputPrefixArgument(opt) || isOutputPrefixArgument(opt)))
213213
return;
214214

215215
if (length(opt.validValues) != 0)
@@ -408,6 +408,10 @@ writeCTD(ArgumentParser const & me, std::ostream & ctdfile)
408408
type = "input-file";
409409
else if (isOutputFileArgument(opt))
410410
type = "output-file";
411+
else if (isInputPrefixArgument(opt))
412+
type = "input-prefix";
413+
else if (isOutputPrefixArgument(opt))
414+
type = "output-prefix";
411415
else if (isStringArgument(opt) || isBooleanOption(opt))
412416
type = "string";
413417

@@ -419,7 +423,6 @@ writeCTD(ArgumentParser const & me, std::ostream & ctdfile)
419423
std::vector<std::string> supported_formats;
420424
_getSupportedFormats(supported_formats, opt);
421425

422-
423426
ctdfile << _indent(currentIndent)
424427
<< "<ITEM" << (isListArgument(opt) ? "LIST" : "") << " name=\"" << xmlEscape(optionName) << "\"";
425428

@@ -487,6 +490,10 @@ writeCTD(ArgumentParser const & me, std::ostream & ctdfile)
487490
type = "input-file";
488491
else if (isOutputFileArgument(arg))
489492
type = "output-file";
493+
else if (isInputPrefixArgument(arg))
494+
type = "input-prefix";
495+
else if (isOutputPrefixArgument(arg))
496+
type = "output-prefix";
490497
else if (isStringArgument(arg))
491498
type = "string";
492499

core/tests/arg_parse/test_app.ctd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ The second one contains formating &lt;bla&gt;.
3333
<clielement optionIdentifier="--out-file-ext" isList="false">
3434
<mapping referenceName="test_app.out-file-ext" />
3535
</clielement>
36+
<clielement optionIdentifier="--input-prefix-option" isList="false">
37+
<mapping referenceName="test_app.input-prefix-option" />
38+
</clielement>
39+
<clielement optionIdentifier="--output-prefix-option" isList="false">
40+
<mapping referenceName="test_app.output-prefix-option" />
41+
</clielement>
3642
<clielement optionIdentifier="--hidden" isList="false">
3743
<mapping referenceName="test_app.hidden" />
3844
</clielement>
@@ -59,6 +65,8 @@ The second one contains formating &lt;bla&gt;.
5965
<ITEM name="in-file-ext" value="" type="string" description="Override file extension for --in" restrictions="fasta" required="false" advanced="true" tags="file-ext-override,gkn-ignore" />
6066
<ITEM name="out" value="" type="output-file" description="set an output file" supported_formats="*.sam" required="false" advanced="false" />
6167
<ITEM name="out-file-ext" value="" type="string" description="Override file extension for --out" restrictions="sam" required="false" advanced="true" tags="file-ext-override,gkn-ignore" />
68+
<ITEM name="input-prefix-option" value="" type="input-prefix" description="set an input prefix" supported_formats="*.btx" required="false" advanced="false" />
69+
<ITEM name="output-prefix-option" value="" type="output-prefix" description="set an output prefix" supported_formats="*.blub" required="false" advanced="false" />
6270
<ITEM name="hidden" value="" type="string" description="a hidden option - will be advanced in the ctd" required="false" advanced="true" />
6371
<ITEM name="argument-0" value="" type="double" description="Double Argument" required="true" advanced="false" />
6472
<ITEM name="argument-1" value="" type="string" description="Documentated Argument with formating" required="true" advanced="false" />

core/tests/arg_parse/test_arg_parse_ctd_support.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ SEQAN_DEFINE_TEST(test_arg_parse_ctd_support)
6666
setValidValues(parser, "f", "fasta");
6767
addOption(parser, seqan::ArgParseOption("o", "out", "set an output file", seqan::ArgParseArgument::OUTPUTFILE));
6868
setValidValues(parser, "o", "sam");
69+
addOption(parser, seqan::ArgParseOption("ip", "input-prefix-option", "set an input prefix", seqan::ArgParseArgument::INPUTPREFIX));
70+
setValidValues(parser, "ip", "btx");
71+
addOption(parser, seqan::ArgParseOption("op", "output-prefix-option", "set an output prefix", seqan::ArgParseArgument::OUTPUTPREFIX));
72+
setValidValues(parser, "output-prefix-option", "blub");
6973
addOption(parser, seqan::ArgParseOption("hi", "hidden", "a hidden option - will be advanced in the ctd", seqan::ArgParseArgument::STRING));
7074

7175
hideOption(parser, "hi");

0 commit comments

Comments
 (0)