on master help sign in
Merge pull request #26 from obsidiansystems/no-handoff-completion

Handle --no-handoff somewhat more correctly when bash completing

commit511be223f29b4fb5cb03cfbdbcf2176413518fee authorMin <madelinja@users.noreply.github.com> dateMon 15 Jan 2018, 22:08 (9 years ago) parent5d3ec030e39100
1 file changed+10−5
command/src/Obelisk/Command.hs+10−5
command/src/Obelisk/Command.hs+10−5
@@ -3,6 +3,7 @@
33module Obelisk.Command where
44
55import Control.Monad
6+import Data.List
67import Data.Monoid
78import Options.Applicative
89import System.Environment
@@ -114,14 +115,18 @@ main = do
114115 --TODO: Use a proper logging system with log levels and whatnot
115116 True -> hPutStrLn stderr "NOTICE: --no-handoff should only be passed once and as the first argument; ignoring"
116117 ob cmd
117− case myArgs of
118− "--no-handoff" : as -> go as -- If we've been told not to hand off, don't hand off
119− as -> do
120− findProjectObeliskCommand "." >>= \case
121− Nothing -> go as -- If we aren't in a project, just run ourselves
118+ handoffAndGo as = findProjectObeliskCommand "." >>= \case
119+ Nothing -> go as -- If not in a project, just run ourselves
122120 Just impl -> do
123121 -- Invoke the real implementation, using --no-handoff to prevent infinite recursion
124122 executeFile impl False ("--no-handoff" : myArgs) Nothing
123+ case myArgs of
124+ "--no-handoff" : as -> go as -- If we've been told not to hand off, don't hand off
125+ a:as -- Otherwise bash completion would always hand-off even if the user isn't trying to
126+ | "--bash-completion" `isPrefixOf` a
127+ && "--no-handoff" `elem` as -> go (a:as)
128+ | otherwise -> handoffAndGo (a:as)
129+ as -> handoffAndGo as
125130
126131ob :: ObCommand -> IO ()
127132ob = \case