Skip to content

Instantly share code, notes, and snippets.

@AndrewRademacher
Created October 6, 2015 18:11
Show Gist options
  • Save AndrewRademacher/8a8391713ca9e1e9e903 to your computer and use it in GitHub Desktop.
Save AndrewRademacher/8a8391713ca9e1e9e903 to your computer and use it in GitHub Desktop.
{-# 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