UNPKG

@iotize/cli

Version:
123 lines 5.05 kB
"use strict"; // import { bufferToHexString, bufferToAsciiString} from '@iotize/common/byte-converter'; // import { ServiceCallType, Tap } from '@iotize/device-client.js'; // import { ResponseError } from '@iotize/device-client.js/client/impl'; // import { MethodType } from '@iotize/device-client.js/client/api'; // import { IoTizeClient } from '@iotize/device-client.js/client/api'; // import { CommandBuilder } from '@iotize/shell-grammar.js'; // import { Command, command, metadata, param } from 'clime'; // import { display, input } from 'src/ui'; // import { DeviceOptions } from '../../options/device'; // export class MyOptions extends DeviceOptions { } // @command({ // description: 'Connect to an iotize device' // }) // export default class extends Command { // protected client!: IoTizeClient; // protected device!: Tap; // protected commandBuilder: CommandBuilder = new CommandBuilder(); // @metadata // async execute( // @param({ // default: '' // }) // command: string, // options: MyOptions // ) { // this.device = await options.getDevice(true, false, false); // if (command) { // await this.interpretCommand(command); // } else { // display.message('Starting interactive session... \n'); // await this.runInteractiveShell(); // } // await this.finish(); // } // runInteractiveShell(): Promise<boolean> { // return this.waitForCall().then((continueLooping: boolean) => { // if (continueLooping) { // return this.runInteractiveShell(); // } else { // return Promise.resolve(false); // } // }); // } // async waitForCall() { // let call = await input.selectLwm2mCommand(); // return this._processCall(call).then(() => true); // } // async waitForCommand(): Promise<boolean> { // var commandString = await input.string(''); // if (commandString == 'quit') { // return Promise.resolve(false); // } else { // return this.interpretCommand(commandString) // .catch((err: Error) => { // display.error(err.toString()); // }) // .then(() => { // return true; // }); // } // } // interpretCommand(commandString: string) { // try { // var command = CommandBuilder.fromString(commandString); // } catch (err) { // return Promise.reject( // `Invalid syntax!!! ${ // err ? (err.message ? err.message : err) : err // }` // ); // } // let call = { // path: command.getCommandUrl(), // methodType: MethodType[command.getMethod()] as any // }; // return this._processCall(call); // } // _processCall(call: ServiceCallType) { // let promise = this.device.lwm2m.call(call); // // let promise = this.client.command(command as any).toPromise(); // console.log('Waiting for promise resolve...'); // return promise // .then(result => { // if (result.isSuccessful()) { // var formattedResponse = ''; // if (result.hasBody()) { // // var content = "; // // formattedResponse += " - hex: " + bufferToHexString(result.rawBody()!) + " - ascii: " + content; // let body = result.body(); // if (body instanceof Uint8Array) { // formattedResponse = `0x${bufferToHexString( // body // )}`; // formattedResponse += `\r\nASCII:${bufferToAsciiString( // body // )}`; // } else if (typeof body === 'object') { // formattedResponse = JSON.stringify(body); // } else { // formattedResponse = body; // } // } else { // formattedResponse = '[NO CONTENT]'; // } // display.success(formattedResponse); // } else { // display.error(` > ${new ResponseError(result)}`); // } // }) // .catch((err: any) => { // display.error(err); // }); // } // async finish() { // // display.info("Quit!"); // if (this.device) { // await this.device.disconnect(); // } // process.exit(0); // } // } //# sourceMappingURL=cmd.js.map