import Bluebird from "bluebird" ; import assert from "node:assert" ; import process from "node:process" ; import streamToPromise from "stream-to-promise" ; import { ReadonlyDeep , } from "type-fest" ; import CameraHelper from "../camera-helper.js" ; import { Command , CommandHandlerArgumentCameraHelper , CommandHandlerArgumentNames , } from "../types/command.js" ; import isUvccControls from "../utilities/is-uvcc-controls.js" ; export default class ImportCommand implements Command { constructor ( ) { assert . strictEqual ( arguments . length , 0 ) ; } async getArguments ( ) { return [ CommandHandlerArgumentCameraHelper , ] ; } async execute ( ... args ) { assert . strictEqual ( arguments . length , 1 ) ; const cameraHelper = args [ 0 ] as ReadonlyDeep < CameraHelper > ; const stdinTimeout = 1000 ; const controlValues = await Bluebird . try ( async ( ) => { const buffer = await streamToPromise ( process . stdin ) ; const json = JSON . parse ( buffer . toString ( ) ) as unknown ; assert ( typeof json === "object" ) ; assert ( json !== null ) ; return json ; } ) . timeout ( stdinTimeout , `Could not read uvcc configuration from stdin within the ${ stdinTimeout } millisecond timeout. Was any data piped in?` ) . tapCatch ( ( error ) => { process . stdin . destroy ( error ) ; } ) ; assert ( isUvccControls ( controlValues ) ) ; return cameraHelper . setControls ( controlValues ) ; } }