More work in progress.
This commit is contained in:
parent
a854fb2638
commit
e6c9b18304
|
@ -1,7 +1,10 @@
|
|||
exports.config = {
|
||||
short: "-h",
|
||||
long: "hosting",
|
||||
opts: ["init", "start", "stop", "update"],
|
||||
}
|
||||
const Option = require("../utils/Option")
|
||||
|
||||
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 program = new Command()
|
||||
|
||||
program
|
||||
.option(hosting.Config.short, hosting.Config.)
|
||||
// add hosting config
|
||||
function init() {
|
||||
const program = new Command()
|
||||
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