@iotize/cli
Version:
IoTize command line interface
83 lines • 4.04 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const api_1 = require("@iotize/device-client.js/api");
const clime_1 = require("clime");
const ui_1 = require("../../../../ui");
const device_1 = require("../../../options/device");
const byte_converter_1 = require("@iotize/common/byte-converter");
function parseUserInput(value) {
if (value.match(/^0x([\sa-fA-F0-9]*)$/)) {
return byte_converter_1.hexStringToBuffer(value);
}
else {
return JSON.parse(value);
}
}
exports.parseUserInput = parseUserInput;
class MyOptions extends device_1.DeviceOptions {
}
exports.MyOptions = MyOptions;
let default_1 = class default_1 extends clime_1.Command {
execute(key, value, options) {
return __awaiter(this, void 0, void 0, function* () {
const device = yield options.getDevice(true, false);
// if (!options.credentials) {
// display.warn(
// `Use --credentials option to write configuration`
// );
// }
const ressource = new api_1.ApiExplorer(device).resources.find(r => {
return r.path === `/${key}` && r.methodType === 'PUT';
});
if (!ressource) {
throw new Error(`Resource with path ${key} not found (with method PUT).`);
}
ressource.body = parseUserInput(value);
(yield device.lwm2m.call(ressource)).successful();
ui_1.display.success(`PUT on "${key}" successful`);
});
}
};
__decorate([
clime_1.metadata,
__param(0, clime_1.param({
description: 'Resource path to edit. Eg: /device/serial-number',
})),
__param(1, clime_1.param({
description: 'Value to write as JSON. Eg: "Hello World" for a string, 12 for a number or 0x01A0BC34 for bytes',
})),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, String, MyOptions]),
__metadata("design:returntype", Promise)
], default_1.prototype, "execute", null);
default_1 = __decorate([
clime_1.command({
description: `Set value for a configuration entry.
For example: iotize tap lwm2m put interface/app-name '"My App Name"'
`,
brief: 'Set value for a configuration entry'
})
], default_1);
exports.default = default_1;
//# sourceMappingURL=put.js.map