git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Make directive parser recognize only unambiguous commands
commit9f938b84c0cd3d948e096cc919ba57a5c9d4cdfe authorŁukasz Hanuszczak <lukasz.hanuszczak@gmail.com> dateWed 11 Mar 2015, 00:57 (12 years ago) parentfccd2f6
1 file changed+5−3
psci/Directive.hs+5−3
psci/Directive.hs+5−3
@@ -15,8 +15,7 @@
1515
1616module Directive where
1717
18−import Control.Applicative
19−import Data.List (find, isPrefixOf)
18+import Data.List (isPrefixOf)
2019
2120data Directive
2221 = Help
@@ -47,7 +46,10 @@ commands Show = ["show"]
4746-- Tries to parse given string into a directive.
4847--
4948parseDirective :: String -> Maybe Directive
50−parseDirective cmd = fst <$> find (matches . snd) mapping
49+parseDirective cmd =
50+ case filter (matches . snd) mapping of
51+ [directive] -> Just $ fst directive
52+ _ -> Nothing
5153 where
5254 mapping :: [(Directive, [String])]
5355 mapping = zip directives (map commands directives)