diff --git a/lib/cli.js b/lib/cli.js index a0aef5e..0e7cb18 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -9,19 +9,45 @@ var logger = require('./logger'); var highlightClient = require('./highlight/client'); var baseDir = path.join(__dirname, '..'); -var packageName = require('../package').name; -var opts = util.parseOpts(rc(packageName, path.join(baseDir, packageName + '.ini'))); +var package = require('../package'); +var configFile = path.join(baseDir, package.name + '.ini'); +var opts = util.parseOpts(rc(package.name, configFile)); + +if (opts.h || opts.help) { + var command = process.argv[1]; + if (!process.env.PATH.split(path.delimiter).some(function (binPath) { + var newCommand = path.relative(binPath, command); + if (path.dirname(newCommand) === '.') { + command = newCommand; + return true; + } + })) { + command = path.relative(process.cwd(), command); + if (path.dirname(command) === '.') command = '.' + path.sep + command; + } + + console.error([ + "Usage: " + command + " [options...] [file]", + "", + package.description, + "", + "To see what options are available, run `" + command + " " + configFile + "`.", + "Example: `" + command + " --editor.tabSize 2 file.c`." + ].join("\n")); + + return process.exit(0); +} logger(opts.logger); highlightClient.send(_(opts.logger).merge({type: 'logger'}).toObject()); var slap = new Slap(opts); -var homeSlapRc = Slap.normalizePath('~/.slaprc'); +var homeRc = Slap.normalizePath('~/.' + package.name + 'rc'); if (opts._.length) { slap.open("" + opts._[0]).done(); -} else if (!fs.existsSync(homeSlapRc)) { +} else if (!fs.existsSync(homeRc)) { slap.open(path.join(baseDir, 'README.md')).done(); } -fs.openSync(homeSlapRc, 'a'); // touch +fs.openSync(homeRc, 'a'); // touch module.exports = slap;