import { Command } from "./Command" ; /**
 * Holds commands indexed by name.
 */ export class CommandsBag { /**
     * Globally known commands, keyed by their Budgie alias.
     */ private commands : { [ i ] : Command ; } ; param context public constructor ( commands ) { this . commands = { } ; for ( const command of commands ) { this . addCommand ( command ) ; } } param command public addCommand ( command ) { const metadata = command . getMetadata ( ) ; const name = metadata . name ; if ( { } . hasOwnProperty . call ( this . commands , name ) ) { throw new Error ( `Cannot add duplicate command: '${ name }'.` ) ; } this . commands [ name ] = command ; } param name returns public getCommand ( name ) { if ( ! { } . hasOwnProperty . call ( this . commands , name ) ) { throw new Error ( `Unknown command requested: '${ name }'.` ) ; } return this . commands [ name ] ; } returns public getCommands ( ) { return this . commands ; } }