Simplify determineShell
This commit is contained in:
parent
ea24e25efd
commit
c95914f9b3
|
@ -239,19 +239,15 @@ prop_determineShell8 = determineShellTest' (Just Ksh) "#!/bin/sh" == Sh
|
||||||
|
|
||||||
determineShellTest = determineShellTest' Nothing
|
determineShellTest = determineShellTest' Nothing
|
||||||
determineShellTest' fallbackShell = determineShell fallbackShell . fromJust . prRoot . pScript
|
determineShellTest' fallbackShell = determineShell fallbackShell . fromJust . prRoot . pScript
|
||||||
determineShell fallbackShell t = fromMaybe Bash $ do
|
determineShell fallbackShell t = fromMaybe Bash $
|
||||||
shellString <- foldl mplus Nothing $ getCandidates t
|
|
||||||
shellForExecutable shellString `mplus` fallbackShell
|
shellForExecutable shellString `mplus` fallbackShell
|
||||||
where
|
where
|
||||||
forAnnotation t =
|
shellString = getCandidate t
|
||||||
case t of
|
getCandidate :: Token -> String
|
||||||
(ShellOverride s) -> return s
|
getCandidate t@T_Script {} = fromShebang t
|
||||||
_ -> fail ""
|
getCandidate (T_Annotation _ annotations s) =
|
||||||
getCandidates :: Token -> [Maybe String]
|
fromMaybe (fromShebang s) $
|
||||||
getCandidates t@T_Script {} = [Just $ fromShebang t]
|
listToMaybe [s | ShellOverride s <- annotations]
|
||||||
getCandidates (T_Annotation _ annotations s) =
|
|
||||||
map forAnnotation annotations ++
|
|
||||||
[Just $ fromShebang s]
|
|
||||||
fromShebang (T_Script _ (T_Literal _ s) _) = executableFromShebang s
|
fromShebang (T_Script _ (T_Literal _ s) _) = executableFromShebang s
|
||||||
|
|
||||||
-- Given a string like "/bin/bash" or "/usr/bin/env dash",
|
-- Given a string like "/bin/bash" or "/usr/bin/env dash",
|
||||||
|
|
Loading…
Reference in New Issue