Skip to content
Permalink
Browse files

feat(generic): add basic tab completion for top level commands

ISSUES CLOSED: #49
  • Loading branch information
MarshallOfSound committed Dec 31, 2016
1 parent 0063818 commit 30082bbf4bf0eb1ee06343e2319f46ea4a57f593
Showing with 47 additions and 25 deletions.
  1. +2 −0 package.json
  2. +45 −25 src/electron-forge.js
@@ -13,6 +13,7 @@
"precommit": "npm run lint",
"commit": "git-cz",
"docs": "esdoc",
"install": "tabtab install --auto",
"lint": "eslint src test gulpfile.babel.js",
"prepublish": "gulp build",
"pretest": "gulp build",
@@ -115,6 +116,7 @@
"semver": "^5.3.0",
"spawn-rx": "^2.0.7",
"sudo-prompt": "^6.2.1",
"tabtab": "^2.2.1",
"username": "^2.2.2",
"yarn-or-npm": "^2.0.2",
"zip-folder": "^1.0.0"
@@ -1,38 +1,58 @@
#!/usr/bin/env node
import 'colors';
import program from 'commander';
import tabtab from 'tabtab';

import './util/terminate';
import asyncOra from './util/ora-handler';
import checkSystem from './util/check-system';
import config from './util/config';

program
.version(require('../package.json').version)
.option('--verbose', 'Enables verbose mode')
.command('init', 'Initialize a new Electron application')
.command('import', 'Attempts to navigate you through the process of importing an existing project to "electron-forge"')
.command('lint', 'Lints the current Electron application')
.command('package', 'Package the current Electron application')
.command('make', 'Generate distributables for the current Electron application')
.command('start', 'Start the current Electron application')
.command('publish', 'Publish the current Electron application to GitHub')
.command('install', 'Install an Electron application from GitHub');

(async () => {
let goodSystem;
await asyncOra('Checking your system', async () => {
goodSystem = await checkSystem();
});

if (!goodSystem) {
console.error(('It looks like you are missing some dependencies you need to get Electron running.\n' +
'Make sure you have git installed and Node.js version 6.0.0+').red);
process.exit(1);
const tab = tabtab({
name: 'electron-forge',
});
tab.on('electron-forge', (data, done) => {
if (data.line.split(' ').length <= 2) {
done(
null,
program.commands
.filter(cmd => cmd._name.startsWith(data.lastPartial))
.map(cmd => `${cmd._name}:${cmd._description}`).sort()
);
} else {
done(null, []);
}
});
tab.start();

if (process.argv[2] !== 'completion') {
(async () => {
let goodSystem;
await asyncOra('Checking your system', async () => {
goodSystem = await checkSystem();
});

if (!goodSystem) {
console.error(('It looks like you are missing some dependencies you need to get Electron running.\n' +
'Make sure you have git installed and Node.js version 6.0.0+').red);
process.exit(1);
}

program
.version(require('../package.json').version)
.option('--verbose', 'Enables verbose mode')
.command('init', 'Initialize a new Electron application')
.command('import', 'Attempts to navigate you through the process of importing an existing project to "electron-forge"')
.command('lint', 'Lints the current Electron application')
.command('package', 'Package the current Electron application')
.command('make', 'Generate distributables for the current Electron application')
.command('start', 'Start the current Electron application')
.command('publish', 'Publish the current Electron application to GitHub')
.command('install', 'Install an Electron application from GitHub')
.parse(process.argv);
program.parse(process.argv);

config.reset();
config.set('verbose', !!program.verbose);
})();
config.reset();
config.set('verbose', !!program.verbose);
})();
}

0 comments on commit 30082bb

Please sign in to comment.
You can’t perform that action at this time.