Monday, January 16, 2017

The Node-Solid-server help menu

Theory: The behavior:

$ solid

Usage: solid [options] [command]

Commands:

init [options] create solid server configurations
start [options] run the Solid server

Options:

-h, --help output usage information
-V, --version output the version number

Is due to:

https://github.com/solid/node-solid-server/blob/master/bin/solid.js

The key is the command line argument is sent to a node module called commander (https://www.npmjs.com/package/commander) .

The help() is automated, and it is triggered by no command options or parameters. The code that does this:

program.parse(process.argv)
if (program.args.length === 0) program.help()

Code that prints the description of the commands init and start is the .description method in the referenced files.

var loadInit = require('./lib/init')
var loadStart = require('./lib/start')

and

loadInit(program)
loadStart(program)

init.js (https://github.com/solid/node-solid-server/blob/master/bin/lib/init.js)

module.exports = function (program) {
program
.command('init')
.option('--advanced', 'Ask for all the settings')
.description('create solid server configurations')
.action((opts) => {
// Filter out advanced commands
if (!opts.advanced) {
questions = questions.filter((option) => option.prompt)
}

start.js (https://github.com/solid/node-solid-server/blob/master/bin/lib/start.js)

module.exports = function (program) {
const start = program
.command('start')
.description('run the Solid server')

solid start options dumps the options array.

In ./lib/start.js (https://github.com/solid/node-solid-server/blob/master/bin/lib/start.js) .

const options = require('./options')

options
.filter((option) => !option.hide)
.forEach((option) => {
var name = '--' + option.name
if (!option.flag) {
name += ' [value]'
}
start.option(name, option.help)
})

See: (https://github.com/solid/node-solid-server/blob/master/bin/lib/options.js)

No comments:

Post a Comment