How to use the cli.install function in cli

To help you get started, we’ve selected a few cli examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Moddable-OpenSource / moddable / examples / network / telnet / main.js View on Github external
*
 *   This file is part of the Moddable SDK.
 * 
 *   This work is licensed under the
 *       Creative Commons Attribution 4.0 International License.
 *   To view a copy of this license, visit
 *       .
 *   or send a letter to Creative Commons, PO Box 1866,
 *   Mountain View, CA 94042, USA.
 *
 */

import Telnet from "telnet";
import CLI from "cli";

CLI.install(function (command, params) {
	switch (command) {
		case "example":
			this.line(`example with ${params.length} parameters`);
			break;
		case "help":
			this.line(`example [params] - display number of parameters`);
			break;
		default:
			return false;
	}
	return true;
});

export default function() {
	new Telnet({port: 2300});
github Moddable-OpenSource / moddable / modules / base / cli / commands / sensor.js View on Github external
/*
 *     Copyright (C) 2016-2017 Moddable Tech, Inc.
 *     All rights reserved.
 */

import CLI from "cli";

CLI.install(async function(command, parts) {
	if ("sensor" !== command)
		return false;

	if (!parts.length)
		throw new Error("missing open/close/configure/sample");

	switch (parts.shift().toLowerCase()) {
		case "open":
			if (this.sensor)
				throw new Error("already open");
			this.suspend();
			try {
				this.sensor = new ((await import(parts[0]))).default({});
			}
			catch(e) {
				this.line(e.toString());
github Moddable-OpenSource / moddable / modules / base / cli / commands / i2c.js View on Github external
*   (at your option) any later version.
 * 
 *   The Moddable SDK Runtime is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Lesser General Public License for more details.
 * 
 *   You should have received a copy of the GNU Lesser General Public License
 *   along with the Moddable SDK Runtime.  If not, see .
 *
 */

import CLI from "cli";
import SMBus from "pins/smbus";

CLI.install(function(command, parts) {
	switch (command) {
		case "i2c":
			if (parts.length < 1)
				throw new Error("missing read/write/scan");
			let address = parseInt(parts[1]);
			let i2c = new SMBus({address});
			let mode = parts[0].toLowerCase();
			if ("read" === mode) {
				if (parts.length < 2)
					throw new Error("missing address");
				if (parts.length < 3)
					throw new Error("missing register number");

				let i2c = new SMBus({address});
				let count = (3 == parts.length) ? 1 : parseInt(parts[3]);
				for (let i = 0, register = parseInt(parts[2]); i < count; i++, register++)
github Moddable-OpenSource / moddable / modules / base / cli / commands / pixelsout.js View on Github external
/*
 *     Copyright (C) 2016-2019 Moddable Tech, Inc.
 *     All rights reserved.
 */

import CLI from "cli";

CLI.install(function(command, parts) {
	if ("help" === command) {
		this.line("screen - print information");
		this.line("screen rotate degrees - rotate display");
		this.line("screen fill r g b [x y width height] - uses specified color to fill full screen or specified area");
		return;
	}

	if ("screen" !== command)
		return false;

	if (!global.screen) {
		this.line("no screen found");
		return true;
	}

	if (!parts.length) {
github Moddable-OpenSource / moddable / modules / base / cli / commands / network.js View on Github external
*   GNU Lesser General Public License for more details.
 * 
 *   You should have received a copy of the GNU Lesser General Public License
 *   along with the Moddable SDK Runtime.  If not, see .
 *
 */


import CLI from "cli";
import Timer from "timer";
import Net from "net";
import WiFi from "wifi";

const status = ["idle", "connecting", "wrong password", "no ap found", "connect fail", "got ip"];

CLI.install(function(command, parts) {
	switch (command) {
		case "net":
			this.line(`  IP Address: ${Net.get("IP") || "(undefined)"}`);
			this.line(`  SSID: ${Net.get("SSID") || "(undefined)"}`);
			this.line(`  BSSID: ${Net.get("BSSID") || "(undefined)"}`);
			this.line(`  RSSI: ${Net.get("RSSI") || "(undefined)"}`);
			this.line(`  MAC Address: ${Net.get("MAC") || "(undefined)"}`);
			this.line(`  Connection status: ${status[WiFi.status]}`);
			break;

		case "connect": {
			let dictionary;
			if (1 === parts.length)
				dictionary = {ssid: parts[0]};
			else if (2 === parts.length)
				dictionary = {ssid: parts[0], password: parts[1]};