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

Commit 4790ac7

Browse files
committed
add shell and version to top-level help
Fixes #689
1 parent 4eaef79 commit 4790ac7

File tree

9 files changed

+68
-29
lines changed

9 files changed

+68
-29
lines changed

app/content/js/usage-error.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ const format = message => {
125125
messageString = replWrappedAMessageString && message.message
126126

127127
const { command, docs, title, breadcrumb=title||command, header=`${docs}.`, example, detailedExample, sampleInputs,
128-
commandPrefix, available, parents=[], related, required, optional, oneof } = usage
128+
commandPrefix, commandPrefixNotNeeded,
129+
available, parents=[], related, required, optional, oneof } = usage
129130

130131
// the return value will be `result`; we will populate it with
131132
// those fields now; `body` is the flex-wrap portion of the
@@ -334,6 +335,9 @@ const format = message => {
334335
docsPart = span(docs),
335336
allowedPart = allowed && smaller(span(undefined))
336337

338+
// for repl.exec,
339+
const commandForExec = alias => `${commandPrefix && !commandPrefixNotNeeded ? commandPrefix + ' ' : ''}${alias}`
340+
337341
row.className = 'log-line entity'
338342
cmdCell.className = 'log-field'
339343
docsCell.className = 'log-field'
@@ -351,7 +355,7 @@ const format = message => {
351355
cmdPart = span(alias, 'clickable clickable-blatant'),
352356
dirPart = isDir && span('/')
353357

354-
cmdPart.onclick = () => repl.pexec(`${commandPrefix ? commandPrefix + ' ' : ''}${alias}`)
358+
cmdPart.onclick = () => repl.pexec(commandForExec(alias))
355359

356360
aliasesPart.appendChild(cmdCell)
357361
cmdCell.appendChild(cmdPart)
@@ -379,11 +383,12 @@ const format = message => {
379383
if (command) {
380384
cmdPart.classList.add('clickable')
381385
cmdPart.classList.add('clickable-blatant')
386+
if (!isDir) cmdPart.style.fontWeight = 'bold'
382387
cmdPart.onclick = () => {
383388
if (partial) {
384-
return repl.partial(`${commandPrefix ? commandPrefix + ' ' : ''}${command}${partial === true ? '' : ' ' + partial}`)
389+
return repl.partial(commandForExec(alias)(command) + `${partial === true ? '' : ' ' + partial}`)
385390
} else {
386-
return repl.pexec(`${commandPrefix ? commandPrefix + ' ' : ''}${command}`)
391+
return repl.pexec(commandForExec(command))
387392
}
388393
}
389394
}
@@ -442,7 +447,7 @@ const format = message => {
442447
}
443448
}
444449

445-
module.exports = function UsageError(message, extra, code=message.statusCode || message.code || 500) {
450+
module.exports = function UsageError(message, extra, code=(message && (message.statusCode || message.code)) || 500) {
446451
Error.captureStackTrace(this, this.constructor)
447452
this.name = this.constructor.name
448453
this.message = format(message)

app/headless.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ const prettyDom = (dom, logger=log, stream=process.stdout, _color, { columnWidth
272272
stream.write(' ')
273273
}
274274

275-
const extraColor = isHeader ? 'bold' : dom.hasStyle('fontWeight', 500) ? 'green' : dom.hasStyle('fontSize', '0.875em') ? 'gray' : _extraColor || 'reset',
275+
const extraColor = isHeader || dom.hasStyle('fontWeight', 'bold') ? 'bold' : dom.hasStyle('fontWeight', 500) ? 'green' : dom.hasStyle('fontSize', '0.875em') ? 'gray' : _extraColor || 'reset',
276276
colorCode = dom.hasStyle('color') || _color,
277277
color = colorMap[colorCode] || colorCode
278278
// debug('child', dom.nodeType)

app/plugins/admin/updater.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616

1717
const fs = require('fs'),
18-
rp = require('request-promise'),
1918
path = require('path'),
2019
exec = require('child_process').exec
2120

@@ -75,14 +74,15 @@ const notifyOfAvailableUpdatesVisually = changes => {
7574
* Wrap the given string in a div
7675
*
7776
*/
78-
const wrapInDiv = str => {
77+
const wrapInDiv = (str, tag='div') => {
7978
if (typeof str === 'string') {
80-
const div = document.createElement('div')
79+
const div = document.createElement(tag)
8180
div.innerText = str
8281
return div
8382

8483
} else {
85-
const pre = document.createElement('pre')
84+
const pre = document.createElement('div')
85+
pre.style.whiteSpace = 'pre-wrap'
8686

8787
str.forEach(line => {
8888
pre.appendChild(wrapInDiv(line))
@@ -158,11 +158,13 @@ const npmProcessResponse = (exec = 'npm', name, stdout) => {
158158
Current = header.indexOf('Current'),
159159
Wanted = header.indexOf('Wanted'),
160160
Location = header.indexOf(' Location')
161+
161162
return lines
162163
.filter(_ => _) // strip blank lines
163164
.map(line => line.substring(0, Location)) // strip last column
164165
.map(line => line.substring(0, Current + 'Current'.length) +
165-
line.substring(Wanted + 'Wanted'.length)) // strip Wanted column
166+
line.substring(Wanted + 'Wanted'.length)) // strip Wanted column
167+
.concat(' ')
166168
.concat('To update, run the following command from the terminal:')
167169
.concat(`${exec} update ${name} -g`)
168170
}

app/plugins/modules/activation-visualizations/usage.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ module.exports = {
5252
title: 'Activation visualizations',
5353
header: 'These commands will help you visualize your activations',
5454
example: 'visualize <command>',
55-
commandPrefix: '',
55+
commandPrefix: 'visualize',
56+
commandPrefixNotNeeded: true,
5657
available: [{ command: 'summary', docs: header.summary },
5758
{ command: 'timeline', docs: header.timeline },
5859
{ command: 'grid', docs: header.grid }],
@@ -61,6 +62,7 @@ module.exports = {
6162

6263
summary: {
6364
strict: 'summary',
65+
command: 'summary',
6466
nRowsInViewport,
6567
title: 'Summarize performance',
6668
header: '${header.summary}.',

app/plugins/ui/commands/help.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ debug('loading')
2121
* Respond with a top-level usage document
2222
*
2323
*/
24-
const help = (usage, docs) => (_1, _2, _3, { errors }) => {
24+
const help = (usage, docs) => (_1, _2, _3, { ui, errors }) => {
2525
if (usage) {
2626
// this will be our return value
2727
const topLevelUsage = {
@@ -34,12 +34,12 @@ const help = (usage, docs) => (_1, _2, _3, { errors }) => {
3434
// traverse the top-level usage documents, populating topLevelUsage.available
3535
for (let key in usage) {
3636
const { route, usage:model } = usage[key]
37-
if (model) {
37+
if (model && (ui.headless || !model.headlessOnly)) {
3838
topLevelUsage.available.push({
3939
label: route.substring(1),
40-
dir: true,
41-
command: model.commandPrefix,
42-
docs: model.title
40+
dir: model.available,
41+
command: model.commandPrefix || model.command, // either subtree or leaf command
42+
docs: model.command ? model.header : model.title // for leaf commands, print full header
4343
})
4444
}
4545
}

app/plugins/ui/commands/open-ui-from-terminal.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 IBM Corporation
2+
* Copyright 2017-18 IBM Corporation
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,7 +15,15 @@
1515
*/
1616

1717

18-
const docs = { docs: 'Open the visual shell', needsUI: true, fullscreen: false, noEcho: true, noHistory: true } // noEcho means don't echo the command if we came from headless
18+
const usage = {
19+
command: 'shell',
20+
title: 'Visual Shell',
21+
header: 'Open the visual shell',
22+
headlessOnly: true
23+
}
24+
25+
// noEcho means don't echo the command if we came from headless
26+
const docs = { usage, needsUI: true, fullscreen: false, noEcho: true, noHistory: true }
1927

2028
/**
2129
* This plugin allows opening the graphical shell from the terminal

app/plugins/ui/commands/shell.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@
1616

1717

1818
/**
19-
* This plugin introduces /shell, and a synonym !, which executes a
20-
* given shell command.
19+
* This plugin introduces !, which executes a given shell command.
2120
*
2221
*/
2322

2423
const shell = require('shelljs')
25-
const request = require('request-promise')
2624

2725
const doShell = (argv, options, execOptions) => new Promise((resolve, reject) => {
2826
if (argv.length < 2) {
@@ -137,23 +135,28 @@ const usage = {
137135
}
138136
}
139137

138+
/**
139+
* Register command handlers
140+
*
141+
*/
140142
module.exports = commandTree => {
143+
// commandTree.subtree('/!', { usage: usage.toplevel })
144+
141145
const shellFn = (_1, _2, fullArgv, _3, _4, execOptions, argv, options) => doShell(fullArgv, options, execOptions)
142146
const shellCmd = commandTree.listen('/!', shellFn, { docs: 'Execute a UNIX shell command' })
143-
// commandTree.synonym('/shell', shellFn, shellCmd)
144147

145-
commandTree.listen('/pwd', (_1, _2, fullArgv, _3, _4, execOptions, argv, options) => doShell(['!', 'pwd', ...argv.slice(1)], options, execOptions),
148+
commandTree.listen('/!/pwd', (_1, _2, fullArgv, _3, _4, execOptions, argv, options) => doShell(['!', 'pwd', ...argv.slice(1)], options, execOptions),
146149
{ docs: 'Print the current working directory' })
147150

148-
commandTree.listen('/lcd', (_1, _2, fullArgv, _3, _4, execOptions, argv, options) => doShell(['!', 'cd', ...argv.slice(1)], options, execOptions),
151+
commandTree.listen('/!/lcd', (_1, _2, fullArgv, _3, _4, execOptions, argv, options) => doShell(['!', 'cd', ...argv.slice(1)], options, execOptions),
149152
{ docs: 'Change the current working directory for future shell commands' })
150153

151-
commandTree.listen('/lls', (_1, _2, fullArgv, { errors }, _4, execOptions, argv, options) => {
154+
commandTree.listen('/!/lls', (_1, _2, fullArgv, { errors }, _4, execOptions, argv, options) => {
152155
return doShell(['!', 'ls', '-l', ...argv.slice(1)], options, Object.assign({}, execOptions, { nested: true }))
153156
.catch(message => { throw new errors.usage({ message, usage: usage.lls }) })
154157
}, { usage: usage.lls })
155158

156-
commandTree.listen('/lrm', (_1, _2, fullArgv, _3, _4, execOptions, argv, options) => doShell(['!', 'rm', ...argv.slice(1)], options, execOptions),
159+
commandTree.listen('/!/lrm', (_1, _2, fullArgv, _3, _4, execOptions, argv, options) => doShell(['!', 'rm', ...argv.slice(1)], options, execOptions),
157160
{ docs: 'Remove a file from your local filesystem' })
158161

159162
return {

app/plugins/welcome/about.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
*/
1616

1717
const debug = require('debug')('about')
18+
debug('loading')
19+
20+
const usage = require('./usage')
1821

1922
/**
2023
* The repl allows plugins to provide their own window, via the
@@ -67,7 +70,7 @@ const getVersion = () => {
6770
const reportVersion = (_1, _2, argv) => {
6871
debug('reportVersion')
6972

70-
const checkForUpdates = argv.find(_ => _ === '-u'),
73+
const checkForUpdates = argv.find(_ => _ === '-u' || _ === '--update-check'),
7174
version = getVersion()
7275

7376
if (!checkForUpdates) {
@@ -99,6 +102,7 @@ const reportVersion = (_1, _2, argv) => {
99102
// now we need to clear a newline see shell issue
100103
// #194
101104
console.log('')
105+
console.log('')
102106
}
103107
return updates
104108
}
@@ -126,7 +130,8 @@ module.exports = (commandTree, prequire) => {
126130
*/
127131
commandTree.listen('/version', // the command path
128132
reportVersion, // the command handler
129-
{ noAuthOk }) // the command options
133+
{ noAuthOk, // the command options
134+
usage: usage.version })
130135

131136
/**
132137
* Open a graphical window displaying more detail about the tool

app/plugins/welcome/usage.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"version": {
3+
"strict": "version",
4+
"command": "version",
5+
"title": "Version Information",
6+
"header": "Print the current version of the Shell",
7+
"example": "version",
8+
"optional": [
9+
{ "name": "--update-check", "alias": "-u",
10+
"docs": "also check for updates"
11+
}
12+
]
13+
}
14+
}

0 commit comments

Comments
 (0)