@karmaniverous/get-dotenv 3.0.4 → 3.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -79,31 +79,38 @@ Usage: getdotenv [options] [command]
79
79
  Base CLI. All options except delimiters follow dotenv-expand rules.
80
80
 
81
81
  Options:
82
- -e, --env <string> target environment
83
- --default-env <string> default target environment (default: "dev")
84
- -p, --paths <string> delimited list of paths to dotenv directory (default: "./")
85
- --paths-delimiter <string> regex paths delimiter (default: "\\s+")
86
- -v, --vars <string> delimited list KEY=VALUE pairs
87
- --vars-delimiter <string> regex vars delimiter (default: "\\s+")
88
- --vars-assignor <string> regex vars assignment operator (default: "=")
89
- -y, --dynamic-path <string> dynamic variables path
90
- -o, --output-path <string> consolidated output file, follows dotenv-expand rules using loaded env vars
91
- -n, --exclude-env [bool] exclude environment-specific variables (default: false)
92
- -g, --exclude-global [bool] exclude global & dynamic variables (default: false)
93
- -r, --exclude-private [bool] exclude private variables (default: false)
94
- -u, --exclude-public [bool] exclude public variables (default: false)
95
- -z, --exclude-dynamic [bool] exclude dynamic variables (default: false)
96
- -l, --log [bool] console log extracted variables (default: false)
97
- -x, --suppress-dotenv suppress dotenv loading (default: false)
98
- -c, --command <string> shell command string
99
- -s, --shell <string> execa shell option
100
- --dotenv-token <string> token indicating a dotenv file (default: ".env")
101
- --private-token <string> token indicating private variables (default: "local")
102
- -h, --help display help for command
82
+ -e, --env <string> target environment
83
+ --default-env <string> default target environment (default: "dev")
84
+ -p, --paths <string> delimited list of paths to dotenv directory (default: "./")
85
+ --paths-delimiter <string> regex paths delimiter (default: "\\s+")
86
+ -v, --vars <string> delimited list KEY=VALUE pairs
87
+ --vars-delimiter <string> regex vars delimiter (default: "\\s+")
88
+ --vars-assignor <string> regex vars assignment operator (default: "=")
89
+ -y, --dynamic-path <string> dynamic variables path
90
+ -o, --output-path <string> consolidated output file, follows dotenv-expand rules using loaded env vars
91
+ -n, --exclude-env exclude environment-specific variables
92
+ -N, --exclude-env-off exclude environment-specific variables OFF (default)
93
+ -g, --exclude-global exclude global variables
94
+ -G, --exclude-global-off exclude global variables OFF (default)
95
+ -r, --exclude-private exclude private variables
96
+ -R, --exclude-private-off exclude private variables OFF (default)
97
+ -u, --exclude-public exclude public variables
98
+ -U, --exclude-public-off exclude public variables OFF (default)
99
+ -z, --exclude-dynamic exclude dynamic variables
100
+ -Z, --exclude-dynamic-off exclude dynamic variables OFF (default)
101
+ -l, --log console log extracted variables
102
+ -L, --log-off console log extracted variables OFF (default)
103
+ -x, --suppress-dotenv suppress dotenv loading (default: false)
104
+ -c, --command <string> shell command string
105
+ -s, --shell <string> execa shell option
106
+ --dotenv-token <string> token indicating a dotenv file (default: ".env")
107
+ --private-token <string> token indicating private variables (default: "local")
108
+ -D, --debug debug mode
109
+ -h, --help display help for command
103
110
 
104
111
  Commands:
