Skip to content

Commit

Permalink
Fix for positional argument name (#71)
Browse files Browse the repository at this point in the history
* Positional argument name fix

* Add unit tests
  • Loading branch information
andrey-zherikov authored Aug 29, 2022
1 parent 18c1598 commit 415c1b5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion source/argparse/help.d
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ unittest

@(NamedArgument.AllowedValues!([1,4,16,8])) int i;

@(PositionalArgument(0).Description("This is a help text for param0. Very very very very very very very very very very very very very very very very very very very long text")) string param0;
@(PositionalArgument(0, "param0").Description("This is a help text for param0. Very very very very very very very very very very very very very very very very very very very long text")) string _param0;
@(PositionalArgument(1).AllowedValues!(["q","a"])) string param1;

@TrailingArguments string[] args;
Expand Down
38 changes: 35 additions & 3 deletions source/argparse/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,7 @@ auto PositionalArgument(uint pos)

auto PositionalArgument(uint pos, string name)
{
auto arg = ArgumentUDA!(ValueParseFunctions!(void, void, void, void, void, void))(ArgumentInfo([name])).Required();
arg.info.position = pos;
return arg;
return PositionalArgument(pos).Placeholder(name);
}

auto NamedArgument(string[] name...)
Expand All @@ -433,6 +431,40 @@ auto NamedArgument(string name)

struct TrailingArguments {}


unittest
{
auto arg = PositionalArgument(3, "foo");
assert(arg.info.required);
assert(arg.info.positional);
assert(arg.info.position == 3);
assert(arg.info.placeholder == "foo");
}

unittest
{
auto arg = NamedArgument("foo");
assert(!arg.info.required);
assert(!arg.info.positional);
assert(arg.info.names == ["foo"]);
}

unittest
{
auto arg = NamedArgument(["foo","bar"]);
assert(!arg.info.required);
assert(!arg.info.positional);
assert(arg.info.names == ["foo","bar"]);
}

unittest
{
auto arg = NamedArgument("foo","bar");
assert(!arg.info.required);
assert(!arg.info.positional);
assert(arg.info.names == ["foo","bar"]);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

package struct Group
Expand Down

0 comments on commit 415c1b5

Please sign in to comment.