CommandBox

repository·development·Indexed 41 days ago

https://github.com/ortus-solutions/commandbox

A comprehensive CLI, package manager, and embedded server for ColdFusion (CFML) development designed to streamline the CFML lifecycle. It functions as a multi-purpose toolset including a REPL and provides various system modules such as Globber for file system path pattern matching, JMESPath for querying JSON and CFML data, JSONPrettyPrint for formatting JSON, and PropertyFile for managing Java property files.

Tokens
55.4K
Snippets
270
Records
320
Agent score
100%

What's inside CommandBox

  1. Use the Lucee 5 formatter on Adobe ColdFusion

    development

    On Lucee 5, the library uses an alternate formatter that deserializes JSON to ordered structs, providing a significant performance boost while preserving key order and data types.

    Adobe ColdFusion does not preserve key order and (prior to ACF 2018) may inaccurately serialize data types. If you are using ColdFusion and want the performance boost of the Lucee 5 formatter—and you are willing to accept the loss of key order or potential data type inaccuracies—you can inject the specific formatter using the @JSONPrettyPrint alias.

    component {
      // Inject the Lucee 5 formatter specifically
      property name='JSONPrettyPrint' inject="CFMLPrinter@JSONPrettyPrint";
    
      function writeJSON( required JSON, required path ) {
        fileWrite( path, JSONPrettyPrint.formatJSON( JSON ) );
      }
    }
  2. Use Special Keys and Expressions in JMESPath

    development

    JMESPath supports several special characters to control how expressions and values are evaluated:

    • @ (Current Node): Refers to the current number, string, array, or object being evaluated.
    • & (Expression): Used to denote a function or a keyname (e.g., &to_number() or &keyname). This is required when passing functions as arguments to other functions.
    • ! (NOT): Negates an expression.
    • && (AND): Logical AND expression.
    • || (OR): Logical OR expression.
    • `{'ab':true}` (Literal Expressions): Used to define literals, which are converted to JSON.
    • 'foo' (Raw String Literals): Single quotes are used for raw strings that should not be evaluated.
  3. JMESPath expression features and syntax

    development

    This implementation supports a wide range of JMESPath features for querying data:

    Basic Access & Wildcards

    • Nested values: foo.bar
    • Wildcards: *.bar
    • Array projection: foo[*].bar[1]

    Slicing, Pipes, and Indices

    • Slicing: foo[start:end:step] (e.g., foo[10:0:-1])
    • Pipes: Use | to pass the result of one expression to another (e.g., foo[*].bar[*] | [0][0])
    • Indices: Supports positive, negative, and out-of-bounds indices (out-of-bounds returns null).

    Multiselect

    • List projection: foo.[bar, baz[0]] returns an array of values.
    • Object projection: foo.{bar: bar, buz: buz} returns a new object with specified keys.

    Current Node Reference

    • Use @ to refer to the current node (e.g., @.bar or @.foo[0]).

    Filters

    • Use [? <expression>] to filter arrays. Expressions can use comparison operators like ==, !=, >, >=, <, <=. Note that literals in filters should be enclosed in backticks (e.g., [?age > 25]).
    // Example: Filtering
    var data = { foo: [{ age: 20 }, { age: 25 }, { age: 30 }] };
    JMESPath.search(data, 'foo[?age > `25`]'); // returns [{"age":30}]
    
    // Example: Multiselect Object
    var data = { foo: { bar: 1, baz: [2, 3, 4], buz: 2 } };
    JMESPath.search(data, 'foo.{bar: bar, buz: buz}'); // returns {"bar":1,"buz":2}