mirror of
https://github.com/slap-editor/slap.git
synced 2024-11-09 19:31:01 +03:00
Adds -h and --help
This commit is contained in:
parent
35518b033b
commit
4570f78935
36
lib/cli.js
36
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;
|
||||
|
Loading…
Reference in New Issue
Block a user