1
1
mirror of https://github.com/Yvee1/hascard.git synced 2024-10-06 03:58:29 +03:00

Make command optional

This commit is contained in:
Steven van den Broek 2020-09-12 22:52:27 +02:00
parent aa36610388
commit afd48ae65b
5 changed files with 16 additions and 10 deletions

View File

@ -22,7 +22,7 @@ data Command = Command
| Import ImportOpts
data Opts = Opts
{ _optCommand :: Command
{ _optCommand :: Maybe Command
, _optVersion :: Bool
}
@ -51,15 +51,19 @@ main = do
options <- execParser optsWithHelp
case (options ^. optVersion, options ^. optCommand) of
(True, _) -> putStrLn (showVersion version)
(_, Run rOpts) -> run rOpts
(_, Import iOpts) -> doImport iOpts
(True, _) -> putStrLn (showVersion version)
(_, Just (Run rOpts)) -> run rOpts
(_, Just (Import iOpts)) -> doImport iOpts
(_, Nothing) ->
do g <- createSystemRandom
let gs = GlobalState {_mwc=g, _states=Map.empty, _stack=Stack.empty, _parameters= defaultParameters }
start Nothing gs
opts :: Parser Opts
opts = Opts
<$> hsubparser
<$> optional (hsubparser
( command "run" (info (Run <$> runOpts) ( progDesc "Run hascard directly on a file"))
<> command "import" (info (Import <$> importOpts) (progDesc "Convert a delimited file to syntax compatible with hascard")))
<> command "import" (info (Import <$> importOpts) (progDesc "Convert a delimited file to syntax compatible with hascard"))))
<*> switch (long "version" <> short 'v' <> help "Show version number")
runOpts :: Parser RunOpts

View File

@ -86,5 +86,5 @@ entryFilter acceptHidden info = (fileExtensionMatch "txt" info || fileExtensionM
'.' : _ -> False
_ -> True)
parameterState :: FilePath -> [Card] -> State
parameterState fp cards = ParameterState (PS cards fp (mkParameterForm (length cards) defaultParameters))
parameterState :: Parameters -> FilePath -> [Card] -> State
parameterState ps fp cards = ParameterState (PS cards fp (mkParameterForm (length cards) ps))

View File

@ -14,6 +14,8 @@ module UI
, cardsToString
, parseImportInput
, defaultParameters
) where
import UI.CardSelector as X (addRecent)

View File

@ -92,7 +92,7 @@ handleEvent gs s@CSS{_list=l, _exception=exc} (VtyEvent ev) =
Right result -> continue =<< liftIO (do
s'' <- addRecentInternal s' fp
let gs' = update s''
return (gs' `goToState` parameterState fp result))
return (gs' `goToState` parameterState (gs'^.parameters) fp result))
_ -> continue' s'
handleEvent gs _ _ = continue gs

View File

@ -79,7 +79,7 @@ handleEvent gs s@FBS{_fb=b, _exception'=excep} (VtyEvent ev) =
Right result -> continue =<< liftIO (do
addRecent fp
let gs' = update s'
return (gs' `moveToState` parameterState fp result))
return (gs' `moveToState` parameterState (gs'^.parameters) fp result))
_ -> halt' gs
_ -> continue' s'