-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
160 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,33 @@ | ||
const DeployCommand = require("./lib/commands/deploy.js"); | ||
const ParamCommand = require("./lib/commands/param.js"); | ||
const SetupCommand = require("./lib/commands/setup.js"); | ||
const StatusCommand = require("./lib/commands/status.js"); | ||
const OpsCommand = require("./lib/command"); | ||
const DeployCommand = require("./lib/commands/deploy"); | ||
const ParamCommand = require("./lib/commands/param"); | ||
const SetupCommand = require("./lib/commands/setup"); | ||
const StatusCommand = require("./lib/commands/status"); | ||
|
||
/** | ||
* I'm responsible for the infrastructure and governance side of Miles. | ||
*/ | ||
class OpsPlugin { | ||
/** | ||
* A brand new me. | ||
*/ | ||
constructor() {} | ||
const plugin = async function opsPluginStart(builder) { | ||
builder | ||
.register("plugin.ops.command.deploy", () => new DeployCommand()) | ||
.register("plugin.ops.command.param", () => new ParamCommand()) | ||
.register( | ||
"plugin.ops.command.setup", | ||
async (c) => await SetupCommand.create(c) | ||
) | ||
.register("plugin.ops.command.status", () => new StatusCommand()) | ||
.register("plugin.ops.command", async (c) => await OpsCommand.create(c), [ | ||
"commander-visitor", | ||
]); | ||
|
||
/** | ||
* When I wake up. | ||
*/ | ||
async init(miles) { | ||
this.miles = miles; | ||
} | ||
return { | ||
name: "Ops", | ||
version: "0.2.0", | ||
description: "Control a Miles deployment", | ||
author: "LibreWorks", | ||
}; | ||
}; | ||
|
||
/** | ||
* Set up commander. | ||
* | ||
* @param {commander.Command} program - The Commander instance. | ||
*/ | ||
addCommands(program) { | ||
let opsNestedCommand = program | ||
.command("ops") | ||
.description("Control a Miles deployment."); | ||
const commands = [DeployCommand, ParamCommand, SetupCommand, StatusCommand]; | ||
commands | ||
.map((clz) => new clz(this)) | ||
.forEach((cmd) => opsNestedCommand.addCommand(cmd.createCommand())); | ||
} | ||
} | ||
plugin.MILES_PLUGIN_API = 1; | ||
|
||
OpsPlugin.MILES_PLUGIN_API = 1; | ||
|
||
module.exports = OpsPlugin; | ||
module.exports = plugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const { Command } = require("commander"); | ||
|
||
const COMMANDS = Symbol("commands"); | ||
|
||
/** | ||
* Handles the `miles ops` command. | ||
*/ | ||
class OpsCommand { | ||
/** | ||
* @param {Object[]} commands - The nested commands. | ||
*/ | ||
constructor(commands) { | ||
this[COMMANDS] = commands; | ||
} | ||
|
||
/** | ||
* Factory function. | ||
* | ||
* @param {container.Container} container - The dependency injection container. | ||
* @return {OpsCommand} a new instance of this class. | ||
*/ | ||
static async create(container) { | ||
const commands = await container.getAll([ | ||
"plugin.ops.command.deploy", | ||
"plugin.ops.command.param", | ||
"plugin.ops.command.setup", | ||
"plugin.ops.command.status", | ||
]); | ||
return new OpsCommand(commands); | ||
} | ||
|
||
/** | ||
* Visits a Commander.js instance. | ||
* | ||
* @param {commander.Commander} program - The Commander.js instance. | ||
*/ | ||
visitCommander(program) { | ||
program.addCommand(this.createCommand()); | ||
} | ||
|
||
/** | ||
* Creates a Commander command. | ||
* | ||
* @return {commander.Command} the created Commander command. | ||
*/ | ||
createCommand() { | ||
const command = new Command("ops"); | ||
command.description("Control a Miles deployment."); | ||
for (const nestedCommand of this[COMMANDS]) { | ||
command.addCommand(nestedCommand.createCommand()); | ||
} | ||
return command; | ||
} | ||
} | ||
|
||
module.exports = OpsCommand; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.