npm.io
0.0.7 • Published 3 years agoCLI

cli-env-toggler

Licence
ISC
Version
0.0.7
Deps
4
Size
16 kB
Vulns
0
Weekly
0

CLI Env Toggler

Screenshot

Example_Gif

Usage

Ensure you have Node installed, then run

npx cli-env-toggler [GROUP]

or for more detailed options, run

npx cli-env-toggler -h

Example(s)

1. Database Config

You currently have a .env file with database parameters in, but sometimes switch to another database, and so have commented out the set for the alternate database.

# DB_HOST=host.docker.internal
# DB_PORT=33061
# DB_USERNAME=root
# DB_PASSWORD=

DB_HOST=mysql
DB_PORT=3306
DB_USERNAME=root
DB_PASSWORD=password

When you want to switch, you have to select each of these parameters and enable/disable them, which is a bit of a manual process.

CLI Env Toggler enables you to run a command to instantly uncomment the values that are commented out, and comment out the existing values.

Step 1 - Rewrite .env variables with the following:
###-DB DB_HOST=host.docker.internal
###-DB DB_PORT=33061
###-DB DB_USERNAME=root
###-DB DB_PASSWORD=

DB_HOST=mysql
DB_PORT=3306
DB_USERNAME=root
DB_PASSWORD=password
Step 2 - Run the toggle for the group 'DB'
npx cli-env-toggler DB

And that's it! Your environment variables will now look like the following:

DB_HOST=host.docker.internal
DB_PORT=33061
DB_USERNAME=root
DB_PASSWORD=

###-DB DB_HOST=mysql
###-DB DB_PORT=3306
###-DB DB_USERNAME=root
###-DB DB_PASSWORD=password

Dev

npm run build && npm i -g

Then can do

npx cli-env-toggler