Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

JS: Commands, parameters and authorizations

Commands, parameters and authorizations

A gclass declares its commands in a table, in the same way that it declares its attributes. Every descriptor is an SDataDesc, and the macros below build one.

Source code: src/gobj.js

The command table goes to gclass_create(), and command_parser() reads it. A gclass that gives a command table does not need the mt_command method.

const command_table = [
    SDATACM(data_type_t.DTP_SCHEMA, "help", 0, pm_help, cmd_help,
        "Command's help"),
    SDATA_END()
];

The descriptor

SDataDesc

The class that holds one descriptor. Every macro below builds one of these, and each macro fills a different set of its fields. Build a descriptor with a macro and never with the constructor: the order of the fields is an internal detail.

SDATA_END()

The end of a table. Every table finishes with it.


Commands

SDATACM(type, name, alias, items, json_fn, description)

Declares one command.

KeyDescription
typeDTP_SCHEMA for a command.
nameThe name that the operator writes.
aliasA list of other names for the same command.
itemsThe table of the parameters, built with SDATAPM.
json_fnThe function that runs the command.
descriptionThe help line of the command.

SDATACM2(type, name, flag, alias, items, json_fn, description)

Declares one command, and adds a flag. Use it when the command needs an authorization flag, such as SDF_AUTHZ_X.


Parameters

SDATAPM(type, name, flag, default_value, description)

Declares one parameter of a command. It takes the same shape as SDATA().

const pm_help = [
    SDATAPM(data_type_t.DTP_STRING, "cmd", 0, "", "command about you want help"),
    SDATAPM(data_type_t.DTP_INTEGER, "level", 0, null, "command search level in childs"),
    SDATA_END()
];

SDATAPM0(type, name, flag, authpth, description)

Declares one parameter with an authorization path, and no default value.


Authorizations

SDATAAUTHZ(type, name, flag, alias, items, description)

Declares one authorization of the gclass. The authorization table goes to gclass_create().


Table columns

SDATADF(type, name, flag, header, fillspace, description)

Declares one column of a table of data. header is the title of the column, and fillspace is its part of the width. A schema of a command response uses these descriptors, so a viewer draws the answer without a schema of its own.