mirror of
https://github.com/toddbluhm/env-cmd.git
synced 2025-12-08 18:23:33 +00:00
chore(package): updated ts-standard version
- improved code readability of options parsing - added missing code coverage test cases
This commit is contained in:
parent
0498a0701d
commit
c0ce28cb84
@ -1,5 +1,8 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 10.1.1 - Pending
|
||||||
|
- **Upgrade**: Updated devDependencies `ts-standard`
|
||||||
|
|
||||||
## 10.1.0
|
## 10.1.0
|
||||||
|
|
||||||
- **Feature**: Added support for expanding vars using the `-x` flag.
|
- **Feature**: Added support for expanding vars using the `-x` flag.
|
||||||
|
|||||||
29
dist/parse-args.js
vendored
29
dist/parse-args.js
vendored
@ -14,11 +14,28 @@ function parseArgs(args) {
|
|||||||
const commandArgs = args.splice(args.indexOf(command) + 1);
|
const commandArgs = args.splice(args.indexOf(command) + 1);
|
||||||
// Reprocess the args with the command and command args removed
|
// Reprocess the args with the command and command args removed
|
||||||
program = parseArgsUsingCommander(args.slice(0, args.indexOf(command)));
|
program = parseArgsUsingCommander(args.slice(0, args.indexOf(command)));
|
||||||
const noOverride = !program.override;
|
// Set values for provided options
|
||||||
const useShell = !!program.useShell;
|
let noOverride = false;
|
||||||
const expandEnvs = !!program.expandEnvs;
|
// In commander `no-` negates the original value `override`
|
||||||
const verbose = !!program.verbose;
|
if (program.override === false) {
|
||||||
const silent = !!program.silent;
|
noOverride = true;
|
||||||
|
}
|
||||||
|
let useShell = false;
|
||||||
|
if (program.useShell === true) {
|
||||||
|
useShell = true;
|
||||||
|
}
|
||||||
|
let expandEnvs = false;
|
||||||
|
if (program.expandEnvs === true) {
|
||||||
|
expandEnvs = true;
|
||||||
|
}
|
||||||
|
let verbose = false;
|
||||||
|
if (program.verbose === true) {
|
||||||
|
verbose = true;
|
||||||
|
}
|
||||||
|
let silent = false;
|
||||||
|
if (program.silent === true) {
|
||||||
|
silent = true;
|
||||||
|
}
|
||||||
let rc;
|
let rc;
|
||||||
if (program.environments !== undefined && program.environments.length !== 0) {
|
if (program.environments !== undefined && program.environments.length !== 0) {
|
||||||
rc = {
|
rc = {
|
||||||
@ -46,7 +63,7 @@ function parseArgs(args) {
|
|||||||
verbose
|
verbose
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (verbose === true) {
|
if (verbose) {
|
||||||
console.info(`Options: ${JSON.stringify(options, null, 0)}`);
|
console.info(`Options: ${JSON.stringify(options, null, 0)}`);
|
||||||
}
|
}
|
||||||
return options;
|
return options;
|
||||||
|
|||||||
2
dist/parse-env-file.js
vendored
2
dist/parse-env-file.js
vendored
@ -17,7 +17,7 @@ async function getEnvFileVars(envFilePath) {
|
|||||||
// Get the file extension
|
// Get the file extension
|
||||||
const ext = path.extname(absolutePath).toLowerCase();
|
const ext = path.extname(absolutePath).toLowerCase();
|
||||||
let env = {};
|
let env = {};
|
||||||
if (REQUIRE_HOOK_EXTENSIONS.indexOf(ext) > -1) {
|
if (REQUIRE_HOOK_EXTENSIONS.includes(ext)) {
|
||||||
const possiblePromise = require(absolutePath); /* eslint-disable-line */
|
const possiblePromise = require(absolutePath); /* eslint-disable-line */
|
||||||
env = utils_1.isPromise(possiblePromise) ? await possiblePromise : possiblePromise;
|
env = utils_1.isPromise(possiblePromise) ? await possiblePromise : possiblePromise;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -62,7 +62,7 @@
|
|||||||
"nyc": "^15.0.0",
|
"nyc": "^15.0.0",
|
||||||
"sinon": "^8.0.0",
|
"sinon": "^8.0.0",
|
||||||
"ts-node": "^8.0.0",
|
"ts-node": "^8.0.0",
|
||||||
"ts-standard": "^4.0.0",
|
"ts-standard": "^5.0.0",
|
||||||
"typescript": "^3.7.0"
|
"typescript": "^3.7.0"
|
||||||
},
|
},
|
||||||
"nyc": {
|
"nyc": {
|
||||||
|
|||||||
@ -16,11 +16,29 @@ export function parseArgs (args: string[]): EnvCmdOptions {
|
|||||||
|
|
||||||
// Reprocess the args with the command and command args removed
|
// Reprocess the args with the command and command args removed
|
||||||
program = parseArgsUsingCommander(args.slice(0, args.indexOf(command)))
|
program = parseArgsUsingCommander(args.slice(0, args.indexOf(command)))
|
||||||
const noOverride = !(program.override as boolean)
|
|
||||||
const useShell = !!(program.useShell as boolean)
|
// Set values for provided options
|
||||||
const expandEnvs = !!(program.expandEnvs as boolean)
|
let noOverride = false
|
||||||
const verbose = !!(program.verbose as boolean)
|
// In commander `no-` negates the original value `override`
|
||||||
const silent = !!(program.silent as boolean)
|
if (program.override === false) {
|
||||||
|
noOverride = true
|
||||||
|
}
|
||||||
|
let useShell = false
|
||||||
|
if (program.useShell === true) {
|
||||||
|
useShell = true
|
||||||
|
}
|
||||||
|
let expandEnvs = false
|
||||||
|
if (program.expandEnvs === true) {
|
||||||
|
expandEnvs = true
|
||||||
|
}
|
||||||
|
let verbose = false
|
||||||
|
if (program.verbose === true) {
|
||||||
|
verbose = true
|
||||||
|
}
|
||||||
|
let silent = false
|
||||||
|
if (program.silent === true) {
|
||||||
|
silent = true
|
||||||
|
}
|
||||||
|
|
||||||
let rc: any
|
let rc: any
|
||||||
if (program.environments !== undefined && program.environments.length !== 0) {
|
if (program.environments !== undefined && program.environments.length !== 0) {
|
||||||
@ -51,7 +69,7 @@ export function parseArgs (args: string[]): EnvCmdOptions {
|
|||||||
verbose
|
verbose
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (verbose === true) {
|
if (verbose) {
|
||||||
console.info(`Options: ${JSON.stringify(options, null, 0)}`)
|
console.info(`Options: ${JSON.stringify(options, null, 0)}`)
|
||||||
}
|
}
|
||||||
return options
|
return options
|
||||||
|
|||||||
@ -18,7 +18,7 @@ export async function getEnvFileVars (envFilePath: string): Promise<{ [key: stri
|
|||||||
// Get the file extension
|
// Get the file extension
|
||||||
const ext = path.extname(absolutePath).toLowerCase()
|
const ext = path.extname(absolutePath).toLowerCase()
|
||||||
let env = {}
|
let env = {}
|
||||||
if (REQUIRE_HOOK_EXTENSIONS.indexOf(ext) > -1) {
|
if (REQUIRE_HOOK_EXTENSIONS.includes(ext)) {
|
||||||
const possiblePromise = require(absolutePath) /* eslint-disable-line */
|
const possiblePromise = require(absolutePath) /* eslint-disable-line */
|
||||||
env = isPromise(possiblePromise) ? await possiblePromise : possiblePromise
|
env = isPromise(possiblePromise) ? await possiblePromise : possiblePromise
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -91,4 +91,16 @@ describe('parseArgs', (): void => {
|
|||||||
assert.exists(res.options!.verbose)
|
assert.exists(res.options!.verbose)
|
||||||
assert.equal(logInfoStub.callCount, 1)
|
assert.equal(logInfoStub.callCount, 1)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should parse expandEnvs option', (): void => {
|
||||||
|
const res = parseArgs(['-f', envFilePath, '-x', command, ...commandArgs])
|
||||||
|
assert.exists(res.envFile)
|
||||||
|
assert.isTrue(res.options!.expandEnvs)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should parse silent option', (): void => {
|
||||||
|
const res = parseArgs(['-f', envFilePath, '--silent', command, ...commandArgs])
|
||||||
|
assert.exists(res.envFile)
|
||||||
|
assert.isTrue(res.options!.silent)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user