diff --git a/cli.js b/cli.js index 158fb12..c5028a8 100755 --- a/cli.js +++ b/cli.js @@ -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 ] [-p ] [-- command]', + ' --help print help', + ' -e parses the file as a `.env` file and adds the variables to the environment', + ' -e multiple -e flags are allowed', + ' -p print value of 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') { @@ -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) })