@karmaniverous/get-dotenv 4.0.0-3 → 4.1.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/README.md CHANGED
@@ -76,62 +76,104 @@ If the value corresponding to a key is a function, it will be executed with the
76
76
 
77
77
  Since keys will be evaluated progressively, each successive key function will have access to any previous ones. These keys can also override existing variables.
78
78
 
79
- ## More to Come!
80
-
81
- Implementation always runs a little behind documentation. These topics & improvements are coming soon:
82
-
83
- - An example of dotenv-based environment config.
84
- - Integrating `getdotenv` into your npm scripts.
85
- - Creating a `getdotenv`-based CLI.
86
- - Some gotchas & tips around managing your shell execution context.
87
-
88
- # Command Line Interface
89
-
90
- Note that the defaults below can be changed in your own environment by deriving your base CLI using the [`generateDotenvCli`](./src/generateGetDotenvCli.ts) function or placing a `getdotenv.options.json` file in your project root directory.
91
-
92
- ```text
93
- Usage: getdotenv [options] [command]
94
-
95
- Base CLI.
96
-
97
- Options:
98
- -e, --env <string> target environment (dotenv-expanded)
99
- -v, --vars <string> extra variables expressed as delimited key-value pairs (dotenv-expanded): KEY1=VAL1 KEY2=VAL2
100
- -c, --command <string> shell command string (dotenv-expanded)
101
- -o, --output-path <string> consolidated output file (dotenv-expanded)
102
- -p, --load-process load variables to process.env ON (default)
103
- -P, --load-process-off load variables to process.env OFF
104
- -a, --exclude-all exclude all dotenv variables from loading ON
105
- -A, --exclude-all-off exclude all dotenv variables from loading OFF (default)
106
- -z, --exclude-dynamic exclude dynamic dotenv variables from loading ON
107
- -Z, --exclude-dynamic-off exclude dynamic dotenv variables from loading OFF (default)
108
- -n, --exclude-env exclude environment-specific dotenv variables from loading
109
- -N, --exclude-env-off exclude environment-specific dotenv variables from loading OFF (default)
110
- -g, --exclude-global exclude global dotenv variables from loading ON
111
- -G, --exclude-global-off exclude global dotenv variables from loading OFF (default)
112
- -r, --exclude-private exclude private dotenv variables from loading ON
113
- -R, --exclude-private-off exclude private dotenv variables from loading OFF (default)
114
- -u, --exclude-public exclude public dotenv variables from loading ON
115
- -U, --exclude-public-off exclude public dotenv variables from loading OFF (default)
116
- -l, --log console log loaded variables ON
117
- -L, --log-off console log loaded variables OFF (default)
118
- -d, --debug debug mode ON
119
- -D, --debug-off debug mode OFF (default)
120
- --default-env <string> default target environment
121
- --dotenv-token <string> dotenv-expanded token indicating a dotenv file (default: ".env")
122
- --dynamic-path <string> dynamic variables path
123
- --paths <string> dotenv-expanded delimited list of paths to dotenv directory (default: "./")
124
- --paths-delimiter <string> paths delimiter string (default: " ")
125
- --paths-delimiter-pattern <string> paths delimiter regex pattern
126
- --private-token <string> dotenv-expanded token indicating private variables (default: "local")
127
- --vars-delimiter <string> vars delimiter string (default: " ")
128
- --vars-delimiter-pattern <string> vars delimiter regex pattern
129
- --vars-assignor <string> vars assignment operator string (default: "=")
130
- --vars-assignor-pattern <string> vars assignment operator regex pattern
79
+ ## Command Line Interface
80
+
81
+ You can also use `getdotenv` from the command line:
82
+
83
+ ```bash
84
+ > npx getdotenv -h
85
+
86
+ # Usage: getdotenv [options] [command]
87
+ #
88
+ # Base CLI.
89
+ #
90
+ # Options:
91
+ # -e, --env <string> target environment (dotenv-expanded)
92
+ # -v, --vars <string> extra variables expressed as delimited key-value pairs (dotenv-expanded): KEY1=VAL1 KEY2=VAL2
93
+ # -c, --command <string> shell command string, conflicts with cmd subcommand (dotenv-expanded)
94
+ # -o, --output-path <string> consolidated output file (dotenv-expanded)
95
+ # -p, --load-process load variables to process.env ON (default)
96
+ # -P, --load-process-off load variables to process.env OFF
97
+ # -a, --exclude-all exclude all dotenv variables from loading ON
98
+ # -A, --exclude-all-off exclude all dotenv variables from loading OFF (default)
99
+ # -z, --exclude-dynamic exclude dynamic dotenv variables from loading ON
100
+ # -Z, --exclude-dynamic-off exclude dynamic dotenv variables from loading OFF (default)
101
+ # -n, --exclude-env exclude environment-specific dotenv variables from loading
102
+ # -N, --exclude-env-off exclude environment-specific dotenv variables from loading OFF (default)
103
+ # -g, --exclude-global exclude global dotenv variables from loading ON
104
+ # -G, --exclude-global-off exclude global dotenv variables from loading OFF (default)
105
+ # -r, --exclude-private exclude private dotenv variables from loading ON
106
+ # -R, --exclude-private-off exclude private dotenv variables from loading OFF (default)
107
+ # -u, --exclude-public exclude public dotenv variables from loading ON
108
+ # -U, --exclude-public-off exclude public dotenv variables from loading OFF (default)
109
+ # -l, --log console log loaded variables ON
110
+ # -L, --log-off console log loaded variables OFF (default)
111
+ # -d, --debug debug mode ON
112
+ # -D, --debug-off debug mode OFF (default)
113
+ # --default-env <string> default target environment
114
+ # --dotenv-token <string> dotenv-expanded token indicating a dotenv file (default: ".env")
115
+ # --dynamic-path <string> dynamic variables path
116
+ # --paths <string> dotenv-expanded delimited list of paths to dotenv directory (default: "./")
117
+ # --paths-delimiter <string> paths delimiter string (default: " ")
118
+ # --paths-delimiter-pattern <string> paths delimiter regex pattern
119
+ # --private-token <string> dotenv-expanded token indicating private variables (default: "local")
120
+ # --vars-delimiter <string> vars delimiter string (default: " ")
121
+ # --vars-delimiter-pattern <string> vars delimiter regex pattern
122
+ # --vars-assignor <string> vars assignment operator string (default: "=")
123
+ # --vars-assignor-pattern <string> vars assignment operator regex pattern
131
124
  -h, --help display help for command
