dotnet / dotnet/command-line-api

Provide flag on Option to hide default value if present

Open
#1,456 7 comments 2 reactions 0 assignees View on GitHub
Area-Help
Dominant language
C#
Stars
3.7k
Forks
428
PR merge metrics
No merged PRs in 30d

Description

I created an `Option` for a `--password` option. I am defaulting the option to `Environment.GetVariableName("MY_PASSWORD_ENV")`. I don't want this environment variable to appear in plain text in the option description, but it currently does. I cannot find a way to stop this behavior.

```cs
Option option = new("password");

option.SetDefaultValue(Environment.GetEnvironmentVariable(PasswordEnvironmentVariable));

AddOption(option);
```
```
Options:
password [default: password123] <-- Provide an option to hide this rendering
```
Perhaps something like `Option.IsSecure`?

Another suggestion, although more work, is to incorporate the process of defaulting to environment variables into the library itself. This is a common enough need that it might be worth it.

It might also be nice to support cascading default values. This would support cases where a value should come from an environment variable, if present, but then fall back to a constant value if all else fails. Think options like _database port_:
```
Option value from CLI -> environment variable -> 5432
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.