import { Writable } from 'stream' ; import { Arguments , RawResponse , Registrar } from '@kui-shell/core' ; import { ls , fslice , fstat , fwrite , pipe } from '../delegates' ; import { KuiGlobOptions , GlobStats } from '../../lib/glob' ; import { FwriteOptions } from '../../lib/fwrite' ; export async function lsImpl ( args ) { return { mode : 'raw' , content : await ls ( args , args . argvNoOptions . slice ( 2 ) ) } ; } export async function fwriteImpl ( args ) { return { mode : 'raw' , content : await fwrite ( args , args . argvNoOptions [ 2 ] , args . execOptions . data as string | Buffer , { append : args . parsedOptions && ( args . parsedOptions . append || args . parsedOptions . a ) } ) } ; } export async function fstatImpl ( args ) { return { mode : 'raw' , content : await fstat ( args , args . argvNoOptions [ 2 ] , ! ! args . parsedOptions [ 'with-data' ] , ! ! args . parsedOptions [ 'enoent-ok' ] ) } ; } export default function ( registrar ) { registrar . listen ( '/vfs/_ls' , lsImpl , { requiresLocal : true , flags : { boolean : [ 'A' , 'a' , 'd' , 'c' , 'C' , 'l' , 'h' , 't' , 'r' , 's' , 'S' ] } } ) ; registrar . listen ( '/vfs/_fstat' , fstatImpl , { requiresLocal : true , flags : { boolean : [ 'with-data' , 'enoent-ok' ] } } ) ; registrar . listen ( '/vfs/_fwrite' , fwriteImpl , { requiresLocal : true } ) ; registrar . listen ( '/vfs/cat' , async ( args ) => { await pipe ( args . argvNoOptions [ 2 ] , args . argvNoOptions [ 3 ] ? parseInt ( args . argvNoOptions [ 3 ] , 10 ) : 0 , args . argvNoOptions [ 4 ] ? parseInt ( args . argvNoOptions [ 4 ] , 10 ) : undefined , args . execOptions . data as Writable ) ; return true ; } , { requiresLocal : true } ) ; registrar . listen ( '/vfs/fslice' , args => { return fslice ( args . argvNoOptions [ 2 ] , parseInt ( args . argvNoOptions [ 3 ] , 10 ) , parseInt ( args . argvNoOptions [ 4 ] , 10 ) , args . argvNoOptions [ 5 ] as 'bytes' | 'lines' ) ; } , { requiresLocal : true } ) ; }