Skip to content

Commit

Permalink
Add help from Servershell plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
kofrezo committed Mar 13, 2024
1 parent a4cb315 commit 1939760
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions serveradmin/servershell/static/js/servershell/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ function validate_selected(min=1, max=-1) {
return true;
}

// Servershell plugins can add help for their commands here.
servershell.commands_help = [
// Example:
// {
// "command": "foo",
// "arguments": "attr_name",
// "description": "A foo that bars",
// }
]

servershell.commands = {
pin: function() {
let selected_ids = servershell.get_selected();
Expand Down Expand Up @@ -770,7 +780,23 @@ function execute_command() {
}

$(document).ready(function() {
$('#command_form').submit(function(event) {

// Collect help description from Servershell plugins and add them to the
// help modal.
servershell.commands_help.forEach(function(command_help) {
let row = document.createElement("tr");
row.id = `cmd-${command_help["command"]}`;

for (let index of ["command", "arguments", "description"]) {
let cell = document.createElement("td");
cell.innerText = command_help[index];
row.appendChild(cell);
}

$("#help_command").append(row);
});

$('#command_form').submit(function(event) {
event.preventDefault();

// Workaround:
Expand All @@ -786,5 +812,5 @@ $(document).ready(function() {
if (execute_command()) {
servershell.command = '';
}
})
});
});

0 comments on commit 1939760

Please sign in to comment.