import { middleware, Middleware as GenericMiddleware } from './utils/middleware'

export { help } from './middlewares/helper'

export type CommandFunction = (options: ICLIOptions, ...args: any[]) => any
export type CLIParams = string[]
export type CommandsModule = ICommandsDictionary | CommandFunction
export type Middleware = GenericMiddleware<IMiddlewareArguments>

export interface ICLIOptions {
  [key: string]: number | string | boolean
}

export interface ICommandsDictionary {
  [namespace: string]: CommandsModule
}

export interface IMiddlewareArguments {
  options: ICLIOptions
  params: CLIParams
  definition: CommandsModule
  namespace: string
  command: CommandFunction
}

export class CLIError extends Error {}

export function cli(
  definition: CommandsModule,
  middlewares: Middleware[] = []
) {
  middleware<IMiddlewareArguments>(middlewares)({
    command: () => null,
    definition,
    namespace: '',
    options: {},
    params: []
  })
}

import { middleware, Middleware as GenericMiddleware } from './utils/middleware'

export { help } from './middlewares/helper'

export type CommandFunction = (options: ICLIOptions, ...args: any[]) => any
export type CLIParams = string[]
export type CommandsModule = ICommandsDictionary | CommandFunction
export type Middleware = GenericMiddleware<IMiddlewareArguments>

export interface ICLIOptions {
  [key: string]: number | string | boolean
}

export interface ICommandsDictionary {
  [namespace: string]: CommandsModule
}

export interface IMiddlewareArguments {
  options: ICLIOptions
  params: CLIParams
  definition: CommandsModule
  namespace: string
  command: CommandFunction
}

export interface IInterpreterArguments extends IMiddlewareArguments {
  middlewares?: Middleware[]
}

export class CLIError extends Error {}

export function cli(definition: CommandsModule) {
  middleware<IMiddlewareArguments>([])({
    command: () => null,
    definition,
    namespace: '',
    options: {},
    params: []
  })
}

--- 
+++ 
@@ -23,14 +23,13 @@
   command: CommandFunction
 }
 
-export interface IInterpreterArguments extends IMiddlewareArguments {
-  middlewares?: Middleware[]
-}
-
 export class CLIError extends Error {}
 
-export function cli(definition: CommandsModule) {
-  middleware<IMiddlewareArguments>([])({
+export function cli(
+  definition: CommandsModule,
+  middlewares: Middleware[] = []
+) {
+  middleware<IMiddlewareArguments>(middlewares)({
     command: () => null,
     definition,
     namespace: '',
Add middlewares argument to cli function
