config/
src/
helper/
models/
test (not really in use yet)
All commands with configuration have a specific yaml config file. A common.yml file defined what is common, such as IP, devices, USB id, etc. A specific config file overrides values from the common file and add new properties like a list of actions (diagnose command). Configuration files are separated for a better structure and it's easier to edit.
The configuration file must follow this pattern (capitals are replaced by a value):
PLATFORM: # platform value (become the "name" property of a platform instance)
devices: # list of devices for the platform
DEVICE: # device value (become the "name" property of a device instance)
ip: 0.0.0.0 # IP address of the device
# other device properties (ex: USB ID, username, etc.)
A specific configuration file must define new properties to a device or platform. To do so, you need to repeat the structure of platforms and devices, but you don't need to repeat common properties (like IP).
PLATFORM: # from common file
devices:
DEVICE: # from common file
CMD: # ex: name of the command
# Properties
In the configuration file, you can use tokens to access properties. Tokens are evaluated on runtime with the eval JavaScript function. Using this, an IP address (and other properties) can be written once and used in multiple places in the config file (you can also access a value from the common file). When you create a new src/commands/command.ts, make sure tokens are presents and that you eval every value you get from config. To use a token, you need to insert {{TOKEN_TO_EVALUATE.PROPERTY}} as a value in the config file. Property used in the {{}} doesn't have to be defined in the model (see below).
Possible tokens are:
platform.name)device.name, device.ip)PLATFORM:
devices:
DEVICE:
diagnose: # Object (if defined, diagnose command avalaible for platform-device)
name: "Value to show in the terminal" # Required (string, token available)
errorMessage: "Message to display if an error occurs" # Required (string, token available)
actions: # Array of action with the following structure (Required)
- name: "Value to show in the terminal" # Required (string, token available)
errorMessage: "Message to display if an error occurs" # Required (string, token available)
cmd: "command to execute in the terminal context" #Required (string, token available)
Actions are executed sequentially, but each device is executed in parallel.
PLATFORM:
devices:
DEVICE:
execute: # Array of possible commands (if defined, execute command available for platform-device)
- name: "name_of_the_command" # Required (string, no spaces allowed)
cmd: "command to execute in the terminal context" # Required (string, token available)
Each command has its file with the code inside. See oclif documentation for more details.
This folder contains helpers for configuration deserialization. They parse the common and specific configuration files and transform platforms and devices object keys to name values. Config objects can now be used in a command.
Configuration files are mapped to models so they can be used in the src/commands/COMMAND.ts file.
The common structure interfaces (defined in the config/common.yml file) are defined in the folder with the same name. Specific interfaces for command must extend common interfaces: this is why we have a platform.ts and device.ts in both folders. Specific properties MUST be defined as undefined possible value (possible with the question mark in TypeScript), so you can check in the src/commands/command.ts file that the command is possible for the platform-device combination.
sonia execute command