1- module Spago.Command.Path (showPaths , getOutputPath ) where
1+ module Spago.Command.Path (showPaths , getOutputPath , findFlag ) where
22
33import Spago.Prelude
44import Spago.Env
@@ -43,7 +43,7 @@ getOutputPath buildOpts = do
4343 Just path -> Text. unpack path
4444
4545
46- -- TODO tests:
46+ -- See tests in: test/Spago/Command/PathSpec.hs
4747-- ["-o", "something"]
4848-- ["--output", "something"]
4949-- ["--output something"]
@@ -53,18 +53,34 @@ getOutputPath buildOpts = do
5353-- | Try to find the content of a certain flag in a list of PursArgs
5454findFlag :: Char -> Text -> [PursArg ] -> Maybe Text
5555findFlag char string = \ case
56- [] -> Nothing
57- [_] -> Nothing
58- (x: y: xs) -> if isFlag x
59- then Just (unPursArg y)
60- else findFlag char string (y : xs)
61- where
56+ (x: xs) -> if isFlag x
57+ then case xs of
58+ (y: _) -> Just (unPursArg y)
59+ _ -> Nothing
60+ else if hasFlag x
61+ then case Text. words (unPursArg x) of
62+ [word] -> case Text. split (== ' =' ) word of
63+ [_,value] -> Just value
64+ _ -> Nothing
65+ (_: value: _) -> Just value
66+ _ -> Nothing
67+ else findFlag char string xs
68+ _ -> Nothing
69+ where
6270 isFlag :: PursArg -> Bool
63- isFlag (PursArg a)
71+ isFlag (PursArg word)
72+ = word == (Text. pack [' -' , char])
73+ || word == (" --" <> string)
74+ hasFlag :: PursArg -> Bool
75+ hasFlag (PursArg a)
6476 = firstWord == (Text. pack [' -' , char])
6577 || firstWord == (" --" <> string)
6678 where
6779 firstWord
6880 = fromMaybe " " $ case Text. words a of
6981 [] -> Nothing
70- (word: _) -> Just word
82+ [word] -> case Text. split (== ' =' ) word of
83+ [one] -> Just one
84+ [key,_] -> Just key
85+ _ -> Nothing
86+ (word: _) -> Just word
0 commit comments