Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add version flag #29

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions app/App/Arguments.hs
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
module App.Arguments (execArgParser) where

import Data.Version (showVersion)
import Options.Applicative
import Paths_static_ls (version)
import StaticLS.StaticEnv.Options
import System.Environment
import System.Exit
import Text.Parsec hiding (many, option)

currVersion :: String
currVersion = showVersion version

data PrgOptions = PrgOptions
{ staticEnvOpts :: StaticEnvOptions
, showVer :: Bool
, showHelp :: Bool
}

Expand All @@ -24,6 +30,10 @@ execArgParser =
-- Get the help text (optparse-applicative usually shows the help text on error)
handleParseResult . Failure $
parserFailure defaultPrefs progParseInfo (ShowHelpText Nothing) mempty
handleParseResultWithSuppression (Success (PrgOptions{showVer = True})) = do
-- Show version info
putStrLn $ "static-ls, version " <> currVersion
exitSuccess
handleParseResultWithSuppression (Success a) = return a.staticEnvOpts
-- Ignore if invalid arguments are input
handleParseResultWithSuppression (Failure _) = return defaultStaticEnvOptions
Expand All @@ -46,6 +56,13 @@ argParser :: Parser PrgOptions
argParser =
PrgOptions
<$> staticEnvOptParser
<*> flag
False
True
( long "version"
<> short 'v'
<> help "Show the program version"
)
<*> flag
False
True
Expand Down
2 changes: 2 additions & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ executable:
dependencies:
- static-ls
- optparse-applicative >= 0.17.0.0 && < 0.19
generated-other-modules:
- Paths_static_ls

tests:
static-ls-test:
Expand Down
8 changes: 7 additions & 1 deletion static-ls.cabal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cabal-version: 1.12
cabal-version: 2.0

-- This file has been generated from package.yaml by hpack version 0.36.0.
--
Expand Down Expand Up @@ -50,6 +50,8 @@ library
StaticLS.StaticEnv.Options
other-modules:
Paths_static_ls
autogen-modules:
Paths_static_ls
hs-source-dirs:
src
default-extensions:
Expand Down Expand Up @@ -91,6 +93,8 @@ executable static-ls
other-modules:
App.Arguments
Paths_static_ls
autogen-modules:
Paths_static_ls
hs-source-dirs:
app
default-extensions:
Expand Down Expand Up @@ -144,6 +148,8 @@ test-suite static-ls-test
TestImport.HieDb
TestImport.TestData
Paths_static_ls
autogen-modules:
Paths_static_ls
hs-source-dirs:
test
default-extensions:
Expand Down
Loading