diff options
Diffstat (limited to 'scratch/brilliant')
-rw-r--r-- | scratch/brilliant/.ghci | 2 | ||||
-rw-r--r-- | scratch/brilliant/Main.hs | 45 | ||||
-rw-r--r-- | scratch/brilliant/shell.nix | 9 |
3 files changed, 56 insertions, 0 deletions
diff --git a/scratch/brilliant/.ghci b/scratch/brilliant/.ghci new file mode 100644 index 000000000000..efc88e630ccb --- /dev/null +++ b/scratch/brilliant/.ghci @@ -0,0 +1,2 @@ +:set prompt "> " +:set -Wall diff --git a/scratch/brilliant/Main.hs b/scratch/brilliant/Main.hs new file mode 100644 index 000000000000..999771f55836 --- /dev/null +++ b/scratch/brilliant/Main.hs @@ -0,0 +1,45 @@ +{-# LANGUAGE RecordWildCards #-} +-------------------------------------------------------------------------------- +module Main where +-------------------------------------------------------------------------------- +import Options.Applicative +import Data.Semigroup ((<>)) + +import qualified System.Environment as Env +-------------------------------------------------------------------------------- + +data CommandArgs = CommandArgs + { hello :: String + , quiet :: Bool + , enthusiasm :: Int + } deriving (Eq, Show) + +parseArgs :: Parser CommandArgs +parseArgs = + CommandArgs <$> strOption + ( long "hello" + <> metavar "TARGET" + <> help "Target for the greeting" ) + <*> switch + ( long "quiet" + <> short 'q' + <> help "Whether to be quiet" ) + <*> option auto + ( long "enthusiasm" + <> help "How enthusiastic to greet" + <> showDefault + <> value 1 + <> metavar "INT" ) + +main :: IO () +main = do + args <- execParser opts + greet args + where + opts = info (parseArgs <**> helper) + ( fullDesc + <> progDesc "Print a greeting for TARGET" + <> header "header - a test for optparse-applicative" ) + +greet :: CommandArgs -> IO () +greet CommandArgs{..} = putStrLn $ "Hello, " ++ hello ++ replicate enthusiasm '!' diff --git a/scratch/brilliant/shell.nix b/scratch/brilliant/shell.nix new file mode 100644 index 000000000000..58a2e9a6a573 --- /dev/null +++ b/scratch/brilliant/shell.nix @@ -0,0 +1,9 @@ +let + pkgs = import /home/wpcarro/nixpkgs {}; +in pkgs.mkShell { + buildInputs = with pkgs; [ + (haskellPackages.ghcWithPackages (hpkgs: with hpkgs; [ + optparse-applicative + ])) + ]; +} |