Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added support for shel completion

  • Loading branch information...
commit c843be3b34fbbde5e7dd13cfa945eee946f2e598 1 parent e7790cb
@davglass davglass authored
Showing with 46 additions and 2 deletions.
  1. +35 −1 bin/yogi.js
  2. +1 −0  lib/args.js
  3. +8 −0 lib/cmds/cdn.js
  4. +2 −1  package.json
View
36 bin/yogi.js
@@ -6,13 +6,47 @@ Code licensed under the BSD License:
http://yuilibrary.com/license/
*/
+var args = require('../lib/args');
+var complete = require('complete');
+
+var comp = {
+ program: 'yogi',
+ commands: {},
+ options: {
+ '--help': {},
+ '-h': {},
+ '--version': {},
+ '-v': {}
+ }
+};
+
+Object.keys(args.cmds).forEach(function(item) {
+ comp.commands[item] = {};
+ if (args.cmds[item].shell_complete) {
+ args.cmds[item].shell_complete.forEach(function(line) {
+ comp.commands[item][line] = {};
+ });
+ } else if (args.cmds[item].help) {
+ var help = args.cmds[item].help();
+ help.forEach(function(line) {
+ if (line.indexOf('--') === 0) {
+ line = line.split(' ')[0];
+ comp.commands[item][line] = {};
+ }
+ });
+ }
+});
+
+
+complete(comp);
+
var log = require('../lib/log');
var config = require('../lib/config');
-var args = require('../lib/args');
var which = require('which');
var spawn = require('win-spawn');
var path = require('path');
+
var options = args.parse();
config.init(options);
var version = require('../lib/cmds/version');
View
1  lib/args.js
@@ -54,6 +54,7 @@ var nopt = require('nopt'),
exports.known = known;
exports.shorts = shorts;
+exports.cmds = cmds;
exports.parse = function(args) {
args = args || process.argv;
View
8 lib/cmds/cdn.js
@@ -311,6 +311,14 @@ mods = {
print: function() {
log.info('valid commands: ' + Object.keys(this.cmds).join(' '));
},
+ shell_complete: [
+ 'request',
+ 'status',
+ 'waiting',
+ 'queue',
+ 'logs',
+ 'tags'
+ ],
help: function() {
return [
'cdn',
View
3  package.json
@@ -35,7 +35,8 @@
"git-travis": "~0.1.2",
"win-spawn": "*",
"which": "*",
- "ansispan": "https://github.com/davglass/ansispan/tarball/fixclosing"
+ "ansispan": "https://github.com/davglass/ansispan/tarball/fixclosing",
+ "complete": "*"
},
"scripts": {
"pretest": "jshint --config ./node_modules/yui-lint/jshint.json ./lib/*.js ./lib/*/*.js",
Please sign in to comment.
Something went wrong with that request. Please try again.