mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
Make help function use OperationConfig.json file
Tidy up Gruntfile execs
This commit is contained in:
parent
db7b52d84c
commit
fa8736b1a4
8 changed files with 1396 additions and 165 deletions
|
@ -7,6 +7,7 @@
|
|||
*/
|
||||
|
||||
import SyncDish from "./SyncDish";
|
||||
import OperationConfig from "./config/OperationConfig.json";
|
||||
|
||||
/**
|
||||
* Extract default arg value from operation argument
|
||||
|
@ -134,56 +135,31 @@ export function decapitalise(name) {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract properties from an operation by instantiating it and
|
||||
* returning some of its properties for reference.
|
||||
* @param {Operation} Operation - the operation to extract info from
|
||||
* @returns {Object} operation properties
|
||||
*/
|
||||
function extractOperationInfo(Operation) {
|
||||
const operation = new Operation();
|
||||
return {
|
||||
name: decapitalise(operation.name).replace(/ /g, ""),
|
||||
module: operation.module,
|
||||
description: operation.description,
|
||||
inputType: operation.inputType,
|
||||
outputType: operation.outputType,
|
||||
// Make arg names lowercase, no spaces to encourage non-sentence
|
||||
// caps in repl
|
||||
args: Object.assign([], operation.args).map((s) => {
|
||||
s.name = decapitalise(s.name).replace(/ /g, "");
|
||||
return s;
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @namespace Api
|
||||
* @param {Operation[]} operations - an object filled with operations.
|
||||
* @param {String} searchTerm - the name of the operation to get help for.
|
||||
* Case and whitespace are ignored in search.
|
||||
* @returns {Function} taking search term and outputting description.
|
||||
* @returns {Object} Describe function matching searchTerm.
|
||||
*/
|
||||
export function help(operations) {
|
||||
return function(searchTerm) {
|
||||
let sanitised = false;
|
||||
if (typeof searchTerm === "string") {
|
||||
sanitised = searchTerm;
|
||||
} else if (typeof searchTerm === "function") {
|
||||
sanitised = searchTerm.opName;
|
||||
}
|
||||
export function help(searchTerm) {
|
||||
let sanitised = false;
|
||||
if (typeof searchTerm === "string") {
|
||||
sanitised = searchTerm;
|
||||
} else if (typeof searchTerm === "function") {
|
||||
sanitised = searchTerm.opName;
|
||||
}
|
||||
|
||||
if (!sanitised) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const operation = operations
|
||||
.find(o => o.name.toLowerCase() === sanitised.replace(/ /g, "").toLowerCase());
|
||||
if (operation) {
|
||||
return extractOperationInfo(operation);
|
||||
}
|
||||
if (!sanitised) {
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
const key = Object.keys(OperationConfig)
|
||||
.find(o => o.replace(/ /g, "").toLowerCase() === sanitised.replace(/ /g, "").toLowerCase());
|
||||
if (key) {
|
||||
const result = OperationConfig[key];
|
||||
result.name = key;
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue