Created
October 6, 2015 18:11
-
-
Save AndrewRademacher/8a8391713ca9e1e9e903 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE DeriveDataTypeable #-} | |
{-# LANGUAGE DeriveGeneric #-} | |
import Control.Lens | |
import Control.Monad | |
import Data.Data | |
import Data.Text (Text) | |
import Data.Word | |
import GHC.Generics | |
import System.Console.CmdLib | |
import Shared.Rules | |
data Commands | |
= Foo | |
{ cmdWibble :: Bool | |
} | |
| Bar | |
{ cmdWibble :: Bool | |
, cmdText :: String | |
} | |
deriving (Eq, Show, Read, Data, Typeable, Generic) | |
instance Attributes Commands where | |
attributes _ = group "Commands" | |
[ cmdWibble %> [ Short "w" | |
, Long [ "wibble" ] | |
, Help ("Shall I wibble."::String) | |
] | |
, cmdText %> [ Short "t" | |
, Long [ "text" ] | |
, Help ("What should I wibble about?"::String) | |
, ArgHelp "TEXT" | |
] | |
] | |
instance RecordCommand Commands where | |
mode_summary (Foo{}) = "Foo." | |
mode_summary (Bar{}) = "Bar." | |
main :: IO () | |
main = getArgs >>= dispatchR [] >>= \cmd -> case cmd of | |
Foo{} -> putStrLn $ "Foo running. Wibble = " ++ show (cmdWibble cmd) | |
Bar{} -> putStrLn $ "This is bar: " ++ show (cmdText cmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment