import { CommandHandler , KResponse , ParsedOptions , Registrar } from '@kui-shell/core' ; import { fstatImpl , fwriteImpl , lsImpl } from './server-side' ; import { cp , rm , mkdir , rmdir } from '../delegates' ; param boolean function withBooleanFlags < Handler extends CommandHandler < KResponse , ParsedOptions > > ( this , command , handler , booleans , booleans2 ? ) { this . listen ( `/${ command }` , handler , { flags : { boolean : ( typeof booleans === 'string' ? booleans . split ( '' ) : booleans ) . concat ( booleans2 || [ ] ) } } ) ; } export default function ( registrar ) { const on = withBooleanFlags . bind ( registrar ) ; on ( 'vfs/ls' , async ( args ) => { try { return await lsImpl ( args ) ; } catch ( err ) { return args . REPL . qexec ( args . command . replace ( 'vfs ls' , 'vfs _ls' ) ) ; } } , 'AadcClhtrsS' ) ; on ( 'vfs/fstat' , async ( args ) => { try { return await fstatImpl ( args ) ; } catch ( err ) { return args . REPL . qexec ( args . command . replace ( 'vfs fstat' , 'vfs _fstat' ) ) ; } } , [ 'with-data' , 'enoent-ok' ] ) ; on ( 'vfs/fwrite' , async ( args ) => { try { return await fwriteImpl ( args ) ; } catch ( err ) { return args . REPL . qexec ( args . command . replace ( 'vfs fwrite' , 'vfs _fwrite' ) , undefined , undefined , { data : args . execOptions . data } ) ; } } , 'data' ) ; on ( 'rm' , args => rm ( args , args . argvNoOptions [ 1 ] , ! ! ( args . parsedOptions . r || args . parsedOptions . R ) ) . then ( response => typeof response === 'string' ? response : true ) , 'frRidPvw' ) ; on ( 'mkdir' , args => mkdir ( args , args . argvNoOptions [ 1 ] ) . then ( ( ) => true ) , 'pv' ) ; on ( 'rmdir' , args => rmdir ( args , args . argvNoOptions [ 1 ] ) . then ( ( ) => true ) , 'p' ) ; on ( 'cp' , args => { const N = args . argvNoOptions . length ; const srcs = args . argvNoOptions . slice ( 1 , N - 1 ) ; const dst = args . argvNoOptions [ N - 1 ] ; return cp ( args , srcs , dst ) ; } , 'acfHiLnPpRvXs' ) ; }