Skip to content

Commit

Permalink
Merge pull request #43 from nfischer/preparse-all-commands
Browse files Browse the repository at this point in the history
Preparse all commands
  • Loading branch information
dthree committed Feb 28, 2016
2 parents 8b2d45c + 2bb4de2 commit e4a3d1b
Show file tree
Hide file tree
Showing 36 changed files with 113 additions and 22 deletions.
3 changes: 2 additions & 1 deletion dist/commands/alias.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var interfacer = require('./../util/interfacer');
var preparser = require('./../preparser');

var alias = {
exec: function exec(args, options) {
Expand Down Expand Up @@ -94,7 +95,7 @@ module.exports = function (vorpal) {
return alias;
}
vorpal.api.alias = alias;
vorpal.command('alias [name...]').option('-p', 'print all defined aliases in a reusable format').action(function (args, callback) {
vorpal.command('alias [name...]').parse(preparser).option('-p', 'print all defined aliases in a reusable format').action(function (args, callback) {
args.options = args.options || {};
args.options.vorpal = vorpal;
return interfacer.call(this, {
Expand Down
3 changes: 2 additions & 1 deletion dist/commands/boilerplate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var interfacer = require('./../util/interfacer');
var preparser = require('./../preparser');

/**
* This is a boilerplate for implementing a new command.
Expand Down Expand Up @@ -81,7 +82,7 @@ module.exports = function (vorpal) {
* descriptions should exactly emulate
* existing commands.
*/
vorpal.command('cmdName [files...]').option('-o, --option', 'option description').action(function (args, callback) {
vorpal.command('cmdName [files...]').parse(preparser).option('-o, --option', 'option description').action(function (args, callback) {
args.options = args.options || {};
/**
* The interfacer method does a
Expand Down
3 changes: 2 additions & 1 deletion dist/commands/cat.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var fsAutocomplete = require('vorpal-autocomplete-fs');

var fetch = require('./../util/fetch');
var interfacer = require('./../util/interfacer');
var preparser = require('./../preparser');
var lpad = require('./../util/lpad');
var strip = require('./../util/stripAnsi');

Expand Down Expand Up @@ -102,7 +103,7 @@ module.exports = function (vorpal) {
return cat;
}
vorpal.api.cat = cat;
vorpal.command('cat [files...]').option('-A, --show-all', 'equivalent to -vET').option('-b, --number-nonblank', 'number nonempty output lines, overrides -n').option('-e', 'equivalent to -vE').option('-E, --show-ends', 'display $ at end of each line').option('-n, --number', 'number all output lines').option('-s, --squeeze-blank', 'suppress repeated empty output lines').option('-t', 'equivalent to -vT').option('-T, --show-tabs', 'display TAB characters as ^I').option('-v, --show-nonprinting', 'use ^ and M- notation, except for LFD and TAB') // this doesn't work yet...
vorpal.command('cat [files...]').parse(preparser).option('-A, --show-all', 'equivalent to -vET').option('-b, --number-nonblank', 'number nonempty output lines, overrides -n').option('-e', 'equivalent to -vE').option('-E, --show-ends', 'display $ at end of each line').option('-n, --number', 'number all output lines').option('-s, --squeeze-blank', 'suppress repeated empty output lines').option('-t', 'equivalent to -vT').option('-T, --show-tabs', 'display TAB characters as ^I').option('-v, --show-nonprinting', 'use ^ and M- notation, except for LFD and TAB') // this doesn't work yet...
.autocomplete(fsAutocomplete()).action(function (args, cb) {
args.options = args.options || {};
return interfacer.call(this, {
Expand Down
3 changes: 2 additions & 1 deletion dist/commands/cd.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var fsAutocomplete = require('vorpal-autocomplete-fs');
var delimiter = require('./../delimiter');

var interfacer = require('./../util/interfacer');
var preparser = require('./../preparser');

var cd = {
exec: function exec(dir, options) {
Expand Down Expand Up @@ -46,7 +47,7 @@ module.exports = function (vorpal) {
return cd;
}
vorpal.api.cd = cd;
vorpal.command('cd [dir]').autocomplete(fsAutocomplete({ directory: true })).action(function (args, callback) {
vorpal.command('cd [dir]').parse(preparser).autocomplete(fsAutocomplete({ directory: true })).action(function (args, callback) {
args.options = args.options || {};
args.options.vorpal = vorpal;
return interfacer.call(this, {
Expand Down
3 changes: 2 additions & 1 deletion dist/commands/cp.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var os = require('os');

var expand = require('./../util/expand');
var interfacer = require('./../util/interfacer');
var preparser = require('./../preparser');

var cp = {
exec: function exec(args, options) {
Expand Down Expand Up @@ -194,7 +195,7 @@ module.exports = function (vorpal) {
return cp;
}
vorpal.api.cp = cp;
vorpal.command('cp [args...]').option('-f, --force', 'do not prompt before overwriting').option('-n, --no-clobber', 'do not overwrite an existing file').option('-r, --recursive', 'copy directories recursively').option('-R', 'copy directories recursively').autocomplete(fsAutocomplete()).action(function (args, callback) {
vorpal.command('cp [args...]').parse(preparser).option('-f, --force', 'do not prompt before overwriting').option('-n, --no-clobber', 'do not overwrite an existing file').option('-r, --recursive', 'copy directories recursively').option('-R', 'copy directories recursively').autocomplete(fsAutocomplete()).action(function (args, callback) {
args.options = args.options || {};
return interfacer.call(this, {
command: cp,
Expand Down
3 changes: 2 additions & 1 deletion dist/commands/kill.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var fkill = require('fkill');
var os = require('os');

var interfacer = require('./../util/interfacer');
var preparser = require('./../preparser');

var usage = 'kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]';
var windows = os.platform().indexOf('win') > -1;
Expand Down Expand Up @@ -83,7 +84,7 @@ module.exports = function (vorpal) {
return kill;
}
vorpal.api.kill = kill;
vorpal.command('kill [process...]').option('-9', 'sigkill').option('-s [sig]', 'sig is a signal name').option('-n [sig]', 'sig is a signal number').option('-l [sigspec]', 'list the signal names').action(function (args, callback) {
vorpal.command('kill [process...]').parse(preparser).option('-9', 'sigkill').option('-s [sig]', 'sig is a signal name').option('-n [sig]', 'sig is a signal number').option('-l [sigspec]', 'list the signal names').action(function (args, callback) {
args.options = args.options || {};
args.options.vorpal = vorpal;
return interfacer.call(this, {
Expand Down
3 changes: 2 additions & 1 deletion dist/commands/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var columnify = require('./../util/columnify');
var dateConverter = require('./../util/converter.date');
var fileFromPath = require('./../util/fileFromPath');
var interfacer = require('./../util/interfacer');
var preparser = require('./../preparser');
var pad = require('./../util/pad');
var lpad = require('./../util/lpad');
var permissionsConverter = require('./../util/converter.permissions');
Expand Down Expand Up @@ -345,7 +346,7 @@ module.exports = function (vorpal) {
return ls;
}
vorpal.api.ls = ls;
vorpal.command('ls [paths...]').option('-a, --all', 'do not ignore entries starting with .').option('-A, --almost-all', 'do not list implied . and ..').option('-d, --directory', 'list directory entries instead of contents, and do not dereference symbolic links').option('-F, --classify', 'append indicator (one of */=>@|) to entries').option('-h, --human-readable', 'with -l, print sizes in human readable format (e.g., 1K 234M 2G)').option('-i, --inode', 'print the index number of each file').option('-l', 'use a long listing format').option('-Q, --quote-name', 'enclose entry names in double quotes').option('-r, --reverse', 'reverse order while sorting').option('-R, --recursive', 'list subdirectories recursively').option('-S', 'sort by file size').option('-t', 'sort by modification time, newest first').option('-U', 'do not sort; list entries in directory order').option('-w, --width [COLS]', 'assume screen width instead of current value').option('-x', 'list entries by lines instead of columns').option('-1', 'list one file per line').autocomplete(fsAutocomplete()).action(function (args, cb) {
vorpal.command('ls [paths...]').parse(preparser).option('-a, --all', 'do not ignore entries starting with .').option('-A, --almost-all', 'do not list implied . and ..').option('-d, --directory', 'list directory entries instead of contents, and do not dereference symbolic links').option('-F, --classify', 'append indicator (one of */=>@|) to entries').option('-h, --human-readable', 'with -l, print sizes in human readable format (e.g., 1K 234M 2G)').option('-i, --inode', 'print the index number of each file').option('-l', 'use a long listing format').option('-Q, --quote-name', 'enclose entry names in double quotes').option('-r, --reverse', 'reverse order while sorting').option('-R, --recursive', 'list subdirectories recursively').option('-S', 'sort by file size').option('-t', 'sort by modification time, newest first').option('-U', 'do not sort; list entries in directory order').option('-w, --width [COLS]', 'assume screen width instead of current value').option('-x', 'list entries by lines instead of columns').option('-1', 'list one file per line').autocomplete(fsAutocomplete()).action(function (args, cb) {
return interfacer.call(this, {
command: ls,
args: args.paths,
Expand Down
3 changes: 2 additions & 1 deletion dist/commands/mkdir.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var path = require('path');
var fsAutocomplete = require('vorpal-autocomplete-fs');

var interfacer = require('./../util/interfacer');
var preparser = require('./../preparser');

var mkdir = {
exec: function exec(args, options) {
Expand Down Expand Up @@ -73,7 +74,7 @@ module.exports = function (vorpal) {
return mkdir;
}
vorpal.api.mkdir = mkdir;
vorpal.command('mkdir [directory...]').option('-p, --parents', 'no error if existing, make parent directories as needed').option('-v, --verbose', 'print a message for each created directory').autocomplete(fsAutocomplete({ directory: true })).action(function (args, callback) {
vorpal.command('mkdir [directory...]').parse(preparser).option('-p, --parents', 'no error if existing, make parent directories as needed').option('-v, --verbose', 'print a message for each created directory').autocomplete(fsAutocomplete({ directory: true })).action(function (args, callback) {
args.options = args.options || {};
args.options.vorpal = vorpal;
return interfacer.call(this, {
Expand Down
3 changes: 2 additions & 1 deletion dist/commands/mv.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var path = require('path');

var expand = require('./../util/expand');
var interfacer = require('./../util/interfacer');
var preparser = require('./../preparser');

var mv = {
exec: function exec(args, options) {
Expand Down Expand Up @@ -91,7 +92,7 @@ module.exports = function (vorpal) {
return mv;
}
vorpal.api.mv = mv;
vorpal.command('mv [args...]').option('-f, --force', 'do not prompt before overwriting').option('-n, --no-clobber', 'do not overwrite an existing file').option('--striptrailingslashes', 'remove any trailing slashes from each source') // vorpal bug, need to add dashes between words
vorpal.command('mv [args...]').parse(preparser).option('-f, --force', 'do not prompt before overwriting').option('-n, --no-clobber', 'do not overwrite an existing file').option('--striptrailingslashes', 'remove any trailing slashes from each source') // vorpal bug, need to add dashes between words
.option('-v, --verbose', 'explain what is being done').autocomplete(fsAutocomplete()).action(function (args, callback) {
args.options = args.options || {};
return interfacer.call(this, {
Expand Down
3 changes: 2 additions & 1 deletion dist/commands/rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var fsAutocomplete = require('vorpal-autocomplete-fs');

var expand = require('./../util/expand');
var interfacer = require('./../util/interfacer');
var preparser = require('./../preparser');
var unlinkSync = require('./../util/unlinkSync');

var rm = {
Expand Down Expand Up @@ -159,7 +160,7 @@ module.exports = function (vorpal) {
return rm;
}
vorpal.api.rm = rm;
vorpal.command('rm [files...]').option('-f, --force', 'ignore nonexistent files and arguments, never prompt').option('-r, --recursive', 'remove directories and their contents recursively').option('-R', 'remove directories and their contents recursively').autocomplete(fsAutocomplete()).action(function (args, callback) {
vorpal.command('rm [files...]').parse(preparser).option('-f, --force', 'ignore nonexistent files and arguments, never prompt').option('-r, --recursive', 'remove directories and their contents recursively').option('-R', 'remove directories and their contents recursively').autocomplete(fsAutocomplete()).action(function (args, callback) {
args.options = args.options || {};
return interfacer.call(this, {
command: rm,
Expand Down
3 changes: 2 additions & 1 deletion dist/commands/sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var fsAutocomplete = require('vorpal-autocomplete-fs');

var fetch = require('./../util/fetch');
var interfacer = require('./../util/interfacer');
var preparser = require('./../preparser');
var strip = require('./../util/stripAnsi');
var shuffle = require('array-shuffle');

Expand Down Expand Up @@ -244,7 +245,7 @@ module.exports = function (vorpal) {
return sort;
}
vorpal.api.sort = sort;
vorpal.command('sort [files...]').option('-M, --month-sort', 'compare (unknown) < \'JAN\' < ... < \'DEC\'').option('-h, --human-numeric-sort', 'compare human readable numbers (e.g., 2K 1G)').option('-n, --numeric-sort', 'compare according to string numerical value').option('-R, --random-sort', 'sort by random hash of keys').option('-r, --reverse', 'reverse the result of comparisons').option('-c, --check', 'check for sorted input; do not sort').option('-o, --output [file]', 'write result to file instead of standard output').autocomplete(fsAutocomplete()).action(function (args, callback) {
vorpal.command('sort [files...]').parse(preparser).option('-M, --month-sort', 'compare (unknown) < \'JAN\' < ... < \'DEC\'').option('-h, --human-numeric-sort', 'compare human readable numbers (e.g., 2K 1G)').option('-n, --numeric-sort', 'compare according to string numerical value').option('-R, --random-sort', 'sort by random hash of keys').option('-r, --reverse', 'reverse the result of comparisons').option('-c, --check', 'check for sorted input; do not sort').option('-o, --output [file]', 'write result to file instead of standard output').autocomplete(fsAutocomplete()).action(function (args, callback) {
args.options = args.options || {};
return interfacer.call(this, {
command: sort,
Expand Down
3 changes: 2 additions & 1 deletion dist/commands/touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var fs = require('fs-extra');
var fsAutocomplete = require('vorpal-autocomplete-fs');

var interfacer = require('./../util/interfacer');
var preparser = require('./../preparser');
require('./../lib/sugar');

var touch = {
Expand Down Expand Up @@ -141,7 +142,7 @@ module.exports = function (vorpal) {
return touch;
}
vorpal.api.touch = touch;
vorpal.command('touch <files...>').option('-a', 'change only the access time').option('-c, --no-create', 'do not create any files').option('-d, --date [STRING]', 'parse STRING and use it instead of current time').option('-m', 'change only the modification time').option('-r, --reference [FILE]', 'use this file\'s times instead of current time').option('--time [WORD]', 'change the specified time: WORD is access, atime, or use: equivalent to -a WORD is modify or mtime: equivalent to -m').autocomplete(fsAutocomplete()).action(function (args, callback) {
vorpal.command('touch <files...>').parse(preparser).option('-a', 'change only the access time').option('-c, --no-create', 'do not create any files').option('-d, --date [STRING]', 'parse STRING and use it instead of current time').option('-m', 'change only the modification time').option('-r, --reference [FILE]', 'use this file\'s times instead of current time').option('--time [WORD]', 'change the specified time: WORD is access, atime, or use: equivalent to -a WORD is modify or mtime: equivalent to -m').autocomplete(fsAutocomplete()).action(function (args, callback) {
return interfacer.call(this, {
command: touch,
args: args.files || [],
Expand Down
3 changes: 2 additions & 1 deletion dist/commands/unalias.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var interfacer = require('./../util/interfacer');
var preparser = require('./../preparser');

var unalias = {
exec: function exec(args, options) {
Expand Down Expand Up @@ -85,7 +86,7 @@ module.exports = function (vorpal) {
return unalias;
}
vorpal.api.unalias = unalias;
vorpal.command('unalias [name...]').option('-a', 'remove all alias definitions').action(function (args, callback) {
vorpal.command('unalias [name...]').parse(preparser).option('-a', 'remove all alias definitions').action(function (args, callback) {
args.options = args.options || {};
args.options.vorpal = vorpal;
return interfacer.call(this, {
Expand Down
3 changes: 2 additions & 1 deletion packages/cat/dist/commands/cat.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var fsAutocomplete = require('vorpal-autocomplete-fs');

var fetch = require('./../util/fetch');
var interfacer = require('./../util/interfacer');
var preparser = require('./../preparser');
var lpad = require('./../util/lpad');
var strip = require('./../util/stripAnsi');

Expand Down Expand Up @@ -102,7 +103,7 @@ module.exports = function (vorpal) {
return cat;
}
vorpal.api.cat = cat;
vorpal.command('cat [files...]').option('-A, --show-all', 'equivalent to -vET').option('-b, --number-nonblank', 'number nonempty output lines, overrides -n').option('-e', 'equivalent to -vE').option('-E, --show-ends', 'display $ at end of each line').option('-n, --number', 'number all output lines').option('-s, --squeeze-blank', 'suppress repeated empty output lines').option('-t', 'equivalent to -vT').option('-T, --show-tabs', 'display TAB characters as ^I').option('-v, --show-nonprinting', 'use ^ and M- notation, except for LFD and TAB') // this doesn't work yet...
vorpal.command('cat [files...]').parse(preparser).option('-A, --show-all', 'equivalent to -vET').option('-b, --number-nonblank', 'number nonempty output lines, overrides -n').option('-e', 'equivalent to -vE').option('-E, --show-ends', 'display $ at end of each line').option('-n, --number', 'number all output lines').option('-s, --squeeze-blank', 'suppress repeated empty output lines').option('-t', 'equivalent to -vT').option('-T, --show-tabs', 'display TAB characters as ^I').option('-v, --show-nonprinting', 'use ^ and M- notation, except for LFD and TAB') // this doesn't work yet...
.autocomplete(fsAutocomplete()).action(function (args, cb) {
args.options = args.options || {};
return interfacer.call(this, {
Expand Down
3 changes: 2 additions & 1 deletion packages/cp/dist/commands/cp.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var os = require('os');

var expand = require('./../util/expand');
var interfacer = require('./../util/interfacer');
var preparser = require('./../preparser');

var cp = {
exec: function exec(args, options) {
Expand Down Expand Up @@ -194,7 +195,7 @@ module.exports = function (vorpal) {
return cp;
}
vorpal.api.cp = cp;
vorpal.command('cp [args...]').option('-f, --force', 'do not prompt before overwriting').option('-n, --no-clobber', 'do not overwrite an existing file').option('-r, --recursive', 'copy directories recursively').option('-R', 'copy directories recursively').autocomplete(fsAutocomplete()).action(function (args, callback) {
vorpal.command('cp [args...]').parse(preparser).option('-f, --force', 'do not prompt before overwriting').option('-n, --no-clobber', 'do not overwrite an existing file').option('-r, --recursive', 'copy directories recursively').option('-R', 'copy directories recursively').autocomplete(fsAutocomplete()).action(function (args, callback) {
args.options = args.options || {};
return interfacer.call(this, {
command: cp,
Expand Down
3 changes: 2 additions & 1 deletion packages/kill/dist/commands/kill.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var fkill = require('fkill');
var os = require('os');

var interfacer = require('./../util/interfacer');
var preparser = require('./../preparser');

var usage = 'kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]';
var windows = os.platform().indexOf('win') > -1;
Expand Down Expand Up @@ -83,7 +84,7 @@ module.exports = function (vorpal) {
return kill;
}
vorpal.api.kill = kill;
vorpal.command('kill [process...]').option('-9', 'sigkill').option('-s [sig]', 'sig is a signal name').option('-n [sig]', 'sig is a signal number').option('-l [sigspec]', 'list the signal names').action(function (args, callback) {
vorpal.command('kill [process...]').parse(preparser).option('-9', 'sigkill').option('-s [sig]', 'sig is a signal name').option('-n [sig]', 'sig is a signal number').option('-l [sigspec]', 'list the signal names').action(function (args, callback) {
args.options = args.options || {};
args.options.vorpal = vorpal;
return interfacer.call(this, {
Expand Down

0 comments on commit e4a3d1b

Please sign in to comment.