提交 1d24e701 编写于 作者: D Daniel Imms

Remove yargs, roll own arg parser

上级 aedd9ecd
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
"native-keymap": "^0.1.2", "native-keymap": "^0.1.2",
"weak": "^1.0.1", "weak": "^1.0.1",
"winreg": "0.0.12", "winreg": "0.0.12",
"yargs": "^3.32.0",
"yauzl": "^2.3.1" "yauzl": "^2.3.1"
}, },
"devDependencies": { "devDependencies": {
......
...@@ -8,27 +8,38 @@ ...@@ -8,27 +8,38 @@
var packageJson = require('../../../package.json'); var packageJson = require('../../../package.json');
var os = require('os'); var os = require('os');
var spawn = require('child_process').spawn; var spawn = require('child_process').spawn;
var yargs = require('yargs');
function parseArgs() { function ArgParser(args) {
this.args = args;
}
ArgParser.prototype.hasFlag = function (flag, alias) {
return (flag && this.args.indexOf('--' + flag) >= 0) ||
(alias && this.args.indexOf('-' + alias) >= 0);
}
ArgParser.prototype.printHelp = function () {
var executable = 'code' + (os.platform() == 'win32' ? '.exe' : ''); var executable = 'code' + (os.platform() == 'win32' ? '.exe' : '');
var options = yargs(process.argv.slice(1)); console.log(
options.usage(
'Visual Studio Code v' + packageJson.version + '\n' + 'Visual Studio Code v' + packageJson.version + '\n' +
'\n' + '\n' +
'Usage: ' + executable + ' [arguments] [path]'); 'Usage: ' + executable + ' [arguments] [paths...]\n' +
options.alias('h', 'help').boolean('h').describe('h', 'Print usage.'); '\n' +
options.string('locale').describe('locale', 'Use a specific locale.'); 'Options:\n' +
options.boolean('n').describe('n', 'Force a new instance of code.'); ' -h, --help Print usage.\n' +
options.alias('v', 'version').boolean('v').describe('v', 'Print version.'); ' --locale Use a specific locale.\n' +
' -n Force a new instance of code.\n' +
var args = options.argv; ' -v, --version Print version.');
if (args.help) { }
process.stdout.write(options.help());
function parseArgs() {
var argParser = new ArgParser(process.argv.slice(2));
if (argParser.hasFlag('help', 'h')) {
argParser.printHelp();
process.exit(0); process.exit(0);
} }
if (args.version) { if (argParser.hasFlag('version', 'v')) {
process.stdout.write(packageJson.version + '\n'); console.log(packageJson.version);
process.exit(0); process.exit(0);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册