From d9cd40f9d84e104207f8ef34c6d5a4f9d1b3af4b Mon Sep 17 00:00:00 2001 From: Brad Richardson Date: Tue, 25 Feb 2020 11:18:40 -0800 Subject: Add bare minimum of command line parsing --- app/Main.hs | 41 +++++++++++++++++++++++++++++++++++++++-- package.yaml | 1 + stack.yaml | 2 +- stack.yaml.lock | 8 ++++---- 4 files changed, 45 insertions(+), 7 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index de1c1ab..9d9c5dc 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,6 +1,43 @@ module Main where -import Lib +import Options.Applicative + +newtype Arguments = Arguments { command' :: Command } + +data Command = Run | Test | Build main :: IO () -main = someFunc +main = do + args <- getArguments + run args + +run :: Arguments -> IO () +run args = case command' args of + Run -> putStrLn "Run" + Test -> putStrLn "Test" + Build -> putStrLn "Build" + +getArguments :: IO Arguments +getArguments = execParser + (info + (arguments <**> helper) + (fullDesc <> progDesc "Work with Fortran projects" <> header + "fpm - A Fortran package manager and build system" + ) + ) + +arguments :: Parser Arguments +arguments = subparser + ( command "run" (info runArguments (progDesc "Run the executable")) + <> command "test" (info testArguments (progDesc "Run the tests")) + <> command "build" (info buildArguments (progDesc "Build the executable")) + ) + +runArguments :: Parser Arguments +runArguments = pure $ Arguments Run + +testArguments :: Parser Arguments +testArguments = pure $ Arguments Test + +buildArguments :: Parser Arguments +buildArguments = pure $ Arguments Build diff --git a/package.yaml b/package.yaml index ab3a1d0..2cf73a8 100644 --- a/package.yaml +++ b/package.yaml @@ -21,6 +21,7 @@ description: Please see the README on GitHub at = 4.7 && < 5 +- optparse-applicative library: source-dirs: src diff --git a/stack.yaml b/stack.yaml index 465f104..0094ee9 100644 --- a/stack.yaml +++ b/stack.yaml @@ -17,7 +17,7 @@ # # resolver: ./custom-snapshot.yaml # resolver: https://example.com/snapshots/2018-01-01.yaml -resolver: lts-15.1 +resolver: lts-12.26 # User packages to be built. # Various formats can be used as shown in the example below. diff --git a/stack.yaml.lock b/stack.yaml.lock index 7e51098..6bee1e8 100644 --- a/stack.yaml.lock +++ b/stack.yaml.lock @@ -6,7 +6,7 @@ packages: [] snapshots: - completed: - size: 489011 - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/15/1.yaml - sha256: d4ecc42b7125d68e4c3c036a08046ad0cd02ae0d9efbe3af2223a00ff8cc16f3 - original: lts-15.1 + size: 509471 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/12/26.yaml + sha256: 95f014df58d0679b1c4a2b7bf2b652b61da8d30de5f571abb0d59015ef678646 + original: lts-12.26 -- cgit v1.2.3