function commandToWords
commandToWords(cmd: Command): string[]

Builds a command sentence from a Command object

Convenience function that converts a Command object into an array of words ready for encoding. This is a wrapper around buildCommand().

Examples

Convert Command to words

import { assertEquals } from "@std/assert";
import { commandToWords } from "@hertzg/routeros-api/protocol/command";

const cmd = {
  command: "/interface/print",
  attributes: { ".proplist": "name,type" }
};
const words = commandToWords(cmd);
assertEquals(words, ["/interface/print", "=.proplist=name,type"]);

Convert complex command

import { assertEquals } from "@std/assert";
import { commandToWords } from "@hertzg/routeros-api/protocol/command";

const cmd = {
  command: "/interface/set",
  attributes: { ".id": "ether1", "comment": "WAN" },
  queries: { "disabled": "no" }
};
const words = commandToWords(cmd);
assertEquals(words.length, 4); // command + 2 attributes + 1 query
assertEquals(words[0], "/interface/set");

Parameters

The Command object to convert

Return Type

string[]

Array of words representing the command

Usage

import { commandToWords } from "protocol/command.ts";