Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change display text of default values #774

Open
tugrulates opened this issue Dec 14, 2024 · 1 comment · May be fixed by #775
Open

Change display text of default values #774

tugrulates opened this issue Dec 14, 2024 · 1 comment · May be fixed by #775

Comments

@tugrulates
Copy link

Feature request for custom default value display on help.

Currently, a default value is displayed as is on the help.

new Command()
  .option("--token", "Token.", {
    required: true,
    default: "ACTUAL_TOKEN"
  });
Options:

  --token     <token>     - Token.       (required, Default: "ACTUAL_TOKEN")

This allows a pattern where secrets are read from ENV or a cache, and passed to the parser as default values, and only the parser is concerned with validating the required config. In this setup, secrets are preferably not logged to stdout.

Options:

  --token     <token>     - Token.       (required, Default: "AC********EN")

One interface would like the following.

new Command()
  .option("--token", "Token.", {
    required: true,
    default: "ACTUAL_TOKEN",
    defaultDisplay: "AC********EN"
  });

Another option would be simpler.

new Command()
  .option("--token", "Token.", {
    required: true,
    secret: true,
    default: "ACTUAL_TOKEN",
  });

Commander provides an ability to change the display value of default values.

I am happy to contribute if this would be a welcome addition.

@c4spar
Copy link
Owner

c4spar commented Dec 15, 2024

A PR would be welcome @tugrulates!

Adding a defaultDisplay or a defaultText option would be nice. We could also allow it to be string or function string | (defaultValue: TDefault) => string.

Additionally we could also add a defaultText method to the Type class, so the type itself can also change the default text. Then we could also add a new SecretType instead of adding a new secret option:

class SecretType extends StringType {
  public override defaultText(): string {
    return "******";
  }
}
new Command()
  .option("--token <token:secret>", "Token.", {
    default: "ACTUAL_TOKEN",
  });

tugrulates added a commit to tugrulates/deno-cliffy that referenced this issue Dec 17, 2024
This PR adds the following two features related to changing default value display for options.

1. `defaultText` option for options

It is either a string or a function that transforms the default value into string. When set, it changes the help text of the default, while the underlying default value is used for processing.

2. `"secret"` input type

This is exactly the same as string type, except it hides its default values on help text.

Testing: new and existing unittests, playing with the build

Fixes: c4spar#774
tugrulates added a commit to tugrulates/deno-cliffy that referenced this issue Dec 18, 2024
This PR adds the following two features related to changing default value display for options.

1. `defaultText` option for options

It is either a string or a function that transforms the default value into string. When set, it changes the help text of the default, while the underlying default value is used for processing.

2. `"secret"` input type

This is exactly the same as string type, except it hides its default values on help text.

Testing: new and existing unittests, playing with the build

Fixes: c4spar#774
tugrulates added a commit to tugrulates/deno-cliffy that referenced this issue Dec 18, 2024
This PR adds the following two features related to changing default value display for options.

1. `defaultText` option for options

It is either a string or a function that transforms the default value into string. When set, it changes the help text of the default, while the underlying default value is used for processing.

2. `"secret"` input type

This is exactly the same as string type, except it hides its default values on help text.

Testing: new and existing unittests, playing with the build

Fixes: c4spar#774
tugrulates added a commit to tugrulates/deno-cliffy that referenced this issue Dec 18, 2024
This PR adds the following two features related to changing default value display for options.

1. `defaultText` option for options

It is either a string or a function that transforms the default value into string. When set, it changes the help text of the default, while the underlying default value is used for processing.

2. `"secret"` input type

This is exactly the same as string type, except it hides its default values on help text.

Testing: new and existing unittests, playing with the build

Fixes: c4spar#774
tugrulates added a commit to tugrulates/deno-cliffy that referenced this issue Dec 18, 2024
This PR adds the following two features related to changing default value display for options.

1. `defaultText` option for options

It is either a string or a function that transforms the default value into string. When set, it changes the help text of the default, while the underlying default value is used for processing.

2. `"secret"` input type

This is exactly the same as string type, except it hides its default values on help text.

Testing: new and existing unittests, playing with the build

Fixes: c4spar#774
tugrulates added a commit to tugrulates/deno-cliffy that referenced this issue Dec 18, 2024
This PR adds the following two features related to changing default value display for options.

1. `defaultText` option for options

It is either a string or a function that transforms the default value into string. When set, it changes the help text of the default, while the underlying default value is used for processing.

2. `"secret"` input type

This is exactly the same as string type, except it hides its default values on help text.

Testing: new and existing unittests, playing with the build

Fixes: c4spar#774
tugrulates added a commit to tugrulates/deno-cliffy that referenced this issue Dec 18, 2024
This PR adds the following two features related to changing default value display for options.

1. `defaultText` option for options

It is either a string or a function that transforms the default value into string. When set, it changes the help text of the default, while the underlying default value is used for processing.

2. `"secret"` input type

This is exactly the same as string type, except it hides its default values on help text.

Testing: new and existing unittests, playing with the build

Fixes: c4spar#774
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants