packages feed

console-program 0.3.1.1 → 0.3.1.2

raw patch · 5 files changed

+28/−20 lines, 5 files

Files

Examples/Full.hs view
@@ -1,16 +1,16 @@ module Full where  --- Used modules from the console-program package.-import           System.Console.Command  (Commands,Tree(Node),Command(..),execute,showUsage,io)+import           System.Console.Command+  (+    Commands,Tree(Node),Command(..),withOption,withNonOption,io+  )+import           System.Console.Program (single,showUsage) import qualified System.Console.Argument as Argument --- Standard tree type, used to build the tree of commands.-import Data.Tree (Tree(Node)) - main :: IO ()-main = execute defaults myCommands+main = single myCommands  myCommands :: Commands myCommands = Node@@ -38,9 +38,17 @@   } help = Command "help" "Show usage info" $ io (showUsage myCommands) -verboseOpt :: Option-verboseOpt = Argument.option Verbosity   ['v'] ["verbose"    ] verbosity        "Specify the verbosity of the program; " +-- Custom data type to describe a verbosity level.+data Verbosity+  = Quiet+  | Normal+  | Verbose+  deriving (Eq)++verboseOpt :: Argument.Option Verbosity+verboseOpt = Argument.option ['v'] ["verbose"] verbosity Normal "Specify the verbosity of the program."+ verbosity :: Argument.Type Verbosity verbosity = Argument.Type   {@@ -49,6 +57,6 @@       "normal"  -> Right Normal       "quiet"   -> Right Quiet       s         -> Left $ "The argument " ++ show s ++ " could not be recognised as a verbosity."-  , Argument.name         = "verbosity"+  , Argument.name         = "VERBOSITY"   , Argument.defaultValue = Just Verbose   }
Examples/Simple.hs view
@@ -2,7 +2,7 @@   import System.Console.Command (Commands,Tree(Node),Command(..),io)-import System.Program         (single)+import System.Console.Program (single)   myCommands :: Commands
console-program.cabal view
@@ -1,5 +1,5 @@ Name:            console-program-Version:         0.3.1.1+Version:         0.3.1.2 Cabal-Version:   >= 1.6 License:         BSD3 Author:          Arie Peterson
src/System/Console/ConfigFile.hs view
@@ -17,7 +17,7 @@ import           Data.Maybe          (isJust) import qualified Data.Tree     as Tree import qualified Fez.Data.Conf as Fez-import           System.Directory    (getHomeDirectory)+import           System.Directory    (getAppUserDataDirectory) import           System.IO.Error     (isDoesNotExistError)  @@ -25,9 +25,9 @@  readFromFile :: Commands -> UserCommand -> IO [String] readFromFile commands command = do-  home <- getHomeDirectory-  let configFile = '.' : name (Tree.rootLabel commands)-  fileContents <- either (const "") id <$> tryJust (guard . isDoesNotExistError) (readFile $ home ++ "/" ++ configFile)+  dataDir <- getAppUserDataDirectory $ name (Tree.rootLabel commands)+  let configFile = dataDir ++ "/" ++ "config"+  fileContents <- either (const "") id <$> tryJust (guard . isDoesNotExistError) (readFile configFile)   return $ Fez.parseToArgs . unlines $ filterSections command fileContents  filterSections :: UserCommand -> String -> [String]
src/System/Console/Program.hs view
@@ -129,11 +129,11 @@   opts c = let o = options $ action c in if null o     then id     else flip (PP.<$>) . PP.indent 2 . PP.vsep . map opt $ o-  opt (GetOpt.Option short long a descr) = list 5 "-" arg (map (: []) short)-    PP.<+> list 20 "--" arg long PP.<+> PP.string descr where-    arg = case a of+  opt (GetOpt.Option short long a descr) = list 5 "-" (arg id) (map (: []) short)+    PP.<+> list 20 "--" (arg (PP.equals PP.<>)) long PP.<+> PP.string descr where+    arg maybeEq = case a of       GetOpt.NoArg _    -> PP.empty-      GetOpt.ReqArg _ x -> PP.equals PP.<> PP.string x-      GetOpt.OptArg _ x -> PP.brackets (PP.equals PP.<> PP.string x)+      GetOpt.ReqArg _ x -> maybeEq $ PP.string x+      GetOpt.OptArg _ x -> PP.brackets (maybeEq $ PP.string x)   list i p a = PP.fill i . PP.cat . PP.punctuate PP.comma . map (\ x -> PP.text p PP.<> PP.text x PP.<> a)   subcs ns = if null ns then id else flip (PP.<$>) $ PP.indent 2 (PP.vsep $ map usage ns)