-- |
-- Module      : Application.CLI.Class
-- License     : BSD-Style
-- Copyright   : Copyright © 2014 Nicolas DI PRIMA
--
-- Maintainer  : Nicolas DI PRIMA <nicolas@di-prima.fr>
-- Stability   : experimental
-- Portability : unknown
--
module Application.CLI.Class
    ( CLI (..)
    , cliToCommand
    ) where

import Application.CLI.Types

-- | This is the CLI Class
-- All command you want to add into the CLIContext must be an instance of this
-- class.
class CLI cli where
    -- | This is the name of the command. It is also the command line option
    -- the action will be triggered every time this string is found to be the
    -- first argument of the program
    name    :: cli
            -> String
    -- | A description of this command
    -- Will be use in the default Usage and the Help function
    desc    :: cli
            -> String
    -- | The list of Options
    -- It is only for printing, the parser won't use this to parse the command
    -- parameters.
    options :: cli
            -> [OptHelp]
    -- | The action to perfom every time the @name@ is found to be the first
    -- string of the program parameters
    action  :: cli
            -> CLIContext -- ^ This could be use in order to know all the different available commands etc...
            -> Options    -- ^ The Command Parameters
            -> IO ()

-- | Make the transformation of a CLI instance to a Command
-- object
cliToCommand :: CLI cli
             => cli
             -> Command
cliToCommand cli =
    Command
        { cmdName    = name cli
        , cmdDesc    = desc cli
        , cmdOptions = options cli
        , cmdAction  = action cli
        }