43 lines
937 B
JavaScript
Executable File
43 lines
937 B
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const omelette = require('omelette');
|
|
const { Command } = require('commander');
|
|
const program = new Command();
|
|
|
|
scriptName = path.parse(process.argv[1]).base;
|
|
|
|
program
|
|
.name(scriptName)
|
|
.version('0.0.1')
|
|
.description('List packages of fake package manager');
|
|
|
|
|
|
// Write the CLI template.
|
|
const completion = omelette(`${scriptName} <actions> <user>`);
|
|
|
|
// Define new actions completion
|
|
completion.on('actions', ({ reply }) => {
|
|
reply(['firstCommand'])
|
|
})
|
|
|
|
completion.on('user', ({ reply }) => {
|
|
reply(fs.readdirSync('/Users/'))
|
|
})
|
|
|
|
program
|
|
.command('firstCommand')
|
|
.description('This is our first command')
|
|
.action(() => {
|
|
console.log('Fancy stuff happens here');
|
|
})
|
|
|
|
// Initialize the omelette and parse args
|
|
completion.init()
|
|
program.parse();
|
|
|
|
if (!Object.keys(program.opts()).length && !program.args.length) {
|
|
program.outputHelp();
|
|
}
|