From a3ea46fc6423dca28c68c9d25164d59b2e042f98 Mon Sep 17 00:00:00 2001 From: Manuel Leduc Date: Tue, 3 May 2016 14:05:38 +0200 Subject: [PATCH] optparse and haskeline working well --- app/Main.hs | 40 ++++++++++++++++++++++++++++++++++++++-- kreg.cabal | 2 ++ stack.yaml | 39 ++++++--------------------------------- 3 files changed, 46 insertions(+), 35 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index de1c1ab..51f4b83 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,6 +1,42 @@ +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE OverloadedStrings #-} + module Main where -import Lib +import Options.Generic +import System.Console.Haskeline (defaultSettings, runInputT, getInputLine, outputStrLn, InputT, getPassword) +import Data.Foldable (forM_) + +data Options + = Auth + | Whoami + | Publish + | Search + deriving (Generic, Show) + + +instance ParseRecord Options + +auth :: IO () +auth = runInputT defaultSettings operations + where operations :: InputT IO () + operations = do + login <- getInputLine "login : " + password <- getPassword Nothing "password : " + case (login, password) of + (Nothing, _) -> return () + (_, Nothing) -> return () + (Just x, Just y) -> outputStrLn $ x ++ " - " ++ y + +processOptions :: Options -> IO() +processOptions x = case x of + Auth -> auth + Whoami -> putStrLn "whoami todo" + Publish -> putStrLn "publish todo" + Search -> putStrLn "search todo" + main :: IO () -main = someFunc +main = do + x <- getRecord "kreg" + processOptions x diff --git a/kreg.cabal b/kreg.cabal index a57bd51..4a7e8ee 100644 --- a/kreg.cabal +++ b/kreg.cabal @@ -25,6 +25,8 @@ executable kreg-exe ghc-options: -threaded -rtsopts -with-rtsopts=-N build-depends: base , kreg + , optparse-generic + , haskeline default-language: Haskell2010 test-suite kreg-test diff --git a/stack.yaml b/stack.yaml index 2f5c3fe..ed80082 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,35 +1,8 @@ -# This file was automatically generated by stack init -# For more information, see: http://docs.haskellstack.org/en/stable/yaml_configuration/ - -# Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2) -resolver: lts-5.15 - -# Local packages, usually specified by relative directory name -packages: -- '.' -# Packages to be pulled from upstream that are not in the resolver (e.g., acme-missiles-0.3) -extra-deps: [] - -# Override default flag values for local packages and extra-deps flags: {} - -# Extra package databases containing global packages extra-package-dbs: [] - -# Control whether we use the GHC we find on the path -# system-ghc: true - -# Require a specific version of stack, using version ranges -# require-stack-version: -any # Default -# require-stack-version: >= 1.0.0 - -# Override the architecture used by stack, especially useful on Windows -# arch: i386 -# arch: x86_64 - -# Extra directories used by stack for building -# extra-include-dirs: [/path/to/dir] -# extra-lib-dirs: [/path/to/dir] - -# Allow a newer minor version of GHC than the snapshot specifies -# compiler-check: newer-minor +packages: +- '.' +extra-deps: +- optparse-generic-1.1.0 +- text-1.2.2.1 +resolver: lts-5.15