UNPKG

mib-cli

Version:

CLI tool to manage projects

58 lines (45 loc) 1.34 kB
const autoComplete = require('../../util/auto-complete'); const shell = require('shelljs'); module.exports = function (vorpal, options) { let self = this; const replaceMap = { 'recursive' : 'R', 'directory' : 'd', 'follow-symlink' : 'L', 'list' : 'l', 'all-files' : 'A' }; vorpal .command('ls [path]') .option('-A, --all-files', 'Include files begining with .') .option('-l, --list', 'List all files with their details') .option('-L, --follow-symlink', 'Follow links') .option('-R, --recursive', 'Go through all files and directory recursively') .option('-d, --directory', 'List the directory themselves, not their content') .autocomplete(autoComplete.getFromFs({directory: true})) .description('Change the current directoy') .action(function (args, callback) { let v = this; let options = ''; // Replace the parameters let keys = Object.keys(args.options); if (keys.length !== 0 ) { options += "-"; for (key in args.options) { if (replaceMap.hasOwnProperty(key)) options += replaceMap[key]; } } // Execute command files = shell.ls(options, args.path); // Log the results if(args.options.list) { files.forEach(function (file) { v.log(file.toString()); }); } else { v.log(files.join(' ')); } callback(); }); }