Skip to content

Commit 996a587

Browse files
committed
Add GLB support to CLI app
1 parent 67486dd commit 996a587

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

app/Command/GLTF/Loader/App.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import RIO.Process
55

66
-- | Command line arguments
77
data Options = Options
8-
{ optionsSummary :: !Bool,
8+
{ optionsBinary :: !Bool,
9+
optionsSummary :: !Bool,
910
optionsVerbose :: !Bool,
1011
optionsFile :: FilePath
1112
}
@@ -29,6 +30,11 @@ instance HasProcessContext App where
2930
instance HasOptions App where
3031
optionsL = lens appOptions (\app opts -> app { appOptions = opts })
3132

33+
_optionsBinary :: Lens' Options Bool
34+
_optionsBinary = lens
35+
optionsBinary
36+
(\opts bin -> opts { optionsBinary = bin })
37+
3238
_optionsSummary :: Lens' Options Bool
3339
_optionsSummary = lens
3440
optionsSummary

app/Command/GLTF/Loader/Run.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ run :: RIO App ()
1313
run = do
1414
options <- asks (^. optionsL)
1515
let file = options ^. _optionsFile
16+
binary = options ^. _optionsBinary
1617
summary = options ^. _optionsSummary
1718
verbose = options ^. _optionsVerbose
19+
fromFile = if binary
20+
then fmap (over _Right (^. _gltf)) . fromBinaryFile
21+
else fromJsonFile
1822

1923
logInfo $ "File: " <> fromString file
20-
result <- liftIO $ fromJsonFile file
24+
result <- liftIO $ fromFile file
2125

2226
either reportError (reporter verbose summary) result
2327

app/Main.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,16 @@ runApp processContext cliOptions logOptions appAction
4040

4141
options :: Parser Options
4242
options = Options
43-
<$> switch summaryOption
43+
<$> switch binaryOption
44+
<*> switch summaryOption
4445
<*> switch verboseOption
4546
<*> strArgument fileArg
4647

48+
binaryOption :: Mod FlagFields Bool
49+
binaryOption = long "binary"
50+
<> short 'b'
51+
<> help "Load file as GLB (Binary glTF)"
52+
4753
summaryOption :: Mod FlagFields Bool
4854
summaryOption
4955
= long "summary"

0 commit comments

Comments
 (0)