hpaco / CommandArgs.hs

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

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

deriving instance Show WrapMode
deriving instance Data WrapMode
deriving instance Typeable WrapMode

programVersion = "0.10.0.4"

data OutputFormat = OutputPHP | OutputJavascript | RunInterpreted
                  deriving (Show, Data, Typeable)

data CommandArgs = CommandArgs { caInputFiles :: [FilePath]
                               , caTemplateName :: Maybe String
                               , caOptimizationLevel :: Int
                               , caOutputFormat :: OutputFormat
                               , caIncludeExtension :: Maybe String
                               , caPhpPretty :: Bool
                               , caPhpNoPreamble :: Bool
                               , caPhpWrapMode :: WrapMode
                               , caPhpExposeAllFunctions :: Bool
                               , caJsPretty :: Bool
                               , caJsWrapMode :: WrapMode
                               , caRunData :: String
                               }
                               deriving (Show, Data, Typeable)

parseArgs = cmdArgs argsParser

argsParser = CommandArgs { caTemplateName = def
                             &= name "template-name"
                             &= help "Template name used in output"
                             &= explicit
                         , caOptimizationLevel = def
                             &= name "O"
                             &= help "Optimization level (currently 0 and 1 supported)"
                             &= explicit
                         , caIncludeExtension = def
                             &= name "include-ext"
                             &= help "Extension to append to included templates"
                             &= explicit
                         , caOutputFormat = enum
                                             [ OutputPHP
                                                    &= name "php"
                                                    &= help "Compile to PHP"
                                                    &= explicit
                                             , OutputJavascript
                                                    &= name "js"
                                                    &= help "Compile to JavaScript"
                                                    &= explicit
                                             , RunInterpreted
                                                    &= name "run"
                                                    &= help "Run directly (act as an interpreter)"
                                                    &= 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 [ WrapNone
                                        &= name "php-raw"
                                        &= help "Output raw PHP without any wrapper"
                                        &= explicit
                                  , WrapFunction
                                        &= name "php-func"
                                        &= help "Wrap PHP code in a function"
                                        &= explicit
                                  , WrapClass
                                        &= name "php-class"
                                        &= help "Wrap PHP code in a class"
                                        &= explicit
                                  ]
                             &= groupname "PHP writer options"
                         , caJsPretty = def
                             &= name "js-pretty"
                             &= help "Output pretty-printed Javascript"
                             &= explicit
                             &= groupname "Javascript writer options"
                         , caJsWrapMode =
                             enum [ WrapNone
                                        &= name "js-raw"
                                        &= help "Output raw Javascript without any wrapper"
                                        &= explicit
                                  , WrapFunction
                                        &= name "js-func"
                                        &= help "Wrap Javascript code in a function"
                                        &= explicit
                                  ]
                             &= groupname "Javascript writer options"
                         , caRunData = def
                            &= name "data"
                            &= help "Initial scope"
                            &= explicit
                         , caInputFiles = def
                             &= args
                         }
                         &= program "hpaco"
                         &= details [ "a compiler for the paco template language" ]
                         &= summary ("hpaco " ++ programVersion ++ " 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.