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:
parent
aa36610388
commit
afd48ae65b
16
app/Main.hs
16
app/Main.hs
@ -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
|
||||
|
@ -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))
|
@ -14,6 +14,8 @@ module UI
|
||||
, cardsToString
|
||||
|
||||
, parseImportInput
|
||||
|
||||
, defaultParameters
|
||||
) where
|
||||
|
||||
import UI.CardSelector as X (addRecent)
|
||||
|
@ -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
|
||||
|
@ -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'
|
||||
|
Loading…
Reference in New Issue
Block a user