Skip to content

Commit

Permalink
Rename HideFromHelp to Hidden (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-zherikov authored Oct 31, 2024
1 parent c3f0cbb commit 6e2e25b
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 18 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
.Validation((char v) { return v >= '0' && v <= '9'; })
```

* `HideFromHelp` is renamed to `Hidden` and now also hides an argument from shell completion.

* Dropped support for DMD-2.099.

### Enhancements and bug fixes
Expand Down
2 changes: 1 addition & 1 deletion docs/code_snippets/help_example.d
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct T
@NamedArgument string s;
@(NamedArgument.Placeholder("VALUE")) string p;

@(NamedArgument.HideFromHelp) string hidden;
@(NamedArgument.Hidden) string hidden;

enum Fruit { apple, pear };
@(NamedArgument("f","fruit").Required.Description("This is a help text for fruit. Very very very very very very very very very very very very very very very very very very very long text")) Fruit f;
Expand Down
2 changes: 1 addition & 1 deletion docs/topics/Help-generation.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ There are some customizations supported on argument level for both `PositionalAr
- `Description` – provides brief description of the argument. This text is printed next to the argument
in the argument-list section of a help message. `Description` takes either `string` or `string function()`
value – the latter can be used to return a value that is not known at compile time.
- `HideFromHelp` – can be used to indicate that the argument shouldn’t be printed in help message.
- `Hidden` – can be used to indicate that the argument shouldn’t be printed in help message.
- `Placeholder` – provides custom text that is used to indicate the value of the argument in help message.

## Help text styling
Expand Down
5 changes: 5 additions & 0 deletions docs/topics/Shell-completion.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
`argparse` supports tab completion of last argument for certain shells (see below). However, this support is limited
to the names of arguments and subcommands.

> Note that hidden arguments are not shown in shell completion. See [Hidden()](PositionalNamedArgument.md#hidden) for details.
>
{style="note"}
or returned in shell completion

## Wrappers for main function

If you are using `CLI!(...).main(alias newMain)` mixin template in your code then you can easily build a completer
Expand Down
8 changes: 4 additions & 4 deletions docs/topics/reference/PositionalNamedArgument.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ struct my_command
}
```
### HideFromHelp
### Hidden
`HideFromHelp` can be used to indicate that the argument should not be printed in help message.
`Hidden` can be used to indicate that the argument should not be printed in help message or returned in shell completion.
**Signature**
```C++
HideFromHelp(auto ref ... argument, bool hide = true)
Hidden(auto ref ... argument, bool hide = true)
```

**Parameters**
Expand All @@ -78,7 +78,7 @@ HideFromHelp(auto ref ... argument, bool hide = true)
```C++
struct my_command
{
@(NamedArgument.HideFromHelp)
@(NamedArgument.Hidden)
int a;
}
```
Expand Down
10 changes: 5 additions & 5 deletions source/argparse/api/argument.d
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ auto ref Optional(T)(auto ref ArgumentUDA!T uda)
return uda;
}

auto ref HideFromHelp(T)(auto ref ArgumentUDA!T uda, bool hide = true)
auto ref Hidden(T)(auto ref ArgumentUDA!T uda, bool hide = true)
{
uda.info.hideFromHelp = hide;
uda.info.hidden = hide;
return uda;
}

Expand Down Expand Up @@ -86,7 +86,7 @@ auto ref MaxNumberOfValues(T)(auto ref ArgumentUDA!T uda, size_t max)
unittest
{
ArgumentUDA!(ValueParser!(void, void)) arg;
assert(!arg.info.hideFromHelp);
assert(!arg.info.hidden);
assert(!arg.info.required);
assert(arg.info.minValuesCount.isNull);
assert(arg.info.maxValuesCount.isNull);
Expand All @@ -98,8 +98,8 @@ unittest
arg = arg.Description(() => "qwer").Placeholder("text");
assert(arg.info.description.get == "qwer");

arg = arg.HideFromHelp.Required.NumberOfValues(10);
assert(arg.info.hideFromHelp);
arg = arg.Hidden.Required.NumberOfValues(10);
assert(arg.info.hidden);
assert(arg.info.required);
assert(arg.info.minValuesCount.get == 10);
assert(arg.info.maxValuesCount.get == 10);
Expand Down
2 changes: 1 addition & 1 deletion source/argparse/internal/arguments.d
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ package(argparse) struct ArgumentInfo

string memberSymbol;

bool hideFromHelp = false; // if true then this argument is not printed on help page
bool hidden = false; // if true then this argument is not printed on help page

bool required;

Expand Down
2 changes: 1 addition & 1 deletion source/argparse/internal/command.d
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ package struct Command
import std.array: array, join;

// suggestions are names of all arguments and subcommands
auto suggestions_ = chain(arguments.namedArguments.map!(_ => _.displayNames).join, subCommands.byName.keys);
auto suggestions_ = chain(arguments.namedArguments.filter!((ref _) => !_.hidden).map!((ref _) => _.displayNames).join, subCommands.byName.keys);

// empty prefix means that we need to provide all suggestions, otherwise they are filtered
return prefix == "" ? suggestions_.array : suggestions_.filter!(_ => _.startsWith(prefix)).array;
Expand Down
6 changes: 3 additions & 3 deletions source/argparse/internal/help.d
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ private void createUsage(void delegate(string) sink, const ref Style style, stri
import std.algorithm: filter, each;

alias print = (r) => r
.filter!((ref _) => !_.hideFromHelp)
.filter!((ref _) => !_.hidden)
.each!((ref _)
{
sink(" ");
Expand Down Expand Up @@ -510,7 +510,7 @@ private auto getSections(const ref Style style, const(Arguments*)[] arguments)

alias showArg = (ref _)
{
if(_.hideFromHelp)
if(_.hidden)
return false;

if(_.shortNames.length > 0 && isHelpArgument(_.shortNames[0]) ||
Expand Down Expand Up @@ -573,7 +573,7 @@ private auto getSection(const ref Style style, in CommandInfo[] commands)

alias showArg = (ref _)
{
//if(_.hideFromHelp)
//if(_.hidden)
// return false;

return _.displayNames.length > 0 && _.displayNames[0].length > 0;
Expand Down
7 changes: 5 additions & 2 deletions source/argparse/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,9 @@ unittest
@NamedArgument
string b = "dummyB";

@(NamedArgument.Hidden)
string hidden;

SubCommand!(cmd1, cmd2) cmd;
}

Expand Down Expand Up @@ -751,7 +754,7 @@ unittest
@Command("MYPROG")
struct T
{
@(NamedArgument.HideFromHelp) string s;
@(NamedArgument.Hidden) string s;
}

assert(CLI!T.parseArgs!((T t) { assert(false); })(["-h","-s","asd"]) == 0);
Expand Down Expand Up @@ -871,7 +874,7 @@ unittest
@NamedArgument string s;
@(NamedArgument.Placeholder("VALUE")) string p;

@(NamedArgument.HideFromHelp) string hidden;
@(NamedArgument.Hidden) string hidden;

enum Fruit { apple, pear };
@(NamedArgument(["f","fruit"]).Required.Description("This is a help text for fruit. Very very very very very very very very very very very very very very very very very very very long text")) Fruit f;
Expand Down

0 comments on commit 6e2e25b

Please sign in to comment.