Skip to content

Commit

Permalink
style: update docblock
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Apr 10, 2019
1 parent b445264 commit c93610a
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions packages/ace/src/utils/sortAndGroupCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,29 @@
* file that was distributed with this source code.
*/

import { CommandConstructorContract } from '../Contracts'
import { CommandConstructorContract, CommandsGroup } from '../Contracts'

/**
* Shape of groups and their commands
*/
type Grouped = {
group: string,
commands: CommandConstructorContract[],
}[]

/**
/**
* Loops over the commands and converts them to an array of sorted groups with
* nested commands inside them. The grouping is done using the command
* namespace seperated with `:`. Example: `make:controller`
*/
export function sortAndGroupCommands (commands: CommandConstructorContract[]): Grouped {
export function sortAndGroupCommands (commands: CommandConstructorContract[]): CommandsGroup {
/**
* Create a group of commands using it's namespace
*/
const groupsLiteral = commands.reduce((result, command) => {
const tokens = command.commandName.split(':')

/**
* Use the command namespace or move it inside the `root` group when
* it is not namespaced.
*/
const group = tokens.length > 1 ? tokens.shift()! : 'root'

result[group] = result[group] || []
result[group].push(command)

return result
}, {} as { [key: string]: CommandConstructorContract[] })

Expand Down

0 comments on commit c93610a

Please sign in to comment.