Merge pull request #189 from thevahidal/188_add_feature_to_pass_env_path_from_cli

Feature to pass `.env` file path from the `CLI`
This commit is contained in:
Ian Mayo
2024-05-08 12:58:43 +01:00
committed by GitHub
5 changed files with 27 additions and 6 deletions

View File

@@ -34,6 +34,7 @@ Options:
-p, --port Port to listen on [number] -p, --port Port to listen on [number]
-r, --rate-limit-enabled Enable rate limiting [boolean] -r, --rate-limit-enabled Enable rate limiting [boolean]
-c, --cors CORS whitelist origins [string] -c, --cors CORS whitelist origins [string]
--env, --envpath Path to load .env file [string]
-a, --auth Enable authentication and authorization [boolean] -a, --auth Enable authentication and authorization [boolean]
--iuu, --initialuserusername Initial user username [string] --iuu, --initialuserusername Initial user username [string]
@@ -42,8 +43,8 @@ Options:
--ts, --tokensecret Token Secret [string] --ts, --tokensecret Token Secret [string]
--atet, --accesstokenexpirationtime Access Token Expiration Time (Default: 5H) [string] --atet, --accesstokenexpirationtime Access Token Expiration Time (Default: 5H) [string]
--rtet, --refreshtokenexpirationtime Refresh Token Expiration Time (Default: 1D) [string] --rtet, --refreshtokenexpirationtime Refresh Token Expiration Time (Default: 1D) [string]
-S, --studio Start Soul Studio in parallel -S, --studio Start Soul Studio in parallel
--help Show help --help Show help
``` ```
@@ -98,6 +99,20 @@ soul -d foobar.db updatesuperuser --id=1 --is_superuser=true // Upgrade the user
soul -d foobar.db updatesuperuser --id=1 --is_superuser=false // Revoke the superuser role from the superuser with ID 1 soul -d foobar.db updatesuperuser --id=1 --is_superuser=false // Revoke the superuser role from the superuser with ID 1
``` ```
### Passing Custom Path for .env File
There might be cases where you want to pass a custom path for your `.env` file. For this, you can use the `--env` flag when running the `soul` command, providing the absolute file path of your `.env` file.
```shell
soul -d foobar.db --env=/Users/Documents/Projects/React-Project/.env
```
NOTE:
- You should pass an absolute file path of the .env file.
- Relative paths are not allowed.
- Don't forget to include the .env file in the specified path.
## Documentation ## Documentation
API documentation is available while the project is running at [http://localhost:8000/api/docs](http://localhost:8000/api/docs) API documentation is available while the project is running at [http://localhost:8000/api/docs](http://localhost:8000/api/docs)

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "soul-cli", "name": "soul-cli",
"version": "0.7.7", "version": "0.7.8",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "soul-cli", "name": "soul-cli",
"version": "0.7.7", "version": "0.7.8",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"bcrypt": "^5.1.1", "bcrypt": "^5.1.1",

View File

@@ -1,6 +1,6 @@
{ {
"name": "soul-cli", "name": "soul-cli",
"version": "0.7.7", "version": "0.7.8",
"description": "A SQLite REST and Realtime server", "description": "A SQLite REST and Realtime server",
"main": "src/server.js", "main": "src/server.js",
"bin": { "bin": {

View File

@@ -46,6 +46,12 @@ if (process.env.NO_CLI !== 'true') {
type: 'string', type: 'string',
demandOption: false, demandOption: false,
}) })
.options('env', {
alias: 'envpath',
describe: 'Environment variable file path to load',
type: 'string',
demandOption: false,
})
.options('a', { .options('a', {
alias: 'auth', alias: 'auth',
describe: 'Enable authentication and authorization', describe: 'Enable authentication and authorization',

View File

@@ -6,7 +6,7 @@ const { yargs } = require('../cli');
const { argv } = yargs; const { argv } = yargs;
dotenv.config({ path: path.join(__dirname, '../../.env') }); dotenv.config({ path: argv.envpath || path.join(__dirname, '../../.env') });
const envVarsSchema = Joi.object() const envVarsSchema = Joi.object()
.keys({ .keys({