import { MetadataStorage , DSlash , Modifier } from "../.." ; import { SubCommand } from "../../types" ; import { DGroup } from "../classes/DGroup" ; import { DOption } from "../classes/DOption" ; export function Group ( group ) ; export function Group ( subCommands ) ; export function Group ( group , description ) ; export function Group ( group , subCommands ) ; export function Group ( group , description , subCommands ) ; export function Group ( groupOrSubcommands , subCommandsOrDescription ? , subCommands ? ) { return ( target , key ? , descriptor ? ) => { const isGroup = typeof groupOrSubcommands === "string" ; const group = isGroup ? ( groupOrSubcommands as string ) . toLocaleLowerCase ( ) : undefined ; const isDescription = typeof subCommandsOrDescription === "string" ; const description = isDescription ? subCommandsOrDescription as string : undefined ; if ( subCommandsOrDescription !== undefined && ! isDescription ) { subCommands = subCommandsOrDescription as SubCommand ; } subCommands = isGroup ? subCommands : groupOrSubcommands as SubCommand ; if ( ! descriptor ) { if ( group ) { const group = DGroup . create < DSlash > ( groupOrSubcommands as string || key , { description } ) . decorate ( target as Function , ( target as Function ) . name ) ; MetadataStorage . instance . addGroup ( group ) ; } if ( subCommands ) { Object . keys ( subCommands ) . map ( ( key ) => { const group = DGroup . create < DOption > ( key , { description : subCommands [ key ] } ) . decorate ( target as Function , ( target as Function ) . name ) ; MetadataStorage . instance . addSubGroup ( group ) ; } ) ; } } else { MetadataStorage . instance . addModifier ( Modifier . create < DSlash > ( async ( original ) => { original . subgroup = group as string ; } , DSlash ) . decorate ( target . constructor , key ) ) ; } } ; }