1
- import { CommandModule } from "yargs" ;
2
1
import * as yargs from "yargs" ;
2
+ import { Commander } from "./commander" ;
3
3
4
- import * as defaultCmd from "./commands/default_cmd"
5
4
import { Parser } from "./parser" ;
6
5
import * as predefinedVariables from "./predefined_variables" ;
7
6
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
+
8
16
// Array polyfill
9
17
declare global {
10
18
// tslint:disable-next-line:interface-name
@@ -20,22 +28,42 @@ Array.prototype.first = function() {
20
28
return this [ 0 ] ;
21
29
} ;
22
30
23
- const a = yargs
31
+ const argv = yargs
24
32
. version ( "4.0.0" )
25
- . command ( defaultCmd as CommandModule )
33
+ . usage ( "\nUsage: $0 Run entire pipeline\nUsage: $0 [jobname] Run single job" )
26
34
. option ( "manual" , { type : "array" , description : "One or more manual jobs to run during a pipeline" , requiresArg : true } )
27
35
. option ( "list" , { type : "string" , description : "List jobs and job information" , requiresArg : false } )
28
36
. 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 ( ) ;
31
40
const pipelineIid = predefinedVariables . getPipelineIid ( cwd ) ;
32
41
const parser = new Parser ( cwd , pipelineIid ) ;
33
42
return parser . getJobNames ( ) ;
34
43
} )
44
+ . epilogue ( 'for more information, find our manual at http://github.com/firecow/' )
35
45
. argv ;
36
46
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