import { Command , App , Alias } from '../types' ; import * as minimist from 'minimist' ; import { ifElse , identity } from 'ramda' ; export function matchCommands ( app , args ) { const filterMatches = ifElse ( hasAliases , aliasMatches ( args . _ [ 0 ] ) , identity ) ; if ( app . type === 'app' ) { return app . commands . filter ( filterMatches ) ; } return [ app ] . filter ( filterMatches ) ; } function hasAliases ( command ) { return command . aliases . length > 0 ; } function aliasMatches ( commandName ) { return function ( command ) : boolean { return command . aliases . filter ( matchAlias ( commandName ) ) . length > 0 ; } ; } function matchAlias ( name ) { return function ( alias ) { return alias . name === name || alias . abbreviation === name ; } ; }