forked from tsai/budibase
4 changed files with 90 additions and 12 deletions
@ -1,7 +1,10 @@ |
|||||
exports.config = { |
const Option = require("../utils/Option") |
||||
short: "-h", |
|
||||
long: "hosting", |
|
||||
opts: ["init", "start", "stop", "update"], |
|
||||
} |
|
||||
|
|
||||
exports.addOption = () => {} |
const option = new Option("-h", "hosting") |
||||
|
.addHelp("Controls self hosting on the Budibase platform.") |
||||
|
.addSubOption("init", "Configure a self hosted platform in current directory.") |
||||
|
.addSubOption("start", "Start the configured platform in current directory.") |
||||
|
.addSubOption("stop", "Stop the configured platform in the current directory.") |
||||
|
.addSubOption("update", "Updates the Budibase images to the latest version.") |
||||
|
|
||||
|
exports.option = option |
||||
|
|||||
@ -1,8 +1,18 @@ |
|||||
const hosting = require("./hosting") |
const { getOptions, addHelp, displayHelp } = require("./options") |
||||
|
|
||||
const { Command } = require("commander") |
const { Command } = require("commander") |
||||
|
|
||||
const program = new Command() |
// add hosting config
|
||||
|
function init() { |
||||
program |
const program = new Command() |
||||
.option(hosting.Config.short, hosting.Config.) |
addHelp(program) |
||||
|
for (let option of getOptions()) { |
||||
|
option.configure(program) |
||||
|
} |
||||
|
program.parse(process.argv) |
||||
|
const userInput = program.opts() |
||||
|
for (let option of getOptions()) { |
||||
|
if (option.isItThisOption(userInput)) { |
||||
|
option.execute(userInput) |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|||||
@ -0,0 +1,13 @@ |
|||||
|
const hosting = require("./hosting") |
||||
|
|
||||
|
exports.getOptions = () => { |
||||
|
return [hosting.option] |
||||
|
} |
||||
|
|
||||
|
exports.addHelp = program => { |
||||
|
program.option("-h", "help") |
||||
|
} |
||||
|
|
||||
|
exports.displayHelp = () => { |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,52 @@ |
|||||
|
class Option { |
||||
|
constructor(short, long) { |
||||
|
this.short = short |
||||
|
this.long = long |
||||
|
this.opts = [] |
||||
|
} |
||||
|
|
||||
|
addHelp(help) { |
||||
|
this.help = help |
||||
|
return this |
||||
|
} |
||||
|
|
||||
|
addSubOption(command, help) { |
||||
|
this.opts.push({command, help}) |
||||
|
return this |
||||
|
} |
||||
|
|
||||
|
configure(program) { |
||||
|
if (this.opts.length !== 0) { |
||||
|
const opts = this.opts.map(opt => opt.command) |
||||
|
// add a help option to all sub-options
|
||||
|
if (opts.indexOf("help") === -1) { |
||||
|
opts.push("help") |
||||
|
} |
||||
|
program.option(this.short, this.long, opts) |
||||
|
} else { |
||||
|
program.option(this.short, this.long) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
getHelp() { |
||||
|
return this.help |
||||
|
} |
||||
|
|
||||
|
getSubOptions() { |
||||
|
if (this.opts) { |
||||
|
return [{command: "help", help: "Display help for this command."}].concat(this.opts) |
||||
|
} else { |
||||
|
return [] |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
isItThisOption(userInput) { |
||||
|
return !!userInput[this.long] |
||||
|
} |
||||
|
|
||||
|
execute(userInput) { |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
module.exports = Option |
||||
Loading…
Reference in new issue