import { App , Command , Flag , CommandFlags } from '../types' ; import { reduce } from 'ramda' ; import { deepMerge , addFlag } from '../utils' ; export function app ( ... definitions ) { const { commands , flags } = reduce ( toType , { flags : { } , commands : [ ] } , definitions ) ; return new ReginnApp ( commands , flags ) ; } function toType ( acc , definition ) { if ( definition . type === 'flag' ) { return addFlag ( acc , definition ) ; } if ( definition . type === 'command' ) { acc . commands = acc . commands . concat ( [ definition ] ) ; } if ( definition . type === 'app' ) { return deepMerge ( acc , definition ) ; } return acc ; } class ReginnApp implements App { public type : 'app' = 'app' ; public commands : Array < Command > ; public flags : CommandFlags ; constructor ( commands , flags ) { this . commands = commands ; this . flags = flags ; } }