Skip to content

Commit

Permalink
Merge pull request #29 from entropitor/pr-25
Browse files Browse the repository at this point in the history
feat: add help
  • Loading branch information
entropitor authored Nov 20, 2019
2 parents b228362 + a2c8f18 commit b459968
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ var argv = require('minimist')(process.argv.slice(2))
var dotenv = require('dotenv')
var dotenvExpand = require('dotenv-expand')

function printHelp () {
console.log([
'Usage: dotenv [--help] [-e <path>] [-p <variable name>] [-- command]',
' --help print help',
' -e <path> parses the file <path> as a `.env` file and adds the variables to the environment',
' -e <path> multiple -e flags are allowed',
' -p <variable> print value of <variable> to the console. If you specify this, you do not have to specify a `command`',
' command `command` is the actual command you want to run. Best practice is to precede this command with ` -- `. Everything after `--` is considered to be your command. So any flags will not be parsed by this tool but be passed to your command. If you do not do it, this tool will strip those flags'
].join('\n'))
}

if (argv.help) {
printHelp()
process.exit()
}

var paths = ['.env']
if (argv.e) {
if (typeof argv.e === 'string') {
Expand All @@ -25,7 +41,13 @@ if (argv.p) {
process.exit()
}

spawn(argv._[0], argv._.slice(1), { stdio: 'inherit' })
var command = argv._[0]
if (!command) {
printHelp()
process.exit(1)
}

spawn(command, argv._.slice(1), { stdio: 'inherit' })
.on('exit', function (exitCode) {
process.exit(exitCode)
})

0 comments on commit b459968

Please sign in to comment.