MCPcopy
hub / github.com/tj/commander.js / _parseOptionsEnv

Method _parseOptionsEnv

lib/command.js:1978–2001  ·  view source on GitHub ↗

* Apply any option related environment variables, if option does * not have a value from cli or client code. * * @private

()

Source from the content-addressed store, hash-verified

1976 * @private
1977 */
1978 _parseOptionsEnv() {
1979 this.options.forEach((option) => {
1980 if (option.envVar && option.envVar in process.env) {
1981 const optionKey = option.attributeName();
1982 // Priority check. Do not overwrite cli or options from unknown source (client-code).
1983 if (
1984 this.getOptionValue(optionKey) === undefined ||
1985 ['default', 'config', 'env'].includes(
1986 this.getOptionValueSource(optionKey),
1987 )
1988 ) {
1989 if (option.required || option.optional) {
1990 // option can take a value
1991 // keep very simple, optional always takes value
1992 this.emit(`optionEnv:${option.name()}`, process.env[option.envVar]);
1993 } else {
1994 // boolean
1995 // keep very simple, only care that envVar defined and not the value
1996 this.emit(`optionEnv:${option.name()}`);
1997 }
1998 }
1999 }
2000 });
2001 }
2002
2003 /**
2004 * Apply any implied option values, if option is undefined or default value.

Callers 1

_parseCommandMethod · 0.95

Calls 4

getOptionValueMethod · 0.95
getOptionValueSourceMethod · 0.95
attributeNameMethod · 0.80
nameMethod · 0.45

Tested by

no test coverage detected