Skip to content

Commit

Permalink
feat(app): Add version output
Browse files Browse the repository at this point in the history
  • Loading branch information
sgillespie committed Jun 18, 2023
1 parent 05e2f07 commit e23b6a3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 21 deletions.
42 changes: 26 additions & 16 deletions app/Main.hs
Original file line number Diff line number Diff line change
@@ -1,34 +1,44 @@
module Main (main) where

import Graphics.Seangine (SeangineCli (..))
import Data.Version
import Graphics.Seangine (SeangineOptions (..), runSeangine)
import Options.Applicative
import PackageInfo_seangine

data SeangineCli = OptVersion | OptRun SeangineOptions
deriving (Eq)

main :: IO ()
main = run =<< execParser opts'
where
opts' = info (parser <**> helper) infoMods
infoMods =
fullDesc
<> header "Seangine - A Vulkan GlTF viewer"
opts' = info (cliParser <**> helper) infoMods
infoMods = fullDesc <> header "Seangine - A Vulkan GlTF viewer"

run :: SeangineCli -> IO ()
run _ = pass
run (OptRun opts) = runSeangine opts
run OptVersion = printVersion

cliParser :: Parser SeangineCli
cliParser = versionParser <|> (OptRun <$> regularParser)

regularParser :: Parser SeangineOptions
regularParser = SeangineOptions <$> fileParser <*> deviceParser <*> debugParser

parser :: Parser SeangineCli
parser = SeangineCli <$> file <*> device <*> debug <*> version
versionParser :: Parser SeangineCli
versionParser = flag' OptVersion $ long "version" <> short 'V' <> help "Print version"

debug :: Parser Bool
debug =
debugParser :: Parser Bool
debugParser =
switch $
long "verbose"
<> short 'v'
<> help "Debug logging (requires vulkan-validation-layers)"

version :: Parser Bool
version = switch $ long "version" <> short 'V' <> help "Print version"
fileParser :: Parser FilePath
fileParser = strArgument $ metavar "FILE"

file :: Parser FilePath
file = strArgument $ metavar "FILE"
deviceParser :: Parser (Maybe String)
deviceParser = optional $ strOption $ long "device" <> short 'd' <> help "Vulkan device"

device :: Parser (Maybe String)
device = optional $ strOption $ long "device" <> short 'd' <> help "Vulkan device"
printVersion :: IO ()
printVersion = putStrLn $ name <> " " <> showVersion version
2 changes: 1 addition & 1 deletion fourmolu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import-export-style: trailing
indent-wheres: true

# Whether to leave a space before an opening record brace
record-brace-space: true
record-brace-space: false

# Number of spaces between top-level declarations
newlines-between-decls: 1
Expand Down
1 change: 1 addition & 0 deletions seangine.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ library
executable seangine
import: common-options
main-is: Main.hs
other-modules: PackageInfo_seangine
build-depends:
optparse-applicative,
seangine
Expand Down
14 changes: 10 additions & 4 deletions src/Graphics/Seangine.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
module Graphics.Seangine (SeangineCli (..)) where
module Graphics.Seangine
( SeangineOptions (..),
runSeangine,
) where

data SeangineCli = SeangineCli
data SeangineOptions = SeangineOptions
{ optFile :: !FilePath,
optDevice :: !(Maybe String),
optDebug :: !Bool,
optVersion :: !Bool
optDebug :: !Bool
}
deriving (Eq)

runSeangine :: SeangineOptions -> IO ()
runSeangine _ = pass

0 comments on commit e23b6a3

Please sign in to comment.