Skip to content

nvs meta --json

nvs meta --json prints a description of the whole Core library as one JSON object.

The object has these keys: classes, enums, exceptions, interfaces, attributes, directives and capabilities. A class has its methods, and each method has its name, signature, parameters, return type and documentation. directives lists every key of nvs.toml. capabilities lists each method that needs a permission, and the permission it needs.

With a file, as in nvs meta --json cart.nvs, the command also reads that program. It adds the key program with the classes, enums and type aliases of the program. The documentation of a declaration is the /// comment above it. In the signature of a property, readonly and lateinit come before the type, as in lateinit ?Customer $buyer.

Good to know: --json is required. A method that is not in capabilities needs no permission.

Examples

Document your own classes

<?nvs
// Shows how `nvs meta --json` reads the doc comments of your own classes.
// Run `nvs meta --json 01-document-your-own-classes.nvs` to get them as JSON.
// The JSON has a `program` key. It contains the class `Cart`, with `A shopping cart.`
// as its `short` text. You can build a documentation page from that JSON.
/// A shopping cart.
class Cart
{
public uint $items = 0;
// Each method is in the JSON with its `signature`: `add(uint $count = 1): uint`.
/// Adds items to the cart and returns the new number of items.
public function add(uint $count = 1): uint
{
$this->items = $this->items + $count;
return $this->items;
}
}
// Running the program calls the method. This prints `3`.
Cart $cart = new Cart();
$cart->add(2);
echo $cart->add(), "\n";
Output
3

Changelog

VersionChange
0.0.5In the output of nvs meta --json, the description of a @param keeps its line breaks.
0.0.6nvs meta --json writes readonly and lateinit in the signature of a property, before the type. An example is lateinit ?Customer $buyer.