env-var icon indicating copy to clipboard operation
env-var copied to clipboard

Add description() function

Open structinfo opened this issue 4 years ago • 2 comments

Is your feature request related to a problem? Please describe. It would be helpful to provide a description for each environment variable.

Describe the solution you'd like A .description('Specifies that and that') function which text may be used in error messages as well as enhance code readability. Moreover if a .help() function will be implemented (see separate issue) this description text may be used to generate help text.

structinfo avatar Jan 25 '21 08:01 structinfo

@structinfo this certainly could be helpful. Do you think it could be used to replace the current example() or should be used in conjunction with it?

Currently if a developer uses the example() they get output like this on error:

env-var: "ADMIN_EMAIL" is a required variable, but it was not set. An
example of a valid value would be "[email protected]"

With description('This value is used to alert an admin...') should this become similar to the following example?

env-var: "ADMIN_EMAIL" is a required variable, but it was not set. An
example of a valid value would be "[email protected]". This value
 is used to alert an admin...

evanshortiss avatar Feb 08 '21 13:02 evanshortiss

+1 to this. For example, I might let people know where to go to pick up the credentials (e.g. "Check your account settings for the API key: https://airtable.com/account").

I think example(...) is neat. I'd add this as a separate thing.

It'd be amazing if, somehow, all of this metadata around env vars could be pulled out into a .env.template with the examples / descriptions inlined as comments, categorised by required/optional.

janbaykara avatar Jun 15 '21 16:06 janbaykara

Implemented in version 8. You can test it using npm install env-var@beta. I will make an official release after some more testing.

evanshortiss avatar Dec 25 '22 04:12 evanshortiss