125
+ #
126
+ # Commands:
127
+ # batch [options] Batch shell commands across multiple working directories.
128
+ # cmd execute shell command, conflicts with --command option (default command)
129
+ # help [command] display help for command
130
+ ```
131
+
132
+ See [this example repo](https://github.com/karmaniverous/get-dotenv-child) for a deep dive on using the `getDotenv` CLI and how to extend it for your own projects.
133
+
134
+ ### Batch Command
135
+
136
+ The `getdotenv` base CLI includes one very useful subcommand: `batch`.
137
+
138
+ This command lets you execute a shell command across multiple working directories. Executions occur within the loaded `dotenv` context. Might not be relevant to your specific use case, but when you need it, it's a game-changer!
139
+
140
+ My most common use case for this command is a microservice project where release day finds me updating dependencies & performing a release in well over a dozen very similar repositories. The sequence of steps in each case is exactly the same, but I need to respond individually as issues arise, so scripting the whole thing out would fail more often than it would work.
132
141
 
133
- Commands:
134
- cmd execute shell command string (default command)
135
- help [command] display help for command
142
+ I use the `batch` command to perform each step across all repositories at once. Once you get used to it, it feels like a superpower!
143
+
144
+ Lest you doubt what that kind of leverage can do for you, consider this:
145
+
146
+ [![batch superpower in action](./doc/contributions.png)](https://github.com/karmaniverous)
147
+
148
+ ```bash
149
+ > getdotenv batch -h
150
+
151
+ # Usage: getdotenv batch [options] [command]
152
+ #
153
+ # Batch shell commands across multiple working directories.
154
+ #
155
+ # Options:
156
+ # -p, --pkg-cwd use nearest package directory as current working directory
157
+ # -r, --root-path <string> path to batch root directory from current working directory (default: "./")
158
+ # -g, --globs <strings...> space-delimited globs from root path (default: "*")
159
+ # -c, --command <string> shell command string, conflicts with cmd subcommand (dotenv-expanded)
160
+ # -l, --list list working directories without executing command
161
+ # -e, --ignore-errors ignore errors and continue with next path
162
+ # -h, --help display help for command
163
+ #
164
+ # Commands:
165
+ # cmd batch execute shell command, conflicts with --command option (default command)
166
+ # help [command] display help for command
136
167
  ```
137
168
 
169
+ Note that `batch` executes its commands in sequence, rather than in parallel!
170
+
171
+ To understand why, imagine running `npm install` in a dozen repos from the same command line. The visual feedback would be impossible to follow, and if something broke you'd have a really hard time figuring out why.
172
+
173
+ Instead, everything runs in sequence, and you get a clear record of exactly what heppened and where. Also worth noting that many complex processes are resource hogs: you would not _want_ to run a dozen Serverless deployments at once!
174
+
175
+ Meanwhile, [this issue](https://github.com/karmaniverous/get-dotenv/issues/7) documents the parallel-processing option requirement. Feel free to submit a PR!
176
+
177
+ ---
178
+
179
+ See more great templates & tools on [my GitHub Profile](https://github.com/karmaniverous)!