structured-cli 0.9.3.1 → 0.9.4.0
raw patch · 2 files changed
+24/−17 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ System.Console.StructuredCLI: Options :: String -> [String] -> ParseResult
Files
- src/System/Console/StructuredCLI.hs +23/−16
- structured-cli.cabal +1/−1
src/System/Console/StructuredCLI.hs view
@@ -133,6 +133,7 @@ data ParseResult = Done String String | Fail String (Maybe String)+ | Options String [String] | Partial deriving Show @@ -282,7 +283,7 @@ parse remaining tryParse :: (MonadIO m) => String -> [Node m] -> m [Node m]-tryParse [] (x:_) = return [x]+tryParse "" (x:_) = return $ branches x tryParse _ [] = return [] tryParse " " (x:_) = return $ branches x tryParse input (n:_) = do@@ -301,13 +302,16 @@ case result of Fail _ _ -> return acc+ Options _ strs -> do+ let nodes = fakeNode node <$> strs+ return $ nodes ++ acc _ -> return $ node:acc -currentBranches :: (Monad m) => (CState m) [Node m]+currentBranches :: (MonadIO m) => (CState m) [Node m] currentBranches = getCurrentCommand >>= return . branches -currentBranches'' :: (Monad m,+currentBranches'' :: (MonadIO m, MonadTrans t, MonadTrans u, Monad (u (CState m))) =>@@ -334,10 +338,10 @@ case result of Done matched remaining -> return (node, matched, remaining)- Fail _ _ ->- findNode input rest $ (Just result):results Partial -> error $ "Partial match during exact parsing of " ++ input ++ " at or around " ++ label+ _ ->+ findNode input rest $ (Just result):results findNode' :: (MonadIO m) => String -> [Node m] -> m (Maybe (Node m, String)) findNode' _ [] = return Nothing@@ -345,12 +349,18 @@ result <- (runParser parser) False node input case result of Done _ remaining ->- return $ Just (node, remaining)+ return $ Just (node, remaining)+ Options input' strs -> do+ let nodes = fakeNode node <$> strs+ findNode' input' nodes Partial -> error $ "Partial match during exact parsing of " ++ input ++ " at or around " ++ label- Fail _ _ ->- findNode' input rest+ _ ->+ findNode' input rest +fakeNode :: (MonadIO m) => Node m -> String -> Node m+fakeNode node str = node { label = str, parser = Parser labelParser }+ pushCommand' :: (MonadTrans t, Monad m) => Node m -> String -> t (CState m) () pushCommand' n = lift . pushCommand n @@ -372,15 +382,12 @@ explorer :: (MonadIO m) => (String, String) -> CState m (String, [Completion]) explorer input@(left, _) = do- nodes <- gets nodes- options <- lift $ getPossibilities left nodes- let keywords = getLabels options- complete = completeWord Nothing " " $ \str ->+ nodes <- gets nodes+ options <- lift $ getPossibilities left nodes+ let keywords = sort $ fmap label options+ let complete = completeWord Nothing " " $ \str -> return $ map simpleCompletion $ filter (str `isPrefixOf`) keywords- r <- complete input- return r- where- getLabels = sort . fmap label+ complete input getPossibilities :: (MonadIO m) => String -> [Node m] -> m [Node m] getPossibilities "" = return . branches . head
structured-cli.cabal view
@@ -1,5 +1,5 @@ name: structured-cli-version: 0.9.3.1+version: 0.9.4.0 synopsis: Application library for building interactive console CLIs description: This module provides the tools to build a complete "structured" CLI application, similar to those found in systems like Cisco IOS or console configuration utilities etc. It aims to be easy for implementors to use. homepage: https://gitlab.com/codemonkeylabs/structured-cli#readme