Skip to content

Commit

Permalink
Merge pull request #83 from maestro-framework/help-command
Browse files Browse the repository at this point in the history
Add a `help` command
  • Loading branch information
T-monius authored Aug 31, 2020
2 parents 67dad49 + 0a8f315 commit 964534a
Show file tree
Hide file tree
Showing 3 changed files with 239 additions and 33 deletions.
55 changes: 28 additions & 27 deletions bin/maestro.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,42 @@
const minimist = require("minimist");

const argv = minimist(process.argv.slice(2), {
boolean: ["force", "n"],
boolean: ["force", "n", "help"],
string: ["roles", "template"],
alias: {
f: "force",
t: "template",
h: "help",
},
default: {
roles: "",
},
});

const defaultMsg = `See man pages for commands:
maestro(1)
maestro-config(1)
maestro-deploy(1)
maestro-teardown(1)
maestro-new(1)
maestro-get-templates(1)`;

switch (argv._[0]) {
case "config":
require("../src/commands/config")();
break;
case "deploy":
require("../src/commands/deploy")();
break;
case "teardown":
require("../src/commands/teardown")(argv);
break;
case "new":
require("../src/commands/newProject")(argv);
break;
case "get-templates":
require("../src/commands/getTemplates")();
break;
default:
console.log(defaultMsg);
if (argv.help) {
require("../src/commands/help")(argv._[0]);
} else {
switch (argv._[0]) {
case "config":
require("../src/commands/config")();
break;
case "deploy":
require("../src/commands/deploy")();
break;
case "teardown":
require("../src/commands/teardown")(argv);
break;
case "new":
require("../src/commands/newProject")(argv);
break;
case "get-templates":
require("../src/commands/getTemplates")();
break;
case "help":
require("../src/commands/help")(argv._[1]);
break;
default:
require("../src/commands/help")();
break;
}
}
46 changes: 40 additions & 6 deletions doc/man/maestro-help.1
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ maestro \- display help information about maestro or maestro command
.B maestro
[\fIcommand\fR] \fB\-h\fR|\fB\-\-help\fR

.SH DESCRIPTION

.SH OPTIONS

.SH NOTES

.SH BUGS

.PP
Expand All @@ -30,6 +24,46 @@ the GitHub Issues page

.SH EXAMPLE

.SS Using the --help flag

.PP
This shows an example of running
.IR "maestro <subcommand> --help" .

.PP
.RS
.EX
$ \fBmaestro config --help\fR
maestro-config: \fImaestro config\fR
Set up or alter your Maestro configuration files.
Run \fImaestro config\fR to set the global config values of AWS account number and
region.
See manual page \fBmaestro-config(1)\fR for more information.
.EE
.RE

.SS Using the help subcommand

.PP
This shows an example of running
.IR "maestro help <subcommand>" .

.PP
.RS
.EX
$ \fBmaestro help config\fR
maestro-config: \fImaestro config\fR
Set up or alter your Maestro configuration files.
Run \fImaestro config\fR to set the global config values of AWS account number and
region.
See manual page \fBmaestro-config(1)\fR for more information.
.EE
.RE

.SH SEE ALSO

.BR maestro (1),
Expand Down
171 changes: 171 additions & 0 deletions src/commands/help.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
const codes = {
reset: "\033[m",
bold: "\033[1m",
faint: "\033[2m",
italic: "\033[3m",
underline: "\033[4m",
black: "\033[30m",
red: "\033[31m",
green: "\033[32m",
yellow: "\033[33m",
blue: "\033[34m",
magenta: "\033[35m",
cyan: "\033[36m",
white: "\033[37m",
};

const configMsg = `maestro-config: ${codes.italic + codes.blue}maestro config${
codes.reset
}
Set up or alter your Maestro configuration files.
Run ${codes.italic + codes.blue}maestro config${
codes.reset
} to set the global config values of AWS account number and
region.
See manual page ${codes.yellow + codes.bold}maestro-config(1)${
codes.reset
} for more information.`;

const deployMsg = `maestro-deploy: ${codes.italic + codes.blue}maestro deploy${
codes.reset
}
Deploy a full AWS Step Functions workflow with AWS Lambdas.
Run ${codes.italic + codes.blue}maestro deploy${
codes.reset
} inside a Maestro project to quickly deploy all the
project's resources including AWS IAM Roles, AWS Lambdas, and the AWS Step
Functions state machine.
See manual page ${codes.yellow + codes.bold}maestro-deploy(1)${
codes.reset
} for more information.`;

const teardownMsg = `maestro-teardown: ${
codes.italic + codes.blue
}maestro teardown${codes.reset} [${
codes.italic + codes.bold + codes.red
}options${codes.reset} ...]
Teardown an existing Maestro project.
Run ${codes.italic + codes.blue}maestro teardown${
codes.reset
} inside a Maestro project to quickly tear down all
the project's resources including AWS Lambdas, the AWS Step Functions state
machine, and optionally AWS IAM Roles.
Options:
-f, --force
Do not prompt for confirmation.
--roles ${codes.italic + codes.bold + codes.red}role1${codes.reset}[,${
codes.italic + codes.bold + codes.red
}role2${codes.reset}...],
--roles=${codes.italic + codes.bold + codes.red}role1${codes.reset}[,${
codes.italic + codes.bold + codes.red
}role2${codes.reset}...]
Specify the roles to be deleted in addition to the other resources.
See manual page ${codes.yellow + codes.bold}maestro-teardown(1)${
codes.reset
} for more information.`;

const newMsg = `maestro-new: ${codes.italic + codes.blue}maestro new ${
codes.reset
}[${codes.italic + codes.bold + codes.red}options ${codes.reset}...] ${
codes.bold + codes.red
}project_name${codes.reset}
Create a new Maestro project.
Run ${codes.italic + codes.blue}maestro new ${
codes.bold + codes.red
}project_name${codes.reset} to create a new maestro project with the
given project name.
When this command is executed a prompt is displayed listing all of the
available templates on which to base this new project.
Options:
-n, --no-template
Don't use a template for the new project.
-t ${codes.italic + codes.bold + codes.red}template_name${codes.reset},
--template ${codes.italic + codes.bold + codes.red}template_name${
codes.reset
},
--template=${codes.italic + codes.bold + codes.red}template_name${
codes.reset
}
Use a specific template for the new project.
See manual page ${codes.yellow + codes.bold}maestro-new(1)${
codes.reset
} for more information.`;

const getTemplatesMsg = `maestro-get-templates: ${
codes.italic + codes.blue
}maestro get-templates${codes.reset}
Fetch and install the default Maestro templates.
Run ${codes.italic + codes.blue}maestro get-templates${
codes.reset
} to fetch and install the default Maestro
templates from the ${codes.yellow}${
codes.green + codes.underline
}https://github.com/maestro-framework/maestro-templates${
codes.reset + codes.yellow
}${codes.reset}
git repository.
See manual page ${codes.yellow + codes.bold}maestro-get-templates(1)${
codes.reset
} for more information.`;

const helpMsg = `maestro-help: ${codes.italic + codes.blue}maestro help ${
codes.bold + codes.red
}command${codes.reset}
Display help about a specific Maestro command.
Run ${codes.italic + codes.blue}maestro help ${
codes.bold + codes.red
}command${codes.reset} to get help specific to a Maestro subcommand.
See manual page ${codes.yellow + codes.bold}maestro-help(1)${
codes.reset
} for more information.`;

const defaultMsg = `Run \`${codes.italic + codes.blue}maestro help ${
codes.bold + codes.red
}command${codes.reset}\` to get help specific to a subcommand.`;

const help = (command) => {
switch (command) {
case undefined:
console.log(defaultMsg);
break;
case "config":
console.log(configMsg);
break;
case "deploy":
console.log(deployMsg);
break;
case "teardown":
console.log(teardownMsg);
break;
case "new":
console.log(newMsg);
break;
case "get-templates":
console.log(getTemplatesMsg);
break;
case "help":
console.log(helpMsg);
break;
default:
console.log(defaultMsg);
break;
}
};

module.exports = help;

0 comments on commit 964534a

Please sign in to comment.