file copyright author Vivek M. Chawla <@VivekMChawla>
 *  summary description version license const debug = require ( 'debug' ) ; const chalk = require ( 'chalk' ) ; const util = require ( 'util' ) ; /** Type. Alias to any, mainly so the intent is obvious when this is used. */ type DebugFunc = any ; class summary description public export class SfdxFalconDebug { public static lineBreaks : number = 5 ; public static debugDepth : number = 2 ; method param { string } namespace returns { boolean } description public static public static checkEnabled ( namespace ) { const namespaceGroups = namespace . split ( ':' ) ; let namespaceToTest = '' ; for ( const namespaceGroup of namespaceGroups ) { namespaceToTest += namespaceGroup ; if ( SfdxFalconDebug . enabledDebuggers . get ( namespaceToTest ) ) { return true ; } namespaceToTest += ':' ; } return false ; } method param { Array < string > } namespaces param { number } debugDepth returns { void } description public static public static enableDebuggers ( namespaces , debugDepth = 2 ) { for ( const namespace of namespaces ) { SfdxFalconDebug . enabledDebuggers . set ( namespace , true ) ; } SfdxFalconDebug . debugDepth = debugDepth ; if ( SfdxFalconDebug . enabledDebuggers . size > 0 ) { console . log ( chalk `\n{blue The Following Debug Namesapces are Enabled (Debug Depth = ${ debugDepth }):}\n%O\n` , namespaces ) ; } } method param { string } namespace param { string } message returns { void } description public static public static debugMessage ( namespace , message ) { const debugFunc = SfdxFalconDebug . getDebugger ( namespace ) ; debugFunc ( `\n${ chalk . blue ( message ) }\n` ) ; } method param { string } namespace param { object } objToDebug param { string } strLead param { string } strTail returns { void } description public static public static debugObject ( namespace , objToDebug , strLead = '' , strTail = '' ) { const debugFunc = SfdxFalconDebug . getDebugger ( namespace ) ; debugFunc ( `\n${ chalk . yellow ( strLead ) }\n` + `${ util . inspect ( objToDebug , { depth : 8 , colors : true } ) }` + `${ SfdxFalconDebug . printLineBreaks ( ) }` ) ; } method param { string } namespace param { string } strToDebug param { string } strLead param { string } strTail returns { void } description public static public static debugString ( namespace , strToDebug , strLead = '' , strTail = '' ) { const debugFunc = SfdxFalconDebug . getDebugger ( namespace ) ; debugFunc ( `-\n${ chalk . blue ( strLead ) }${ strToDebug }${ chalk . blue ( strTail ) }${ SfdxFalconDebug . printLineBreaks ( ) }` ) ; } method param { string [ ] } namespaces returns { void } description public static public static disableDebuggers ( namespaces ) { for ( const namespace of namespaces ) { SfdxFalconDebug . enabledDebuggers . set ( namespace , false ) ; } } method param { string } namespace returns { DebugFunc } description public static public static getDebugger ( namespace ) { if ( SfdxFalconDebug . debuggers . has ( namespace ) ) { return SfdxFalconDebug . debuggers . get ( namespace ) ; } else { const newDebugger = debug ( namespace ) ; newDebugger . enabled = true ; SfdxFalconDebug . debuggers . set ( namespace , newDebugger ) ; return newDebugger ; } } method param { string } namespace param { string } message returns { void } description public static public static msg ( namespace , message ) { if ( SfdxFalconDebug . checkEnabled ( namespace ) ) { SfdxFalconDebug . debugMessage ( namespace , message ) ; } } method param { string } namespace param { object } objToDebug param { string } strLead param { string } strTail returns { void } description public static public static obj ( namespace , objToDebug , strLead = '' , strTail = '' ) { if ( SfdxFalconDebug . checkEnabled ( namespace ) ) { SfdxFalconDebug . debugObject ( namespace , objToDebug , strLead , strTail ) ; } } method param { string } namespace param { string } strToDebug param { string } strLead param { string } strTail returns { void } description public static public static str ( namespace , strToDebug , strLead = '' , strTail = '' ) { if ( SfdxFalconDebug . checkEnabled ( namespace ) ) { SfdxFalconDebug . debugString ( namespace , strToDebug , strLead , strTail ) ; } } method param { string } message description public static public static toConsole ( message ) { console . log ( `${ SfdxFalconDebug . printLineBreaks ( ) }` + `\n${ chalk . yellow ( message ) }\n` + `${ SfdxFalconDebug . printLineBreaks ( ) }` ) ; } private static debuggers : Map < string , DebugFunc > = new Map ( ) ; private static enabledDebuggers : Map < string , boolean > = new Map < string , boolean > ( ) ; method description private static private static printLineBreaks ( ) { return '\n-' . repeat ( SfdxFalconDebug . lineBreaks ) ; } }