Skip to content

Commit

Permalink
feat: add help
Browse files Browse the repository at this point in the history
  • Loading branch information
andyburke authored and entropitor committed Nov 20, 2019
1 parent f7b3dc5 commit a2c8f18
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 @@ -24,7 +40,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 a2c8f18

Please sign in to comment.