All files / sportident-testbench-shell/src/commands getInfo.ts

43.47% Statements 10/23
0% Branches 0/4
33.33% Functions 2/6
45.45% Lines 10/22

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 721x   1x 1x     1x     1x   2x                           1x 1x 1x 1x                                                                                      
import {siStationStorageLocations} from 'sportident/lib/SiStation/BaseSiStation';
import {ShellCommandContext} from '../Shell';
import {BaseCommand, ArgType} from './BaseCommand';
import {getDirectOrRemoteStation} from './getDirectOrRemoteStation';
 
const allInfoNames = (
    Object.keys(siStationStorageLocations) as (keyof typeof siStationStorageLocations)[]
);
 
export class GetInfoCommand extends BaseCommand {
    getArgTypes(): ArgType[] {
        return [
            {
                name: 'target',
                choices: ['direct', 'remote'],
            },
            {
                name: 'information name',
                choices: Object.keys(siStationStorageLocations),
                isOptional: true,
            },
        ];
    }
 
    printUsage(context: ShellCommandContext): void {
        super.printUsage(context);
        context.putString('e.g. getInfo direct\n');
        context.putString('e.g. getInfo direct code\n');
        context.putString('e.g. getInfo remote mode\n');
    }
 
    run(context: ShellCommandContext): Promise<void> {
        const device = context.env.device;
        Iif (!device) {
            return Promise.reject(new Error('No device.'));
        }
        const station = getDirectOrRemoteStation(context.args[1], device);
        Iif (station === undefined) {
            context.putString('No such station\n');
            return Promise.resolve();
        }
        const infoNames = allInfoNames.filter((infoName) => (context.args[2]
            ? infoName === context.args[2]
            : true
        ));
        return station.readInfo()
            .then(() => {
                infoNames.sort();
                // logReact((
                //     <table>
                //         {infoNames.map((infoName) => (
                //             <tr key={infoName}>
                //                 <td>{infoName}</td>
                //                 <td>:</td>
                //                 <td>{`${station.getInfo(infoName)}`}</td>
                //             </tr>
                //         ))}
                //     </table>
                // ));
                infoNames.forEach((infoName) => {
                    context.putString(`${infoName}: ${station.getInfo(infoName)}\n`);
                });
                // selectedMainStation.getTime().then((time1) => {
                //     console.warn(time1 - new Date());
                //     selectedMainStation.setTime(new Date()).then((time2) => {
                //         console.warn(time2 - new Date());
                //     });
                // });
            });
    }
}