Skip to content

Commit

Permalink
Made help page pretty, and added --completion option
Browse files Browse the repository at this point in the history
  • Loading branch information
firecow committed May 1, 2020
1 parent 4a58157 commit ba96776
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 52 deletions.
29 changes: 0 additions & 29 deletions src/commands/default_cmd.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/commands/list_cmd.ts

This file was deleted.

50 changes: 39 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import {CommandModule} from "yargs";
import * as yargs from "yargs";
import {Commander} from "./commander";

import * as defaultCmd from "./commands/default_cmd"
import {Parser} from "./parser";
import * as predefinedVariables from "./predefined_variables";

process.on('uncaughtException', (err) => {
process.stderr.write(`${err.stack ? err.stack : err}\n`);
process.exit(5);
});
process.on('unhandledRejection', (reason) => {
process.stderr.write(`${reason}\n`);
process.exit(5);
});

// Array polyfill
declare global {
// tslint:disable-next-line:interface-name
Expand All @@ -20,22 +28,42 @@ Array.prototype.first = function() {
return this[0];
};

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

process.on("uncaughtException", (err) => {
// Handle the error safely
process.stderr.write(`${err.stack ? err.stack : err}\n`);
process.exit(5);
});
(async() => {
const cwd = argv.cwd as string || process.cwd();
const pipelineIid = predefinedVariables.getPipelineIid(cwd);
const parser = new Parser(cwd, pipelineIid);

if (argv.completion !== undefined) {
yargs.showCompletionScript();
return;
}

if (argv.list !== undefined) {
await Commander.runList(parser);
return;
}

if (argv._.length > 0) {
await Commander.runSingleJob(parser, argv._[0] as string);
} else {
predefinedVariables.incrementPipelineIid(cwd);
await Commander.runPipeline(parser, argv.manual as string[] || []);
}
})();

0 comments on commit ba96776

Please sign in to comment.