1- import { CommandModule } from "yargs" ;
21import * as yargs from "yargs" ;
2+ import { Commander } from "./commander" ;
33
4- import * as defaultCmd from "./commands/default_cmd"
54import { Parser } from "./parser" ;
65import * 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
917declare 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