@@ -6,9 +6,9 @@ const fs = require('fs');
66/**
77 * yargs script generation file redone
88 * */
9- function _generateCompletionScript ( appPath , appName , completionCommand ) {
9+ function _generateCompletionScript ( appPath , appName , completionCommand , shell ) {
1010 let script = fs . readFileSync (
11- path . resolve ( __dirname , 'completion .sh.hbs' ) ,
11+ path . resolve ( __dirname , ` ${ shell } .sh.hbs` ) ,
1212 'utf-8' ,
1313 ) ;
1414 const name = appName || path . basename ( appPath ) ;
@@ -20,7 +20,8 @@ function _generateCompletionScript(appPath, appName, completionCommand) {
2020
2121const command = new Command ( {
2222 root : true ,
23- command : 'completion' ,
23+ command : 'completion [shell-name]' ,
24+ aliases : [ 'completions' ] ,
2425 description : 'Generate codefresh completion' ,
2526 usage : 'Prints completion script with specified or default path to executable and command alias' ,
2627 webDocs : {
@@ -31,6 +32,11 @@ const command = new Command({
3132 } ,
3233 builder : ( yargs ) => {
3334 return yargs
35+ . positional ( 'shellName' , {
36+ description : 'Name of the shell to generate completion for' ,
37+ choices : [ 'bash' , 'zsh' ] ,
38+ default : 'bash' ,
39+ } )
3440 . option ( 'executable' , {
3541 alias : 'e' ,
3642 description : 'Name or path to your codefresh executable (default same as alias)' ,
@@ -40,14 +46,18 @@ const command = new Command({
4046 description : 'Alias used for calling codefresh executable' ,
4147 default : 'codefresh' ,
4248 } )
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)' )
4454 . 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' ) ;
4656 } ,
4757 handler : async ( argv ) => {
48- const { executable, alias : appName } = argv ;
58+ const { executable, alias : appName , shellName } = argv ;
4959 const appPath = executable || appName ;
50- const script = _generateCompletionScript ( appPath , appName , 'completion' ) ;
60+ const script = _generateCompletionScript ( appPath , appName , 'completion' , shellName ) ;
5161 console . log ( script ) ;
5262 } ,
5363} ) ;
0 commit comments