|
@@ -11,7 +11,7 @@
|
|
|
import SyncDish from "./SyncDish";
|
|
|
import NodeRecipe from "./NodeRecipe";
|
|
|
import OperationConfig from "./config/OperationConfig.json";
|
|
|
-import { sanitise } from "./apiUtils";
|
|
|
+import { sanitise, removeSubheadingsFromArray, sentenceToCamelCase } from "./apiUtils";
|
|
|
import ExludedOperationError from "../core/errors/ExcludedOperationError";
|
|
|
|
|
|
|
|
@@ -58,12 +58,7 @@ function transformArgs(originalArgs, newArgs) {
|
|
|
// See Strings op for example.
|
|
|
const allArgs = Object.assign([], originalArgs).map((a) => {
|
|
|
if (Array.isArray(a.value)) {
|
|
|
- a.value = a.value.filter((v) => {
|
|
|
- if (typeof v === "string") {
|
|
|
- return !v.match(/^\[[\s\S]*\]$/); // Matches anything surrounded in [ ]
|
|
|
- }
|
|
|
- return true;
|
|
|
- });
|
|
|
+ a.value = removeSubheadingsFromArray(a.value);
|
|
|
}
|
|
|
return a;
|
|
|
});
|
|
@@ -96,6 +91,7 @@ function transformArgs(originalArgs, newArgs) {
|
|
|
return allArgs.map(extractArg);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* Ensure an input is a SyncDish object.
|
|
|
* @param input
|
|
@@ -112,6 +108,7 @@ function ensureIsDish(input) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* prepareOp: transform args, make input the right type.
|
|
|
* Also convert any Buffers to ArrayBuffers.
|
|
@@ -132,6 +129,32 @@ function prepareOp(opInstance, input, args) {
|
|
|
return {transformedInput, transformedArgs};
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+/**
|
|
|
+ * createArgOptions
|
|
|
+ *
|
|
|
+ * Create an object of options for each option or togglestring argument
|
|
|
+ * in the given operation.
|
|
|
+ *
|
|
|
+ * Argument names are converted to camel case for consistency.
|
|
|
+ *
|
|
|
+ * @param {Operation} op - the operation to extract args from
|
|
|
+ * @returns {{}} - arrays of options for option and toggleString args.
|
|
|
+*/
|
|
|
+function createArgOptions(op) {
|
|
|
+ const result = {};
|
|
|
+ op.args.forEach((a) => {
|
|
|
+ if (a.type === "option") {
|
|
|
+ result[sentenceToCamelCase(a.name)] = removeSubheadingsFromArray(a.value);
|
|
|
+ } else if (a.type === "toggleString") {
|
|
|
+ result[sentenceToCamelCase(a.name)] = removeSubheadingsFromArray(a.toggleValues);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* Wrap an operation to be consumed by node API.
|
|
|
* Checks to see if run function is async or not.
|
|
@@ -187,13 +210,16 @@ export function wrap(OpClass) {
|
|
|
|
|
|
// used in chef.help
|
|
|
wrapped.opName = OpClass.name;
|
|
|
+ wrapped.argOptions = createArgOptions(opInstance);
|
|
|
+
|
|
|
return wrapped;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
- * @namespace Api
|
|
|
* help: Give information about operations matching the given search term,
|
|
|
* or inputted operation.
|
|
|
+ *
|
|
|
* @param {String || wrapped operation} input - the name of the operation to get help for.
|
|
|
* Case and whitespace are ignored in search.
|
|
|
* @returns {Object[]} Config of matching operations.
|
|
@@ -248,6 +274,7 @@ export function help(input) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* bake [Wrapped] - Perform an array of operations on some input.
|
|
|
* @param operations array of chef's operations (used in wrapping stage)
|
|
@@ -271,7 +298,10 @@ export function bake(operations){
|
|
|
};
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
+ * explainExcludedFunction
|
|
|
+ *
|
|
|
* Explain that the given operation is not included in the Node.js version.
|
|
|
* @param {String} name - name of operation
|
|
|
*/
|