hpaco / CommandArgs.hs

{-#LANGUAGE DeriveDataTypeable, StandaloneDeriving #-}
module CommandArgs ( CommandArgs (..)
                   , parseArgs
                   )
where

import System.Console.CmdArgs.Implicit
import System.Environment
import qualified Text.HPaco.Writers.PHP as PHP
import System.FilePath

deriving instance Show PHP.WrapMode
deriving instance Data PHP.WrapMode
deriving instance Typeable PHP.WrapMode

data CommandArgs = CommandArgs { caInputFiles :: [FilePath]
                               , caTemplateName :: Maybe String
                               , caIncludeExtension :: Maybe String
                               , caPhpPretty :: Bool
                               , caPhpNoPreamble :: Bool
                               , caPhpWrapMode :: PHP.WrapMode
                               , caPhpExposeAllFunctions :: Bool
                               }
                               deriving (Show, Data, Typeable)

parseArgs = cmdArgs argsParser

argsParser = CommandArgs { caTemplateName = def
                             &= name "template-name"
                             &= help "Template name used in output"
                             &= explicit
                         , caIncludeExtension = def
                             &= name "include-ext"
                             &= help "Extension to append to included templates"
                             &= explicit
                         , caPhpPretty = def
                             &= name "php-pretty"
                             &= help "Output pretty-printed PHP"
                             &= explicit
                             &= groupname "PHP writer options"
                         , caPhpExposeAllFunctions = def
                             &= name "php-expose-all-functions"
                             &= help "Expose all defined PHP functions from the host to the template"
                             &= explicit
                             &= groupname "PHP writer options"
                         , caPhpNoPreamble = def
                             &= name "php-no-preamble"
                             &= help "Skip PHP preamble (defines functions used in template)"
                             &= explicit
                             &= groupname "PHP writer options"
                         , caPhpWrapMode =
                             enum [ PHP.WrapNone
                                        &= name "php-raw"
                                        &= help "Output raw PHP without any wrapper"
                                        &= explicit
                                  , PHP.WrapFunction
                                        &= name "php-func"
                                        &= help "Wrap PHP code in a function"
                                        &= explicit
                                  , PHP.WrapClass
                                        &= name "php-class"
                                        &= help "Wrap PHP code in a class"
                                        &= explicit
                                  ]
                             &= groupname "PHP writer options"
                         , caInputFiles = def
                             &= args
                         }
                         &= program "hpaco"
                         &= details [ "a compiler for the paco template language" ]
                         &= summary "hpaco 0.6.1.1 Copyright (c) 2012 by Tobias Dammers. All rights reserved"
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.