Skip to content

Commit ba96776

Browse files
committed
Made help page pretty, and added --completion option
1 parent 4a58157 commit ba96776

File tree

3 files changed

+39
-52
lines changed

3 files changed

+39
-52
lines changed

src/commands/default_cmd.ts

-29
This file was deleted.

src/commands/list_cmd.ts

-12
This file was deleted.

src/index.ts

+39-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
import {CommandModule} from "yargs";
21
import * as yargs from "yargs";
2+
import {Commander} from "./commander";
33

4-
import * as defaultCmd from "./commands/default_cmd"
54
import {Parser} from "./parser";
65
import * as predefinedVariables from "./predefined_variables";
76

7+
process.on('uncaughtException', (err) => {
8+
process.stderr.write(`${err.stack ? err.stack : err}\n`);
9+
process.exit(5);
10+
});
11+
process.on('unhandledRejection', (reason) => {
12+
process.stderr.write(`${reason}\n`);
13+
process.exit(5);
14+
});
15+
816
// Array polyfill
917
declare global {
1018
// tslint:disable-next-line:interface-name
@@ -20,22 +28,42 @@ Array.prototype.first = function() {
2028
return this[0];
2129
};
2230

23-
const a = yargs
31+
const argv = yargs
2432
.version("4.0.0")
25-
.command(defaultCmd as CommandModule)
33+
.usage("\nUsage: $0 Run entire pipeline\nUsage: $0 [jobname] Run single job")
2634
.option("manual", {type: "array", description: "One or more manual jobs to run during a pipeline", requiresArg: true})
2735
.option("list", {type: "string", description: "List jobs and job information", requiresArg: false})
2836
.option("cwd", {type: "string", description: "Path to a gitlab-ci.yml", requiresArg: true})
29-
.completion('', async (current, argv) => {
30-
const cwd = argv.cwd as string || process.cwd();
37+
.option("completion", {type: "string", description: "Generate bash completion script", requiresArg: false})
38+
.completion("completion", false, async (current, a) => {
39+
const cwd = a.cwd as string || process.cwd();
3140
const pipelineIid = predefinedVariables.getPipelineIid(cwd);
3241
const parser = new Parser(cwd, pipelineIid);
3342
return parser.getJobNames();
3443
})
44+
.epilogue('for more information, find our manual at http://github.com/firecow/')
3545
.argv;
3646

37-
process.on("uncaughtException", (err) => {
38-
// Handle the error safely
39-
process.stderr.write(`${err.stack ? err.stack : err}\n`);
40-
process.exit(5);
41-
});
47+
(async() => {
48+
const cwd = argv.cwd as string || process.cwd();
49+
const pipelineIid = predefinedVariables.getPipelineIid(cwd);
50+
const parser = new Parser(cwd, pipelineIid);
51+
52+
if (argv.completion !== undefined) {
53+
yargs.showCompletionScript();
54+
return;
55+
}
56+
57+
if (argv.list !== undefined) {
58+
await Commander.runList(parser);
59+
return;
60+
}
61+
62+
if (argv._.length > 0) {
63+
await Commander.runSingleJob(parser, argv._[0] as string);
64+
} else {
65+
predefinedVariables.incrementPipelineIid(cwd);
66+
await Commander.runPipeline(parser, argv.manual as string[] || []);
67+
}
68+
})();
69+

0 commit comments

Comments
 (0)