'use strict' ; import * as path from 'path' ; import { exec , ExecOptions } from 'child_process' ; import * as constants from './constants' ; import * as utils from './utils' ; interface CommandExecOptions { cmd : string ; cwd ? : boolean ; } /**
 * Command class
 */ export class Command { rootPath : string ; rcPath : string ; constructor ( rootPath ) { this . rootPath = rootPath ; this . rcPath = path . join ( rootPath , `${ constants . direnv . rc }` ) ; } private exec ( options ) { let direnvCmd = [ constants . direnv . cmd , options . cmd ] . join ( ' ' ) ; let execOptions = { } ; if ( options . cwd == null || options . cwd ) { execOptions . cwd = this . rootPath ; } return new Promise ( ( resolve , reject ) => { exec ( direnvCmd , execOptions , ( err , stdout , stderr ) => { if ( err ) { err . message = stderr ; reject ( err ) ; } else { resolve ( stdout ) ; } } ) ; } ) ; } version = ( ) => this . exec ( { cmd : 'version' } ) ; allow = ( ) => this . exec ( { cmd : 'allow' } ) ; deny = ( ) => this . exec ( { cmd : 'deny' } ) ; exportJSON = ( ) => this . exec ( { cmd : 'export json' } ) . then ( ( o ) => o ? JSON . parse ( o ) : { } ) ; }