Skip to content
This repository was archived by the owner on Dec 17, 2024. It is now read-only.

Commit 4eaef79

Browse files
committed
fix for @demos tab completion from inside asar bundle
Fixes #686
1 parent 202b736 commit 4eaef79

File tree

4 files changed

+75
-50
lines changed

4 files changed

+75
-50
lines changed

app/content/js/repl.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,11 @@ self.exec = (commandUntrimmed, execOptions) => {
647647
err = new modules.errors.usage({ message, usage })
648648
err.code = 499
649649
debug(message, args, parsedOptions, optional, argv) // args is argv with options stripped
650-
return ui.oops(block, nextBlock)(err)
650+
if (execOptions && execOptions.failWithUsage) {
651+
return err
652+
} else {
653+
return ui.oops(block, nextBlock)(err)
654+
}
651655

652656
} else if (match.boolean && typeof parsedOptions[optionalArg] !== 'boolean'
653657
|| (match.booleanOK && !(typeof parsedOptions[optionalArg] === 'boolean' || typeof parsedOptions[optionalArg] === 'string'))
@@ -670,7 +674,11 @@ self.exec = (commandUntrimmed, execOptions) => {
670674
error = new modules.errors.usage({ message, usage })
671675
debug(message, match)
672676
error.code = 498
673-
return ui.oops(block, nextBlock)(error)
677+
if (execOptions && execOptions.failWithUsage) {
678+
return error
679+
} else {
680+
return ui.oops(block, nextBlock)(error)
681+
}
674682
}
675683
}
676684
}
@@ -809,7 +817,9 @@ self.exec = (commandUntrimmed, execOptions) => {
809817
// indicate that the command was NOT successfuly completed
810818
evaluator.error(err)
811819

812-
if (!nested) {
820+
if (execOptions && execOptions.failWithUsage) {
821+
return err
822+
} else if (!nested) {
813823
ui.oops(block, nextBlock)(err)
814824
} else {
815825
throw err
@@ -818,7 +828,9 @@ self.exec = (commandUntrimmed, execOptions) => {
818828
})
819829
}
820830
} catch (e) {
821-
if (ui.headless) {
831+
if (execOptions && execOptions.failWithUsage) {
832+
return e
833+
} else if (ui.headless) {
822834
throw e
823835
}
824836

app/plugins/modules/composer/lib/usage.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ exports.create = command => ({
6161
*
6262
*/
6363
exports.invoke = {
64+
command: 'invoke',
6465
strict: 'invoke',
6566
title: 'Invoke composition',
6667
header: 'Invoke a given app and wait for its completion',

app/plugins/ui/commands/openwhisk-usage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ module.exports = {
125125
// ACTION CREATE
126126
{ command: 'create', docs: 'create a new action', strict: 'create',
127127
example: 'wsk action create <action> <sourceFile>',
128-
required: [{ name: 'name', docs: 'the name of your new action' }],
129-
optional: sourceFile.concat(actionMix),
128+
required: [{ name: 'name', docs: 'the name of your new action' }].concat(sourceFile),
129+
optional: actionMix,
130130
parents: context('action')
131131
},
132132
// ACTION UPDATE

app/plugins/ui/commands/tab-completion.js

Lines changed: 56 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ const fs = require('fs'),
2727
*
2828
*/
2929
const complete = (match, prompt, { temporaryContainer, partial=temporaryContainer.partial, dirname=temporaryContainer.dirname }) => {
30+
debug('completion', match, partial, dirname)
31+
3032
// in case match includes partial as a prefix
3133
const partialIdx = match.indexOf(partial),
3234
completion = partialIdx >= 0 ? match.substring(partialIdx + partial.length) : match
@@ -42,9 +44,11 @@ const complete = (match, prompt, { temporaryContainer, partial=temporaryContaine
4244
if (!err) {
4345
if (stats.isDirectory()) {
4446
// add a trailing slash if the dirname/match is a directory
47+
debug('complete as directory')
4548
prompt.value = prompt.value + completion + '/'
4649
} else {
4750
// otherwise, dirname/match is not a directory
51+
debug('complete as file')
4852
prompt.value = prompt.value + completion
4953
}
5054
} else {
@@ -54,8 +58,11 @@ const complete = (match, prompt, { temporaryContainer, partial=temporaryContaine
5458

5559
} else {
5660
// otherwise, just add the completion to the prompt
61+
debug('complete as file (alt)')
5762
prompt.value = prompt.value + completion
5863
}
64+
} else {
65+
debug('no completion string')
5966
}
6067
}
6168

@@ -265,54 +272,59 @@ const suggestLocalFile = (last, block, prompt, temporaryContainer, lastIdx) => {
265272
// dirname will "foo" in the above example; it
266273
// could also be that last is itself the name
267274
// of a directory
268-
const lastIsDir = last.charAt(last.length - 1) === '/'
269-
dirname = lastIsDir ? last : path.dirname(last)
275+
const lastIsDir = last.charAt(last.length - 1) === '/',
276+
dirname = lastIsDir ? last : path.dirname(last)
270277

278+
debug('suggest local file', dirname, last)
279+
271280
if (dirname) {
272-
fs.access(dirname, err => {
273-
if (!err) {
274-
// then dirname exists! now scan the directory so we can find matches
275-
fs.readdir(dirname, (err, files) => {
276-
if (!err) {
277-
const partial = path.basename(last),
278-
matches = files.filter(f => (lastIsDir || f.indexOf(partial) === 0)
279-
&& !f.endsWith('~') && !f.startsWith('.'))
280-
281-
if (matches.length === 1) {
282-
//
283-
// then there is one unique match, so autofill it now;
284-
// completion will be the bit we have to append to the current prompt.value
285-
//
286-
complete(matches[0], prompt, { temporaryContainer, partial, dirname })
287-
288-
} else if (matches.length > 1) {
289-
//
290-
// then there are multiple matches, present the choices
291-
//
292-
293-
// make a temporary div to house the completion options,
294-
// and attach it to the block that encloses the current prompt
295-
if (!temporaryContainer) {
296-
temporaryContainer = makeCompletionContainer(block, prompt, partial, dirname, lastIdx)
297-
}
281+
// then dirname exists! now scan the directory so we can find matches
282+
fs.readdir(dirname, (err, files) => {
283+
if (err) {
284+
debug('fs.readdir error', err)
285+
286+
} else {
287+
debug('fs.readdir success')
288+
289+
const partial = path.basename(last),
290+
matches = files.filter(f => (lastIsDir || f.indexOf(partial) === 0)
291+
&& !f.endsWith('~') && !f.startsWith('.'))
292+
293+
if (matches.length === 1) {
294+
//
295+
// then there is one unique match, so autofill it now;
296+
// completion will be the bit we have to append to the current prompt.value
297+
//
298+
debug('singleton file completion', matches[0])
299+
complete(matches[0], prompt, { temporaryContainer, partial, dirname })
300+
301+
} else if (matches.length > 1) {
302+
//
303+
// then there are multiple matches, present the choices
304+
//
305+
debug('multi file completion')
306+
307+
// make a temporary div to house the completion options,
308+
// and attach it to the block that encloses the current prompt
309+
if (!temporaryContainer) {
310+
temporaryContainer = makeCompletionContainer(block, prompt, partial, dirname, lastIdx)
311+
}
298312

299-
// add each match to that temporary div
300-
matches.forEach((match, idx) => {
301-
const { option, optionInner } = addSuggestion(temporaryContainer, partial, dirname, prompt)(match, idx)
313+
// add each match to that temporary div
314+
matches.forEach((match, idx) => {
315+
const { option, optionInner } = addSuggestion(temporaryContainer, partial, dirname, prompt)(match, idx)
302316

303-
// see if the match is a directory, so that we add a trailing slash
304-
fs.lstat(expandHomeDir(path.join(dirname, match)), (err, stats) => {
305-
if (!err && stats.isDirectory()) {
306-
optionInner.innerText = match + '/'
307-
} else {
308-
optionInner.innerText = match
309-
}
310-
option.setAttribute('data-value', option.innerText)
311-
})
312-
})
313-
}
314-
}
315-
})
317+
// see if the match is a directory, so that we add a trailing slash
318+
fs.lstat(expandHomeDir(path.join(dirname, match)), (err, stats) => {
319+
if (!err && stats.isDirectory()) {
320+
optionInner.innerText = match + '/'
321+
} else {
322+
optionInner.innerText = match
323+
}
324+
option.setAttribute('data-value', option.innerText)
325+
})
326+
})
327+
}
316328
}
317329
})
318330
}

0 commit comments

Comments
 (0)