105
- cmd execute shell command string (default command)
106
- help [command] display help for command
112
+ cmd execute shell command string (default command)
113
+ help [command] display help for command
107
114
  ```
108
115
 
109
116
  # API Documentation
@@ -194,6 +201,7 @@ GetDotenv CLI Options type
194
201
  | Name | Type | Description |
195
202
  | --- | --- | --- |
196
203
  | [cliInvocation] | <code>string</code> | cli invocation string (used for cli help) |
204
+ | [debug] | <code>bool</code> | debug mode |
197
205
  | [defaultEnv] | <code>string</code> | default target environment |
198
206
  | [dotenvToken] | <code>string</code> | token indicating a dotenv file |
199
207
  | [dynamicPath] | <code>string</code> | path to file exporting an object keyed to dynamic variable functions |
@@ -208,7 +216,7 @@ GetDotenv CLI Options type
208
216
  | [outputPath] | <code>string</code> | if populated, writes consolidated .env file to this path (follows [dotenv-expand rules](https://github.com/motdotla/dotenv-expand/blob/master/tests/.env)) |
209
217
  | [paths] | <code>string</code> | space-delimited list of input directory paths |
210
218
  | [privateToken] | <code>string</code> | token indicating private variables. |
211
- | [shell] | <code>bool</code> \| <code>string</code> | execa shell option |
219
+ | [shell] | <code>string</code> | execa shell option |
212
220
  | [suppressDotenv] | <code>bool</code> | suppress dotenv loading |
213
221
 
214
222
  <a name="GetDotenvPreHookCallback"></a>
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  // lib imports
4
4
  import { getCli } from '../../lib/getCli.js';
@@ -24,6 +24,7 @@ const booleanExpand = value => (0, _boolean.boolean)((0, _dotenvExpand.dotenvExp
24
24
  *
25
25
  * @typedef {Object} GetDotenvCliOptions
26
26
  * @property {string} [cliInvocation] - cli invocation string (used for cli help)
27
+ * @property {bool} [debug] - debug mode
27
28
  * @property {string} [defaultEnv] - default target environment
28
29
  * @property {string} [dotenvToken] - token indicating a dotenv file
29
30
  * @property {string} [dynamicPath] - path to file exporting an object keyed to dynamic variable functions
@@ -38,7 +39,7 @@ const booleanExpand = value => (0, _boolean.boolean)((0, _dotenvExpand.dotenvExp
38
39
  * @property {string} [outputPath] - if populated, writes consolidated .env file to this path (follows {@link https://github.com/motdotla/dotenv-expand/blob/master/tests/.env dotenv-expand rules})
39
40
  * @property {string} [paths] - space-delimited list of input directory paths
40
41
  * @property {string} [privateToken] - token indicating private variables.
41
- * @property {bool|string} [shell] - execa shell option
42
+ * @property {string} [shell] - execa shell option
42
43
  * @property {bool} [suppressDotenv] - suppress dotenv loading
43
44
  */
44
45
 
@@ -109,11 +110,7 @@ const getCli = function () {
109
110
  ...defaultOptions
110
111
  };
111
112
  if (Array.isArray(paths)) paths = paths.join(' ');
112
- return new _commander.Command().name(cliInvocation)
113
- // .usage('[options] [command] [command options] [commad args]')
114
- .description('Base CLI. All options except delimiters follow dotenv-expand rules.').enablePositionalOptions().passThroughOptions().option('-e, --env <string>', 'target environment', _dotenvExpand.dotenvExpand, env).option('--default-env <string>', 'default target environment', _dotenvExpand.dotenvExpand, defaultEnv).option('-p, --paths <string>', 'delimited list of paths to dotenv directory', _dotenvExpand.dotenvExpand, paths).option('--paths-delimiter <string>', 'regex paths delimiter', pathsDelimiter).option('-v, --vars <string>', 'delimited list KEY=VALUE pairs', _dotenvExpand.dotenvExpand, vars).option('--vars-delimiter <string>', 'regex vars delimiter', varsDelimiter).option('--vars-assignor <string>', 'regex vars assignment operator', varsAssignor).option('-y, --dynamic-path <string>', 'dynamic variables path', _dotenvExpand.dotenvExpand, dynamicPath).option('-o, --output-path <string>', 'consolidated output file, follows dotenv-expand rules using loaded env vars', _dotenvExpand.dotenvExpand, outputPath).option('-n, --exclude-env [bool]', 'exclude environment-specific variables', booleanExpand, excludeEnv ?? false).option('-g, --exclude-global [bool]', 'exclude global & dynamic variables', booleanExpand, excludeGlobal ?? false).option('-r, --exclude-private [bool]', 'exclude private variables', booleanExpand, excludePrivate ?? false).option('-u, --exclude-public [bool]', 'exclude public variables', booleanExpand, excludePublic ?? false).option('-z, --exclude-dynamic [bool]', 'exclude dynamic variables', booleanExpand, excludeDynamic ?? false).option('-l, --log [bool]', 'console log extracted variables', booleanExpand, log ?? 'false').option('-x, --suppress-dotenv', 'suppress dotenv loading', booleanExpand, suppressDotenv ?? false).option('-c, --command <string>', 'shell command string', _dotenvExpand.dotenvExpand, command).option('-s, --shell <string>', 'execa shell option', _dotenvExpand.dotenvExpand, shell).option('--dotenv-token <string>', 'token indicating a dotenv file', _dotenvExpand.dotenvExpand, dotenvToken).option('--private-token <string>', 'token indicating private variables', _dotenvExpand.dotenvExpand, privateToken).addCommand(new _commander.Command().name('cmd').description('execute shell command string')
115
- // .description('execute shell command string (default command)')
116
- .configureHelp({
113
+ return new _commander.Command().name(cliInvocation).description('Base CLI. All options except delimiters follow dotenv-expand rules.').enablePositionalOptions().passThroughOptions().option('-e, --env <string>', 'target environment', _dotenvExpand.dotenvExpand, env).option('--default-env <string>', 'default target environment', _dotenvExpand.dotenvExpand, defaultEnv).option('-p, --paths <string>', 'delimited list of paths to dotenv directory', _dotenvExpand.dotenvExpand, paths).option('--paths-delimiter <string>', 'regex paths delimiter', pathsDelimiter).option('-v, --vars <string>', 'delimited list KEY=VALUE pairs', _dotenvExpand.dotenvExpand, vars).option('--vars-delimiter <string>', 'regex vars delimiter', varsDelimiter).option('--vars-assignor <string>', 'regex vars assignment operator', varsAssignor).option('-y, --dynamic-path <string>', 'dynamic variables path', _dotenvExpand.dotenvExpand, dynamicPath).option('-o, --output-path <string>', 'consolidated output file, follows dotenv-expand rules using loaded env vars', _dotenvExpand.dotenvExpand, outputPath).addOption(new _commander.Option('-n, --exclude-env', `exclude environment-specific variables${excludeEnv ? ' (default)' : ''}`).conflicts('excludeEnvOff')).addOption(new _commander.Option('-N, --exclude-env-off', `exclude environment-specific variables OFF${!excludeEnv ? ' (default)' : ''}`).conflicts('excludeEnv')).addOption(new _commander.Option('-g, --exclude-global', `exclude global variables${excludeGlobal ? ' (default)' : ''}`).conflicts('excludeGlobalOff')).addOption(new _commander.Option('-G, --exclude-global-off', `exclude global variables OFF${!excludeGlobal ? ' (default)' : ''}`).conflicts('excludeGlobal')).addOption(new _commander.Option('-r, --exclude-private', `exclude private variables${excludePrivate ? ' (default)' : ''}`).conflicts('excludePrivateOff')).addOption(new _commander.Option('-R, --exclude-private-off', `exclude private variables OFF${!excludePrivate ? ' (default)' : ''}`).conflicts('excludePrivate')).addOption(new _commander.Option('-u, --exclude-public', `exclude public variables${excludePublic ? ' (default)' : ''}`).conflicts('excludePublicOff')).addOption(new _commander.Option('-U, --exclude-public-off', `exclude public variables OFF${!excludePublic ? ' (default)' : ''}`).conflicts('excludePublic')).addOption(new _commander.Option('-z, --exclude-dynamic', `exclude dynamic variables${excludeDynamic ? ' (default)' : ''}`).conflicts('excludeDynamicOff')).addOption(new _commander.Option('-Z, --exclude-dynamic-off', `exclude dynamic variables OFF${!excludeDynamic ? ' (default)' : ''}`).conflicts('excludeDynamic')).addOption(new _commander.Option('-l, --log', `console log extracted variables${log ? ' (default)' : ''}`).conflicts('logOff')).addOption(new _commander.Option('-L, --log-off', `console log extracted variables OFF${!log ? ' (default)' : ''}`).conflicts('log')).option('-x, --suppress-dotenv', 'suppress dotenv loading', booleanExpand, suppressDotenv ?? false).option('-c, --command <string>', 'shell command string', _dotenvExpand.dotenvExpand, command).option('-s, --shell <string>', 'execa shell option', _dotenvExpand.dotenvExpand, shell).option('--dotenv-token <string>', 'token indicating a dotenv file', _dotenvExpand.dotenvExpand, dotenvToken).option('--private-token <string>', 'token indicating private variables', _dotenvExpand.dotenvExpand, privateToken).option('-D, --debug', 'debug mode').addCommand(new _commander.Command().name('cmd').description('execute shell command string (default command)').configureHelp({
117
114
  showGlobalOptions: true
118
115
  }).enablePositionalOptions().passThroughOptions().action(async (options, _ref) => {
119
116
  let {
@@ -124,22 +121,39 @@ const getCli = function () {
124
121
  stdio: 'inherit',
125
122
  shell: parent.opts().shell
126
123
  });
127
- })
128
- // { isDefault: true }
129
- ).hook('preSubcommand', async thisCommand => {
124
+ }), {
125
+ isDefault: true
126
+ }).hook('preSubcommand', async thisCommand => {
130
127
  var _paths;
131
128
  // Inherit options from parent command.
132
- let options = {
133
- ...(process.env['getdotenvOptions'] ? JSON.parse(process.env['getdotenvOptions']) : {}),
134
- ...thisCommand.opts()
129
+ const getdotenvOptions = process.env['getdotenvOptions'] ? JSON.parse(process.env['getdotenvOptions']) : {};
130
+ const {
131
+ excludeDynamicOff,
132
+ excludeEnvOff,
133
+ excludeGlobalOff,
134
+ excludePrivateOff,
135
+ excludePublicOff,
136
+ logOff,
137
+ ...localOptions
138
+ } = thisCommand.opts();
139
+ if (excludeDynamicOff) localOptions.excludeDynamic = false;
140
+ if (excludeEnvOff) localOptions.excludeEnv = false;
141
+ if (excludeGlobalOff) localOptions.excludeGlobal = false;
142
+ if (excludePrivateOff) localOptions.excludePrivate = false;
143
+ if (excludePublicOff) localOptions.excludePublic = false;
144
+ if (logOff) localOptions.log = false;
145
+ let mergedOptions = {
146
+ ...getdotenvOptions,
147
+ ...localOptions
135
148
  };
136
149
 
137
150
  // Execute pre-hook.
138
- if (preHook) options = (await preHook(options)) ?? options;
151
+ const options = preHook ? (await preHook(mergedOptions)) ?? mergedOptions : mergedOptions;
139
152
 
140
153
  // Get options.
141
154
  let {
142
155
  command,
156
+ debug,
143
157
  defaultEnv,
144
158
  env,
145
159
  paths,
@@ -153,6 +167,13 @@ const getCli = function () {
153
167
 
154
168
  // Parse vars.
155
169
  const vars = varsStr !== null && varsStr !== void 0 && varsStr.length ? (0, _lodash.default)(varsStr.split(new RegExp(varsDelimiter)).map(v => v.split(new RegExp(varsAssignor)))) : undefined;
170
+ if (debug) {
171
+ console.log('*** getdotenvOptions ***', getdotenvOptions);
172
+ console.log('*** localOptions ***', localOptions);
173
+ console.log('*** mergedOptions ***', mergedOptions);
174
+ console.log('*** options ***', options);
175
+ console.log('*** vars ***', vars);
176
+ }
156
177
 
157
178
  // Execute getdotenv.
158
179
  if ((_paths = paths) !== null && _paths !== void 0 && _paths.length && !suppressDotenv) {
@@ -166,6 +187,7 @@ const getCli = function () {
166
187
  vars
167
188
  });
168
189
  }
190
+ if (debug) console.log('*** dotenv ***', dotenv);
169
191
 
170
192
  // Execute post-hook.
171
193
  if (postHook) await postHook(options, dotenv);
package/lib/getCli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // npm imports
2
2
  import { boolean } from 'boolean';
3
- import { Command } from 'commander';
3
+ import { Command, Option } from 'commander';
4
4
  import { execaCommand } from 'execa';
5
5
  import fromPairs from 'lodash.frompairs';
6
6
  import isString from 'lodash.isstring';
@@ -17,6 +17,7 @@ const booleanExpand = (value) => boolean(dotenvExpand(value));
17
17
  *
18
18
  * @typedef {Object} GetDotenvCliOptions
19
19
  * @property {string} [cliInvocation] - cli invocation string (used for cli help)
20
+ * @property {bool} [debug] - debug mode
20
21
  * @property {string} [defaultEnv] - default target environment
21
22
  * @property {string} [dotenvToken] - token indicating a dotenv file
22
23
  * @property {string} [dynamicPath] - path to file exporting an object keyed to dynamic variable functions
@@ -31,7 +32,7 @@ const booleanExpand = (value) => boolean(dotenvExpand(value));
31
32
  * @property {string} [outputPath] - if populated, writes consolidated .env file to this path (follows {@link https://github.com/motdotla/dotenv-expand/blob/master/tests/.env dotenv-expand rules})
32
33
  * @property {string} [paths] - space-delimited list of input directory paths
33
34
  * @property {string} [privateToken] - token indicating private variables.
34
- * @property {bool|string} [shell] - execa shell option
35
+ * @property {string} [shell] - execa shell option
35
36
  * @property {bool} [suppressDotenv] - suppress dotenv loading
36
37
  */
37
38
 
@@ -99,196 +100,261 @@ export const getCli = ({ defaultOptions = {}, preHook, postHook } = {}) => {
99
100
 
100
101
  if (Array.isArray(paths)) paths = paths.join(' ');
101
102
 
102
- return (
103
- new Command()
104
- .name(cliInvocation)
105
- // .usage('[options] [command] [command options] [commad args]')
106
- .description(
107
- 'Base CLI. All options except delimiters follow dotenv-expand rules.'
108
- )
109
- .enablePositionalOptions()
110
- .passThroughOptions()
111
- .option('-e, --env <string>', 'target environment', dotenvExpand, env)
112
- .option(
113
- '--default-env <string>',
114
- 'default target environment',
115
- dotenvExpand,
116
- defaultEnv
117
- )
118
- .option(
119
- '-p, --paths <string>',
120
- 'delimited list of paths to dotenv directory',
121
- dotenvExpand,
122
- paths
123
- )
124
- .option(
125
- '--paths-delimiter <string>',
126
- 'regex paths delimiter',
127
- pathsDelimiter
128
- )
129
- .option(
130
- '-v, --vars <string>',
131
- 'delimited list KEY=VALUE pairs',
132
- dotenvExpand,
133
- vars
134
- )
135
- .option(
136
- '--vars-delimiter <string>',
137
- 'regex vars delimiter',
138
- varsDelimiter
139
- )
140
- .option(
141
- '--vars-assignor <string>',
142
- 'regex vars assignment operator',
143
- varsAssignor
144
- )
145
- .option(
146
- '-y, --dynamic-path <string>',
147
- 'dynamic variables path',
148
- dotenvExpand,
149
- dynamicPath
150
- )
151
- .option(
152
- '-o, --output-path <string>',
153
- 'consolidated output file, follows dotenv-expand rules using loaded env vars',
154
- dotenvExpand,
155
- outputPath
156
- )
157
- .option(
158
- '-n, --exclude-env [bool]',
159
- 'exclude environment-specific variables',
160
- booleanExpand,
161
- excludeEnv ?? false
162
- )
163
- .option(
164
- '-g, --exclude-global [bool]',
165
- 'exclude global & dynamic variables',
166
- booleanExpand,
167
- excludeGlobal ?? false
168
- )
169
- .option(
170
- '-r, --exclude-private [bool]',
171
- 'exclude private variables',
172
- booleanExpand,
173
- excludePrivate ?? false
174
- )
175
- .option(
176
- '-u, --exclude-public [bool]',
177
- 'exclude public variables',
178
- booleanExpand,
179
- excludePublic ?? false
180
- )
181
- .option(
182
- '-z, --exclude-dynamic [bool]',
183
- 'exclude dynamic variables',
184
- booleanExpand,
185
- excludeDynamic ?? false
186
- )
187
- .option(
188
- '-l, --log [bool]',
189
- 'console log extracted variables',
190
- booleanExpand,
191
- log ?? 'false'
192
- )
193
- .option(
194
- '-x, --suppress-dotenv',
195
- 'suppress dotenv loading',
196
- booleanExpand,
197
- suppressDotenv ?? false
198
- )
199
- .option(
200
- '-c, --command <string>',
201
- 'shell command string',
202
- dotenvExpand,
203
- command
204
- )
205
- .option('-s, --shell <string>', 'execa shell option', dotenvExpand, shell)
206
- .option(
207
- '--dotenv-token <string>',
208
- 'token indicating a dotenv file',
209
- dotenvExpand,
210
- dotenvToken
211
- )
212
- .option(
213
- '--private-token <string>',
214
- 'token indicating private variables',
215
- dotenvExpand,
216
- privateToken
217
- )
218
- .addCommand(
219
- new Command()
220
- .name('cmd')
221
- .description('execute shell command string')
222
- // .description('execute shell command string (default command)')
223
- .configureHelp({ showGlobalOptions: true })
224
- .enablePositionalOptions()
225
- .passThroughOptions()
226
- .action(async (options, { args, parent }) => {
227
- if (args.length)
228
- await execaCommand(args.join(' '), {
229
- stdio: 'inherit',
230
- shell: parent.opts().shell,
231
- });
232
- })
233
- // { isDefault: true }
234
- )
235
- .hook('preSubcommand', async (thisCommand) => {
236
- // Inherit options from parent command.
237
- let options = {
238
- ...(process.env['getdotenvOptions']
239
- ? JSON.parse(process.env['getdotenvOptions'])
240
- : {}),
241
- ...thisCommand.opts(),
242
- };
103
+ return new Command()
104
+ .name(cliInvocation)
105
+ .description(
106
+ 'Base CLI. All options except delimiters follow dotenv-expand rules.'
107
+ )
108
+ .enablePositionalOptions()
109
+ .passThroughOptions()
110
+ .option('-e, --env <string>', 'target environment', dotenvExpand, env)
111
+ .option(
112
+ '--default-env <string>',
113
+ 'default target environment',
114
+ dotenvExpand,
115
+ defaultEnv
116
+ )
117
+ .option(
118
+ '-p, --paths <string>',
119
+ 'delimited list of paths to dotenv directory',
120
+ dotenvExpand,
121
+ paths
122
+ )
123
+ .option(
124
+ '--paths-delimiter <string>',
125
+ 'regex paths delimiter',
126
+ pathsDelimiter
127
+ )
128
+ .option(
129
+ '-v, --vars <string>',
130
+ 'delimited list KEY=VALUE pairs',
131
+ dotenvExpand,
132
+ vars
133
+ )
134
+ .option('--vars-delimiter <string>', 'regex vars delimiter', varsDelimiter)
135
+ .option(
136
+ '--vars-assignor <string>',
137
+ 'regex vars assignment operator',
138
+ varsAssignor
139
+ )
140
+ .option(
141
+ '-y, --dynamic-path <string>',
142
+ 'dynamic variables path',
143
+ dotenvExpand,
144
+ dynamicPath
145
+ )
146
+ .option(
147
+ '-o, --output-path <string>',
148
+ 'consolidated output file, follows dotenv-expand rules using loaded env vars',
149
+ dotenvExpand,
150
+ outputPath
151
+ )
152
+ .addOption(
153
+ new Option(
154
+ '-n, --exclude-env',
155
+ `exclude environment-specific variables${
156
+ excludeEnv ? ' (default)' : ''
157
+ }`
158
+ ).conflicts('excludeEnvOff')
159
+ )
160
+ .addOption(
161
+ new Option(
162
+ '-N, --exclude-env-off',
163
+ `exclude environment-specific variables OFF${
164
+ !excludeEnv ? ' (default)' : ''
165
+ }`
166
+ ).conflicts('excludeEnv')
167
+ )
168
+ .addOption(
169
+ new Option(
170
+ '-g, --exclude-global',
171
+ `exclude global variables${excludeGlobal ? ' (default)' : ''}`
172
+ ).conflicts('excludeGlobalOff')
173
+ )
174
+ .addOption(
175
+ new Option(
176
+ '-G, --exclude-global-off',
177
+ `exclude global variables OFF${!excludeGlobal ? ' (default)' : ''}`
178
+ ).conflicts('excludeGlobal')
179
+ )
180
+ .addOption(
181
+ new Option(
182
+ '-r, --exclude-private',
183
+ `exclude private variables${excludePrivate ? ' (default)' : ''}`
184
+ ).conflicts('excludePrivateOff')
185
+ )
186
+ .addOption(
187
+ new Option(
188
+ '-R, --exclude-private-off',
189
+ `exclude private variables OFF${!excludePrivate ? ' (default)' : ''}`
190
+ ).conflicts('excludePrivate')
191
+ )
192
+ .addOption(
193
+ new Option(
194
+ '-u, --exclude-public',
195
+ `exclude public variables${excludePublic ? ' (default)' : ''}`
196
+ ).conflicts('excludePublicOff')
197
+ )
198
+ .addOption(
199
+ new Option(
200
+ '-U, --exclude-public-off',
201
+ `exclude public variables OFF${!excludePublic ? ' (default)' : ''}`
202
+ ).conflicts('excludePublic')
203
+ )
204
+ .addOption(
205
+ new Option(
206
+ '-z, --exclude-dynamic',
207
+ `exclude dynamic variables${excludeDynamic ? ' (default)' : ''}`
208
+ ).conflicts('excludeDynamicOff')
209
+ )
210
+ .addOption(
211
+ new Option(
212
+ '-Z, --exclude-dynamic-off',
213
+ `exclude dynamic variables OFF${!excludeDynamic ? ' (default)' : ''}`
214
+ ).conflicts('excludeDynamic')
215
+ )
216
+ .addOption(
217
+ new Option(
218
+ '-l, --log',
219
+ `console log extracted variables${log ? ' (default)' : ''}`
220
+ ).conflicts('logOff')
221
+ )
222
+ .addOption(
223
+ new Option(
224
+ '-L, --log-off',
225
+ `console log extracted variables OFF${!log ? ' (default)' : ''}`
226
+ ).conflicts('log')
227
+ )
228
+ .option(
229
+ '-x, --suppress-dotenv',
230
+ 'suppress dotenv loading',
231
+ booleanExpand,
232
+ suppressDotenv ?? false
233
+ )
234
+ .option(
235
+ '-c, --command <string>',
236
+ 'shell command string',
237
+ dotenvExpand,
238
+ command
239
+ )
240
+ .option('-s, --shell <string>', 'execa shell option', dotenvExpand, shell)
241
+ .option(
242
+ '--dotenv-token <string>',
243
+ 'token indicating a dotenv file',
244
+ dotenvExpand,
245
+ dotenvToken
246
+ )
247
+ .option(
248
+ '--private-token <string>',
249
+ 'token indicating private variables',
250
+ dotenvExpand,
251
+ privateToken
252
+ )
253
+ .option('-D, --debug', 'debug mode')
254
+ .addCommand(
255
+ new Command()
256
+ .name('cmd')
257
+ .description('execute shell command string (default command)')
258
+ .configureHelp({ showGlobalOptions: true })
259
+ .enablePositionalOptions()
260
+ .passThroughOptions()
261
+ .action(async (options, { args, parent }) => {
262
+ if (args.length)
263
+ await execaCommand(args.join(' '), {
264
+ stdio: 'inherit',
265
+ shell: parent.opts().shell,
266
+ });
267
+ }),
268
+ { isDefault: true }
269
+ )
270
+ .hook('preSubcommand', async (thisCommand) => {
271
+ // Inherit options from parent command.
272
+ const getdotenvOptions = process.env['getdotenvOptions']
273
+ ? JSON.parse(process.env['getdotenvOptions'])
274
+ : {};
243
275
 
244
- // Execute pre-hook.
245
- if (preHook) options = (await preHook(options)) ?? options;
276
+ const {
277
+ excludeDynamicOff,
278
+ excludeEnvOff,
279
+ excludeGlobalOff,
280
+ excludePrivateOff,
281
+ excludePublicOff,
282
+ logOff,
283
+ ...localOptions
284
+ } = thisCommand.opts();
246
285
 
247
- // Get options.
248
- let {
249
- command,
250
- defaultEnv,
251
- env,
252
- paths,
253
- pathsDelimiter,
254
- suppressDotenv,
255
- vars: varsStr,
256
- varsDelimiter,
257
- varsAssignor,
258
- ...rest
259
- } = options;
286
+ if (excludeDynamicOff) localOptions.excludeDynamic = false;
287
+ if (excludeEnvOff) localOptions.excludeEnv = false;
288
+ if (excludeGlobalOff) localOptions.excludeGlobal = false;
289
+ if (excludePrivateOff) localOptions.excludePrivate = false;
290
+ if (excludePublicOff) localOptions.excludePublic = false;
291
+ if (logOff) localOptions.log = false;
292
+
293
+ let mergedOptions = {
294
+ ...getdotenvOptions,
295
+ ...localOptions,
296
+ };
297
+
298
+ // Execute pre-hook.
299
+ const options = preHook
300
+ ? (await preHook(mergedOptions)) ?? mergedOptions
301
+ : mergedOptions;
302
+
303
+ // Get options.
304
+ let {
305
+ command,
306
+ debug,
307
+ defaultEnv,
308
+ env,
309
+ paths,
310
+ pathsDelimiter,
311
+ suppressDotenv,
312
+ vars: varsStr,
313
+ varsDelimiter,
314
+ varsAssignor,
315
+ ...rest
316
+ } = options;
260
317
 
261
- // Parse vars.
262
- const vars = varsStr?.length
263
- ? fromPairs(
264
- varsStr
265
- .split(new RegExp(varsDelimiter))
266
- .map((v) => v.split(new RegExp(varsAssignor)))
267
- )
268
- : undefined;
318
+ // Parse vars.
319
+ const vars = varsStr?.length
320
+ ? fromPairs(
321
+ varsStr
322
+ .split(new RegExp(varsDelimiter))
323
+ .map((v) => v.split(new RegExp(varsAssignor)))
324
+ )
325
+ : undefined;
269
326
 
270
- // Execute getdotenv.
271
- if (paths?.length && !suppressDotenv) {
272
- if (isString(paths)) paths = paths?.split(new RegExp(pathsDelimiter));
327
+ if (debug) {
328
+ console.log('*** getdotenvOptions ***', getdotenvOptions);
329
+ console.log('*** localOptions ***', localOptions);
330
+ console.log('*** mergedOptions ***', mergedOptions);
331
+ console.log('*** options ***', options);
332
+ console.log('*** vars ***', vars);
333
+ }
334
+
335
+ // Execute getdotenv.
336
+ if (paths?.length && !suppressDotenv) {
337
+ if (isString(paths)) paths = paths?.split(new RegExp(pathsDelimiter));
338
+
339
+ var dotenv = await getDotenv({
340
+ ...rest,
341
+ env: env ?? defaultEnv,
342
+ loadProcess: true,
343
+ paths,
344
+ vars,
345
+ });
346
+ }
273
347
 
274
- var dotenv = await getDotenv({
275
- ...rest,
276
- env: env ?? defaultEnv,
277
- loadProcess: true,
278
- paths,
279
- vars,
280
- });
281
- }
348
+ if (debug) console.log('*** dotenv ***', dotenv);
282
349
 
283
- // Execute post-hook.
284
- if (postHook) await postHook(options, dotenv);
350
+ // Execute post-hook.
351
+ if (postHook) await postHook(options, dotenv);
285
352
 
286
- // Execute shell command.
287
- if (command)
288
- await execaCommand(command, {
289
- stdio: 'inherit',
290
- shell,
291
- });
292
- })
293
- );
353
+ // Execute shell command.
354
+ if (command)
355
+ await execaCommand(command, {
356
+ stdio: 'inherit',
357
+ shell,
358
+ });
359
+ });
294
360
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "bin": {
4
4
  "getdotenv": "bin/getdotenv/index.js"
5
5
  },
6
- "version": "3.0.4",
6
+ "version": "3.0.5",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },