[gjs: 3/5] added helpText for debugger commands
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 3/5] added helpText for debugger commands
- Date: Tue, 16 Apr 2019 03:05:41 +0000 (UTC)
commit 0846ada6a091398a78649df761da998a3129ea8e
Author: namnumr <nmanumr gmail com>
Date: Mon Apr 15 19:04:56 2019 -0700
added helpText for debugger commands
modules/_bootstrap/debugger.js | 130 ++++++++++++++++++++++++++++++++++++-----
1 file changed, 116 insertions(+), 14 deletions(-)
---
diff --git a/modules/_bootstrap/debugger.js b/modules/_bootstrap/debugger.js
index 4e7dca5a..38a3deeb 100644
--- a/modules/_bootstrap/debugger.js
+++ b/modules/_bootstrap/debugger.js
@@ -183,6 +183,8 @@ function quitCommand() {
quit(0);
}
quitCommand.summary = 'Quit the debugger';
+quitCommand.helpText = `USAGE
+ quit`;
function backtraceCommand() {
if (topFrame === null)
@@ -191,6 +193,8 @@ function backtraceCommand() {
showFrame(f, i);
}
backtraceCommand.summary = 'Print backtrace of all stack frames';
+backtraceCommand.helpText = `USAGE
+ bt`;
function setCommand(rest) {
var space = rest.indexOf(' ');
@@ -212,6 +216,13 @@ function setCommand(rest) {
}
}
setCommand.summary = 'Sets the value of the given option';
+setCommand.helpText = `USAGE
+ set <option> <value>
+
+PARAMETERS
+ · option: option name. Allowed options are:
+ · pretty: set print mode to pretty or brief. Allowed value true or false
+ · value: option value`;
function splitPrintOptions(s, style) {
const m = /^\/(\w+)/.exec(s);
@@ -252,17 +263,31 @@ function printCommand(rest) {
return doPrint(expr, style);
}
printCommand.summary = 'Prints the given expression';
+printCommand.helpText = `USAGE
+ print[/pretty|p|brief|b] <expr>
+
+PARAMETER
+ · expr: expression to be printed
+ · pretty|p: prettify the output
+ · brief|b: brief output`;
function keysCommand(rest) {
return doPrint(`Object.keys(${rest})`);
}
keysCommand.summary = 'Prints keys of the given object';
+keysCommand.helpText = `USAGE
+ keys <obj>
+
+PARAMETER
+ · obj: object to get keys of`;
function detachCommand() {
dbg.enabled = false;
return [undefined];
}
detachCommand.summary = 'Detach debugger from the script';
+detachCommand.helpText = `USAGE
+ detach`;
function continueCommand() {
if (focusedFrame === null) {
@@ -272,6 +297,8 @@ function continueCommand() {
return [undefined];
}
continueCommand.summary = 'Continue program execution';
+continueCommand.helpText = `USAGE
+ cont`;
function throwOrReturn(rest, action, defaultCompletion) {
if (focusedFrame !== topFrame) {
@@ -304,11 +331,21 @@ function throwCommand(rest) {
return throwOrReturn(rest, 'throw', {throw: lastExc});
}
throwCommand.summary = 'Throws the given value';
+throwCommand.helpText = `USAGE
+ throw <expr>
+
+PARAMETER
+ · expr: expression to throw`;
function returnCommand(rest) {
return throwOrReturn(rest, 'return', {return: undefined});
}
returnCommand.summary = 'Return the given value from the current frame';
+returnCommand.helpText = `USAGE
+ return <expr>
+
+PARAMETER
+ · expr: expression to return`;
function frameCommand(rest) {
let n, f;
@@ -340,6 +377,11 @@ function frameCommand(rest) {
}
}
frameCommand.summary = 'Jump to specified frame or print current frame (if not specified)';
+frameCommand.helpText = `USAGE
+ frame [frame_num]
+
+PARAMETER
+ · frame_num: frame to jump to`;
function upCommand() {
if (focusedFrame === null)
@@ -353,6 +395,8 @@ function upCommand() {
}
}
upCommand.summary = 'Jump to the parent frame';
+upCommand.helpText = `USAGE
+ up`;
function downCommand() {
if (focusedFrame === null)
@@ -365,6 +409,8 @@ function downCommand() {
}
}
downCommand.summary = 'Jump to the younger frame';
+downCommand.helpText = `USAGE
+ down`;
function printPop(c) {
if (c['return']) {
@@ -484,21 +530,32 @@ function stepCommand() {
return doStepOrNext({step: true});
}
stepCommand.summary = 'Step to next command';
+stepCommand.helpText = `USAGE
+ step`;
function nextCommand() {
return doStepOrNext({next: true});
}
nextCommand.summary = 'Jump to next line';
+nextCommand.helpText = `USAGE
+ next`;
function finishCommand() {
return doStepOrNext({finish: true});
}
finishCommand.summary = 'Run until the current frame is finished also prints the returned value';
+finishCommand.helpText = `USAGE
+ finish`;
function untilCommand(line) {
return doStepOrNext({until: true, stopLine: Number(line)});
}
untilCommand.summary = 'Continue until given line';
+untilCommand.helpText = `USAGE
+ until <line_num>
+
+PARAMETER
+ · line_num: line_num to continue until`;
function findBreakpointOffsets(line, currentScript) {
const offsets = currentScript.getLineOffsets(line);
@@ -555,6 +612,11 @@ function breakpointCommand(where) {
});
}
breakpointCommand.summary = 'Set breakpoint at the specified location.';
+breakpointCommand.helpText = `USAGE
+ break <line_num>
+
+PARAMETERS
+ · line_num: line number to place a breakpoint at.`;
function deleteCommand(breaknum) {
const bp = breakpoints[breaknum];
@@ -570,6 +632,11 @@ function deleteCommand(breaknum) {
print(`${bp} deleted`);
}
deleteCommand.summary = 'Deletes breakpoint';
+deleteCommand.helpText = `USAGE
+ del <breakpoint_num>
+
+PARAMETERS
+ · breakpoint_num: breakpoint number to be removed.`;
// Build the table of commands.
var commands = {};
@@ -607,7 +674,7 @@ for (var i = 0; i < commandArray.length; i++) {
currentCmd = commands[cmd.name.replace(/Command$/, '')] = cmd;
}
-function helpCommand() {
+function _printCommandsList() {
print('Available commands:');
var printcmd = function (group) {
@@ -615,7 +682,16 @@ function helpCommand() {
print(` ${group.map((c) => c.name).join(', ')} -- ${(summary || {}).summary}`);
};
- var group = [];
+ var cmdGroups = _groupCommands();
+
+ for (var group of cmdGroups) {
+ printcmd(group);
+ }
+}
+
+function _groupCommands() {
+ var groups = [];
+
for (var cmd of commandArray) {
// Don't print commands for debugging the debugger
if ([commentCommand, evalCommand].includes(cmd) ||
@@ -623,23 +699,49 @@ function helpCommand() {
continue;
if (typeof cmd === 'string') {
- group.push({
- name: cmd
- });
+ groups[groups.length - 1]['aliases'].push(cmd);
} else {
- if (group.length)
- printcmd(group);
-
- group = [{
- name: cmd.name.replace(/Command$/, ''),
+ groups.push({
summary: cmd.summary,
- helpText: cmd.helpText
- }];
+ helpText: cmd.helpText,
+ aliases: [cmd.name.replace(/Command$/, '')]
+ });
+ }
+ }
+ return groups;
+}
+
+function _printCommand(cmd) {
+ print(`${cmd.summary}\n\n${cmd.helpText}`);
+
+ if (cmd.aliases.length > 1) {
+ print('\nALIASES');
+ for (var alias of cmd.aliases) {
+ print(` · ${alias}`);
}
}
- printcmd(group);
}
-helpCommand.summary = 'List all the available commands';
+
+function helpCommand(cmd) {
+ if (!cmd) {
+ _printCommandsList();
+ } else {
+ var cmdGroups = _groupCommands();
+ var command = cmdGroups.find((c) => c.aliases.includes(cmd));
+
+ if (command && command.helpText) {
+ _printCommand(command);
+ } else {
+ print(`No help found for ${cmd} command`);
+ }
+ }
+}
+helpCommand.summary = 'Show help for the specified command else list all commands';
+helpCommand.helpText = `USAGE
+ help [command]
+
+PARAMETERS
+ · command: command to show help for`;
// Break cmd into two parts: its first word and everything else. If it begins
// with punctuation, treat that as a separate word. The first word is
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]