@iotize/cli
Version:
IoTize command line interface
109 lines • 4.69 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 __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 clime_1 = require("clime");
const inversify_config_1 = require("../../inversify.config");
const types_1 = require("../../types");
const ui_1 = require("src/lib/ui");
const ui_2 = require("../../ui");
const ALLOW_SCANNERS = ['WIFI', 'BLE', 'NETWORK'];
class ListType {
constructor(values) {
this.values = values;
}
static cast(strValue, context) {
return new ListType(strValue.split(','));
}
}
class ScanOptions extends clime_1.Options {
}
__decorate([
clime_1.option({
flag: 'd',
description: 'Scan duration in milliseconds (0 for infinite). By default, it will run forever.',
required: false,
default: 0
}),
__metadata("design:type", Number)
], ScanOptions.prototype, "duration", void 0);
__decorate([
clime_1.option({
flag: 'a',
description: 'Show all devices (do not show only IoTize devices)',
required: false,
default: false,
toggle: true
}),
__metadata("design:type", Boolean)
], ScanOptions.prototype, "all", void 0);
__decorate([
clime_1.option({
description: 'Scanners list to use (BLE,WIFI,NETWORK)',
required: false,
default: new ListType(ALLOW_SCANNERS)
// type: ListType
}),
__metadata("design:type", ListType)
], ScanOptions.prototype, "scanners", void 0);
exports.ScanOptions = ScanOptions;
let default_1 = class default_1 extends clime_1.Command {
execute(options) {
return __awaiter(this, void 0, void 0, function* () {
let scanner = yield inversify_config_1.container.get(types_1.TYPES.DeviceScannerProvider)();
let scannerIds = options.scanners.values.map(v => v.toUpperCase());
ui_2.display.infonl(`Scanning ${scannerIds.join(', ')}`);
let shown = [];
let obs = scanner.search({
all: options.all,
ids: scannerIds,
timeout: options.duration
});
obs.subscribe({
next: (scannedDevices) => {
let newList = scannedDevices.map(ui_1.scanItemToString);
newList = newList.filter(newItem => shown.indexOf(newItem) == -1);
shown.push(...newList);
// display.infonl(`### DEVICES ####`);
ui_2.display.list(newList);
},
complete: () => {
ui_2.display.infonl(`Scan finished!`);
},
error: error => {
ui_2.display.error(error);
}
});
yield obs.toPromise();
});
}
};
__decorate([
clime_1.metadata,
__metadata("design:type", Function),
__metadata("design:paramtypes", [ScanOptions]),
__metadata("design:returntype", Promise)
], default_1.prototype, "execute", null);
default_1 = __decorate([
clime_1.command({
description: 'Scan devices with Wi-Fi or BLE (if enabled)'
})
], default_1);
exports.default = default_1;
//# sourceMappingURL=scan.js.map