import { IBudgieNode } from "./IBudgieNode" ; /**
 * Budgie node for a command and any number of args.
 */ export class CommandNode implements IBudgieNode { /**
     * Characters that indicate a command needs to be wrapped in parenthesis.
     */ private static readonly textWrapIndicators : string [ ] = [ "{" , "(" , " " ] ; /**
     * Budgie command name.
     */ public readonly command : string ; /**
     * Arguments for the command.
     */ public readonly args : IBudgieNode [ ] ; param command param args public constructor ( command , args ) { this . command = command ; this . args = args ; } returns public toString ( ) { if ( this . args . length === 0 ) { return this . command ; } let output = this . command + " :" ; for ( const arg of this . args ) { output += " " + CommandNode . formatArg ( arg ) ; } return output ; } param arg returns private static wrapArg ( arg ) { for ( const indicator of CommandNode . textWrapIndicators ) { if ( arg . indexOf ( indicator ) !== - 1 ) { return `(${ arg })` ; } } return arg ; } param arg returns private static formatArg ( arg ) { if ( arg instanceof CommandNode ) { return `{ ${ arg } }` ; } return CommandNode . wrapArg ( arg . toString ( ) ) ; } }