@@ -6,9 +6,9 @@ const fs = require('fs');
6
6
/**
7
7
* yargs script generation file redone
8
8
* */
9
- function _generateCompletionScript ( appPath , appName , completionCommand ) {
9
+ function _generateCompletionScript ( appPath , appName , completionCommand , shell ) {
10
10
let script = fs . readFileSync (
11
- path . resolve ( __dirname , 'completion .sh.hbs' ) ,
11
+ path . resolve ( __dirname , ` ${ shell } .sh.hbs` ) ,
12
12
'utf-8' ,
13
13
) ;
14
14
const name = appName || path . basename ( appPath ) ;
@@ -20,7 +20,8 @@ function _generateCompletionScript(appPath, appName, completionCommand) {
20
20
21
21
const command = new Command ( {
22
22
root : true ,
23
- command : 'completion' ,
23
+ command : 'completion [shell-name]' ,
24
+ aliases : [ 'completions' ] ,
24
25
description : 'Generate codefresh completion' ,
25
26
usage : 'Prints completion script with specified or default path to executable and command alias' ,
26
27
webDocs : {
@@ -31,6 +32,11 @@ const command = new Command({
31
32
} ,
32
33
builder : ( yargs ) => {
33
34
return yargs
35
+ . positional ( 'shellName' , {
36
+ description : 'Name of the shell to generate completion for' ,
37
+ choices : [ 'bash' , 'zsh' ] ,
38
+ default : 'bash' ,
39
+ } )
34
40
. option ( 'executable' , {
35
41
alias : 'e' ,
36
42
description : 'Name or path to your codefresh executable (default same as alias)' ,
@@ -40,14 +46,18 @@ const command = new Command({
40
46
description : 'Alias used for calling codefresh executable' ,
41
47
default : 'codefresh' ,
42
48
} )
43
- . example ( 'codefresh completion' , 'Print completion script' )
49
+ . example ( 'codefresh completion' , 'Print bash completion script' )
50
+ . example ( 'codefresh completion zsh' , 'Print zsh completion script' )
51
+ . example ( 'codefresh completion zsh >> ~/.zshrc' , 'Install zsh completion script' )
52
+ . example ( 'codefresh completion bash >> ~/.bashrc' , 'Install bash completion script' )
53
+ . example ( 'codefresh completion bash >> ~/.bash_profile' , 'Install bash completion script (on OSX)' )
44
54
. example ( 'cf completion --alias cf' , 'Print completion script for codefresh aliased as "cf"' )
45
- . example ( '/some/path/codefresh completion -- e /some/path/codefresh' , 'Print completion script with specified path to codefresh executable' ) ;
55
+ . example ( '/some/path/codefresh completion -e /some/path/codefresh' , 'Print completion script with specified path to codefresh executable' ) ;
46
56
} ,
47
57
handler : async ( argv ) => {
48
- const { executable, alias : appName } = argv ;
58
+ const { executable, alias : appName , shellName } = argv ;
49
59
const appPath = executable || appName ;
50
- const script = _generateCompletionScript ( appPath , appName , 'completion' ) ;
60
+ const script = _generateCompletionScript ( appPath , appName , 'completion' , shellName ) ;
51
61
console . log ( script ) ;
52
62
} ,
53
63
} ) ;
0 commit comments