@keg-hub/args-parse
Advanced tools
Comparing version 8.0.1 to 9.0.0
@@ -12,2 +12,4 @@ | ||
'y', | ||
`1`, | ||
1 | ||
], | ||
@@ -19,3 +21,5 @@ falsy: [ | ||
'no', | ||
'n' | ||
'n', | ||
`0`, | ||
0 | ||
] | ||
@@ -48,5 +52,6 @@ }, | ||
settings: { | ||
defaultEnv: 'development', | ||
fromEnv: `not-empty`, | ||
defaultEnv: 'local', | ||
task: { | ||
optionsAsk: true | ||
optionsAsk: false | ||
} | ||
@@ -53,0 +58,0 @@ } |
{ | ||
"name": "@keg-hub/args-parse", | ||
"version": "8.0.1", | ||
"version": "9.0.0", | ||
"description": "Parse command line arguments", | ||
@@ -36,4 +36,4 @@ "main": "src/index.js", | ||
"dependencies": { | ||
"@keg-hub/ask-it": "latest", | ||
"@keg-hub/jsutils": "latest", | ||
"@keg-hub/ask-it": "*", | ||
"@keg-hub/jsutils": "*", | ||
"app-root-path": "3.0.0" | ||
@@ -43,3 +43,2 @@ }, | ||
"jest": "27.3.1", | ||
"jest-html-reporter": "3.1.3", | ||
"rimraf": "3.0.2" | ||
@@ -66,12 +65,2 @@ }, | ||
], | ||
"reporters": [ | ||
"default", | ||
[ | ||
"./node_modules/jest-html-reporter", | ||
{ | ||
"pageTitle": "ArgsParse Test Results", | ||
"outputPath": "<rootDir>/reports/test-results.html" | ||
} | ||
] | ||
], | ||
"testURL": "http://localhost/", | ||
@@ -78,0 +67,0 @@ "coverageDirectory": "reports/coverage", |
@@ -0,1 +1,2 @@ | ||
const { clearConfig } = require('../utils/getConfig') | ||
const { | ||
@@ -112,2 +113,8 @@ testTask1, | ||
afterEach(() => { | ||
clearConfig() | ||
Ask.ask.mockClear() | ||
Ask.buildModel.mockClear() | ||
}) | ||
it('should set the first arg to the first option if no other args are passed', async () => { | ||
@@ -170,3 +177,4 @@ | ||
it('should call @keg-hub/ask-it when no value is passed and task.ask is exist', async () => { | ||
process.env.PARSE_CONFIG_PATH = 'src/__mocks__/testConfig' | ||
expect(Ask.ask).not.toHaveBeenCalled() | ||
@@ -182,5 +190,21 @@ expect(Ask.buildModel).not.toHaveBeenCalled() | ||
expect(Ask.buildModel).toHaveBeenCalled() | ||
process.env.PARSE_CONFIG_PATH = `` | ||
clearConfig() | ||
}) | ||
it('should not call @keg-hub/ask-it when it is disabled in config', async () => { | ||
expect(Ask.ask).not.toHaveBeenCalled() | ||
expect(Ask.buildModel).not.toHaveBeenCalled() | ||
const parsed = await argsParse({ | ||
args: [ '--context', 'tap' ], | ||
task: testTask2, | ||
}) | ||
expect(Ask.ask).not.toHaveBeenCalled() | ||
expect(Ask.buildModel).not.toHaveBeenCalled() | ||
}) | ||
it('should map the options to the keys when no identifiers are used', async () => { | ||
@@ -187,0 +211,0 @@ |
@@ -21,6 +21,6 @@ const { checkEnvArg } = require('./checkEnvArg') | ||
const ensureArg = async (task, args, key, meta) => { | ||
let resolved = args[key] | ||
// Check if meta-data has an env set | ||
// If no value exists, then use the ENV value (process.env.<SOME_ENV>) | ||
args[key] = checkENVValue(args[key], meta.env) | ||
resolved = checkENVValue(resolved, meta.env) | ||
@@ -30,3 +30,3 @@ // Ensure any boolean shortcuts are mapped to true or false | ||
// See ./configs/parse.config.js for list of boolean shortcuts | ||
args[key] = checkBoolValue(args[key]) | ||
resolved = checkBoolValue(resolved) | ||
@@ -36,10 +36,13 @@ // Ensure env shortcuts are mapped to the correct environment | ||
// See ./configs/parse.config.js for list of env options | ||
args[key] = checkEnvArg(key, args[key], meta.default) | ||
resolved = checkEnvArg(key, resolved, meta.default) | ||
// Validate the metadata type, to ensure it matches the value | ||
// If no value exists, it will return the meta.default | ||
args[key] = checkValueType(key, args[key], meta) | ||
resolved = checkValueType(key, resolved, meta) | ||
// If a value is found, then just return | ||
if(exists(args[key])) return args | ||
if(exists(resolved)){ | ||
args[key] = resolved | ||
return args | ||
} | ||
@@ -46,0 +49,0 @@ // Check if we should ask the user for an option value |
const { findArg } = require('./args/findArg') | ||
const { getConfig } = require('./utils/getConfig') | ||
const { exists, isObj } = require('@keg-hub/jsutils') | ||
const { parseQuotes } = require('./utils/parseQuotes') | ||
const { mapKeysToArgs } = require('./args/mapKeysToArgs') | ||
const { convertNoArgs } = require('./utils/convertNoArgs') | ||
const { getOptionMeta } = require('./options/getOptionMeta') | ||
@@ -10,4 +12,2 @@ const { ensureArg, ensureArgs } = require('./args/ensureArgs') | ||
const { optionsHasIdentifiers } = require('./options/optionsHasIdentifiers') | ||
const { parseQuotes } = require('./utils/parseQuotes') | ||
const { convertNoArgs } = require('./utils/convertNoArgs') | ||
@@ -14,0 +14,0 @@ /** |
@@ -1,4 +0,24 @@ | ||
const { exists } = require('@keg-hub/jsutils') | ||
const { exists, get } = require('@keg-hub/jsutils') | ||
const { getConfig } = require('../utils/getConfig') | ||
/** | ||
* Check how envs should be loaded based on the config | ||
* @param {string} metaEnv - name of the env from the option meta data | ||
*/ | ||
const useENVValues = (metaEnv) => { | ||
if(!metaEnv) return false | ||
const envName = metaEnv.trim() | ||
const envVal = process.env[envName] | ||
if(!envName || !exists(envVal)) return false | ||
const envSetting = get(getConfig(), 'settings.fromEnv') | ||
return !envSetting || envSetting === false || (envSetting === `not-empty` && envVal.trim() === ``) | ||
? false | ||
: true | ||
} | ||
/** | ||
* If the option meta-data has an env set, then check if it exists, and use it's value | ||
@@ -14,3 +34,3 @@ * IMPORTANT - If no value exists, and meta.env does exist | ||
const checkENVValue = (value, metaEnv) => { | ||
return !exists(value) && exists(process.env[metaEnv]) | ||
return !exists(value) && useENVValues(metaEnv) | ||
? process.env[metaEnv] | ||
@@ -17,0 +37,0 @@ : value |
@@ -15,2 +15,6 @@ const path = require('path') | ||
jest.resetModules() | ||
process.env.PARSE_CONFIG_PATH = undefined | ||
delete process.env.PARSE_CONFIG_PATH | ||
process.env.KEG_TASKS_CONFIG = undefined | ||
delete process.env.KEG_TASKS_CONFIG | ||
}) | ||
@@ -46,3 +50,3 @@ | ||
it('should load and merge the config from an ENV when set', () => { | ||
it('should load and merge the config from a ENV PARSE_CONFIG_PATH when set', () => { | ||
@@ -56,5 +60,14 @@ process.env.PARSE_CONFIG_PATH = 'src/__mocks__/testConfig' | ||
process.env.PARSE_CONFIG_PATH = undefined | ||
delete process.env.PARSE_CONFIG_PATH | ||
}) | ||
it('should work with alternate ENV KEG_TASKS_CONFIG', () => { | ||
expect(process.env.PARSE_CONFIG_PATH).toBe(undefined) | ||
process.env.KEG_TASKS_CONFIG = 'src/__mocks__/testConfig' | ||
const config = getConfig() | ||
expect(typeof config).toBe('object') | ||
expect(typeof config.test).toBe('object') | ||
expect(typeof config.environment).toBe('object') | ||
}) | ||
@@ -61,0 +74,0 @@ |
@@ -73,4 +73,7 @@ const path = require('path') | ||
const loadConfig = (inlineConfig=noOpObj) => { | ||
const { PARSE_CONFIG_PATH } = process.env | ||
const configPath = path.join(appRoot, PARSE_CONFIG_PATH || 'configs/parse.config.js') | ||
const { PARSE_CONFIG_PATH, KEG_TASKS_CONFIG } = process.env | ||
const configPath = path.join( | ||
appRoot, | ||
PARSE_CONFIG_PATH || KEG_TASKS_CONFIG || 'configs/parse.config.js' | ||
) | ||
@@ -77,0 +80,0 @@ let customConfig |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 2 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54254
2
1531
2
30
Updated@keg-hub/ask-it@*
Updated@keg-hub/jsutils@*