@dotenvx/dotenvx 1.16.1 → 1.17.0
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/CHANGELOG.md +7 -1
- package/README.md +27 -0
- package/package.json +1 -1
- package/src/cli/actions/get.js +10 -3
- package/src/cli/dotenvx.js +1 -1
- package/src/lib/helpers/escape.js +5 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
-
## [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.
|
|
5
|
+
## [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.17.0...main)
|
|
6
|
+
|
|
7
|
+
## 1.17.0
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
* add `--format=eval` option for `get` ([#393](https://github.com/dotenvx/dotenvx/pull/393))
|
|
6
12
|
|
|
7
13
|
## 1.16.1
|
|
8
14
|
|
package/README.md
CHANGED
|
@@ -1072,6 +1072,33 @@ More examples
|
|
|
1072
1072
|
```
|
|
1073
1073
|
|
|
1074
1074
|
</details>
|
|
1075
|
+
* <details><summary>`get --format eval`</summary><br>
|
|
1076
|
+
|
|
1077
|
+
Return an `eval`-ready shell formatted response of all key/value pairs in a `.env` file.
|
|
1078
|
+
|
|
1079
|
+
```sh
|
|
1080
|
+
$ echo "HELLO=World" > .env
|
|
1081
|
+
$ echo "KEY=value" >> .env
|
|
1082
|
+
|
|
1083
|
+
$ dotenvx get --format eval
|
|
1084
|
+
HELLO="World"
|
|
1085
|
+
KEY="value"
|
|
1086
|
+
```
|
|
1087
|
+
|
|
1088
|
+
Note that this exports newlines and quoted strings.
|
|
1089
|
+
|
|
1090
|
+
This can be useful for more complex .env values (spaces, escaped characters, quotes, etc) combined with `eval` on the command line.
|
|
1091
|
+
|
|
1092
|
+
```
|
|
1093
|
+
$ echo "console.log('Hello ' + process.env.KEY + ' ' + process.env.HELLO)" > index.js
|
|
1094
|
+
$ eval $(dotenvx get --format=eval) node index.js
|
|
1095
|
+
Hello value World
|
|
1096
|
+
```
|
|
1097
|
+
|
|
1098
|
+
Be careful with `eval` as it allows for arbitrary execution of commands. Prefer `dotenvx run --` but in some cases `eval` is a sharp knife that is useful to have.
|
|
1099
|
+
|
|
1100
|
+
</details>
|
|
1101
|
+
|
|
1075
1102
|
* <details><summary>`get --all`</summary><br>
|
|
1076
1103
|
|
|
1077
1104
|
Return preset machine envs as well.
|
package/package.json
CHANGED
package/src/cli/actions/get.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const { logger } = require('./../../shared/logger')
|
|
2
2
|
|
|
3
3
|
const conventions = require('./../../lib/helpers/conventions')
|
|
4
|
+
const escape = require('./../../lib/helpers/escape')
|
|
4
5
|
|
|
5
6
|
const main = require('./../../lib/main')
|
|
6
7
|
|
|
@@ -23,8 +24,15 @@ function get (key) {
|
|
|
23
24
|
const results = main.get(key, envs, options.overload, process.env.DOTENV_KEY, options.all)
|
|
24
25
|
|
|
25
26
|
if (typeof results === 'object' && results !== null) {
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
if (options.format === 'eval') {
|
|
28
|
+
let inline = ''
|
|
29
|
+
for (const [key, value] of Object.entries(results)) {
|
|
30
|
+
inline += `${key}=${escape(value)}\n`
|
|
31
|
+
}
|
|
32
|
+
inline = inline.trim()
|
|
33
|
+
|
|
34
|
+
console.log(inline)
|
|
35
|
+
} else if (options.format === 'shell') {
|
|
28
36
|
let inline = ''
|
|
29
37
|
for (const [key, value] of Object.entries(results)) {
|
|
30
38
|
inline += `${key}=${value} `
|
|
@@ -32,7 +40,6 @@ function get (key) {
|
|
|
32
40
|
inline = inline.trim()
|
|
33
41
|
|
|
34
42
|
console.log(inline)
|
|
35
|
-
// json format
|
|
36
43
|
} else {
|
|
37
44
|
let space = 0
|
|
38
45
|
if (options.prettyPrint) {
|
package/src/cli/dotenvx.js
CHANGED
|
@@ -75,7 +75,7 @@ program.command('get')
|
|
|
75
75
|
.option('--convention <name>', 'load a .env convention (available conventions: [\'nextjs\'])')
|
|
76
76
|
.option('-a, --all', 'include all machine envs as well')
|
|
77
77
|
.option('-pp, --pretty-print', 'pretty print output')
|
|
78
|
-
.option('--format <type>', 'format of the output (json, shell)', 'json')
|
|
78
|
+
.option('--format <type>', 'format of the output (json, shell, eval)', 'json')
|
|
79
79
|
.action(function (...args) {
|
|
80
80
|
this.envs = envs
|
|
81
81
|
|