@@ -134,7 +134,7 @@ const persisters = {
134134 const fs = require ( 'fs' ) ,
135135 tmp = require ( 'tmp' )
136136
137- tmp . file ( { prefix : 'shell-' , postfix : '.js' } , ( err , filepath , fd , cleanup ) => {
137+ tmp . file ( { prefix : 'shell-' , postfix : extension ( app . exec . kind ) } , ( err , filepath , fd , cleanup ) => {
138138 if ( err ) {
139139 reject ( err )
140140 } else {
@@ -143,7 +143,7 @@ const persisters = {
143143 reject ( err )
144144 } else {
145145 // -r means try to deploy the actions, too
146- return repl . qexec ( `app update "${ app . name } " "${ filepath } " -r` )
146+ return repl . qexec ( `app update "${ app . name } " "${ filepath } " -r --kind ${ app . exec . kind } ` )
147147 . then ( app => {
148148 cleanup ( )
149149 resolve ( app )
@@ -285,13 +285,29 @@ const tidy = ({wsk, getAction, editor, eventBus}) => ({
285285 */
286286const language = kind => {
287287 const base = kind . substring ( 0 , kind . indexOf ( ':' ) ) || kind
288+ debug ( 'language' , kind , base )
288289
289290 return base === 'nodejs'
290291 || base === 'app'
291292 || base === 'composition'
292293 || base === 'sequence' ? 'javascript' : base
293294}
294295
296+ /**
297+ * What is the filename extension for the given kind?
298+ *
299+ */
300+ const extension = kind => {
301+ const lang = language ( kind )
302+ debug ( 'extension' , kind , lang )
303+
304+ switch ( lang ) {
305+ case 'javascript' : return '.js'
306+ case 'python' : return '.py'
307+ default : return `.${ lang } ` // e.g. .swift, .php, .go
308+ }
309+ }
310+
295311/**
296312 * Update the code in the editor to use the given text
297313 *
@@ -555,6 +571,7 @@ const respondToRepl = (wsk, extraModes=[]) => ({ getAction, editor, content, eve
555571 content,
556572 controlHeaders : [ '.header-right-bits' ] ,
557573 displayOptions : [ `entity-is-${ getAction ( ) . type } ` , 'edit-mode' ] ,
574+ badges : [ language ( getAction ( ) . exec . kind ) ] ,
558575 modes : extraModes
559576 . map ( _ => _ ( { wsk, getAction, editor, eventBus} ) )
560577 . concat ( [ save ( { wsk, getAction, editor, eventBus} ) ,
@@ -610,10 +627,6 @@ const edit = (wsk, prequire) => (_0, _1, fullArgv, { ui, errors }, _2, _3, args,
610627 name = args [ args . indexOf ( 'edit' ) + 1 ]
611628 || ( sidecar . entity && `/${ sidecar . entity . namespace } /${ sidecar . entity . name } ` )
612629
613- if ( ! name || options . help ) {
614- throw new errors . usage ( usage . edit )
615- }
616-
617630 //
618631 // fetch the action and open the editor in parallel
619632 // then update the editor to show the action
@@ -644,19 +657,19 @@ const addVariantSuffix = kind => {
644657 * Command handler to create a new action or app
645658 *
646659 */
647- const newAction = ( { wsk, prequire, op= 'new' , type= 'actions' , _kind= defaults . kind , placeholder, persister= persisters . actions } ) => ( _0 , _1 , fullArgv , { ui, errors } , _2 , _3 , args , options ) => {
648- debug ( 'newAction' , op )
649-
660+ const newAction = ( { wsk, prequire, op= 'new' , type= 'actions' , _kind= defaults . kind , placeholder, placeholderFn, persister= persisters . actions } ) => ( _0 , _1 , fullArgv , { ui, errors } , _2 , _3 , args , options ) => {
650661 const name = args [ args . indexOf ( op ) + 1 ] ,
651- kind = addVariantSuffix ( options . kind || _kind )
662+ prettyKind = addVariantSuffix ( options . kind || _kind ) ,
663+ kind = addVariantSuffix ( options . kind || defaults . kind )
652664
653- if ( options . help || ! name ) {
654- throw new errors . usage ( usage [ op ] )
655- }
665+ debug ( 'newAction' , op , name , kind , prettyKind )
666+
667+ // create the initial, placeholder, source code to place in the editor
668+ const makePlaceholderCode = placeholderFn || ( ( ) => placeholder || placeholders [ language ( kind ) ] )
656669
657670 // our placeholder action
658671 const action = { name, type,
659- exec : { kind, code : placeholder || placeholders [ language ( kind ) ] } ,
672+ exec : { kind, prettyKind , code : makePlaceholderCode ( { kind} ) } ,
660673 isNew : true ,
661674 persister
662675 }
@@ -741,7 +754,7 @@ const addWskflow = prequire => opts => {
741754const compositionOptions = baseOptions => {
742755 return Object . assign ( { type : 'apps' ,
743756 _kind : 'app' ,
744- placeholder : placeholders . composition , // the placeholder impl
757+ placeholderFn : ( { kind = 'nodejs:default' } ) => placeholders . composition [ language ( kind ) ] , // the placeholder impl
745758 persister : persisters . apps , // the persister impl
746759 } , baseOptions )
747760}
0 commit comments