get rid of non-script commands

This commit is contained in:
Tom Sydney Kerckhove 2023-10-12 22:01:21 +02:00
parent ee5b44fda0
commit 85c0b64382
5 changed files with 18 additions and 40 deletions

View File

@ -46,7 +46,7 @@ spec =
let cp =
setStdout nullStream
. setWorkingDir (fromAbsDir tdir)
$ proc "feedback" ["--", "bash", "-c", "echo hi >" <> fromAbsFile resultFile]
$ proc "feedback" ["--", "bash", "-c", "'echo hi >" <> fromAbsFile resultFile <> "'"]
withProcessKill cp $ \ph -> do
waitABit
@ -70,7 +70,7 @@ spec =
setStdout nullStream
. setStdin (useHandleOpen slaveHandle)
. setWorkingDir (fromAbsDir tdir)
$ proc "feedback" ["--", "bash", "-c", "date +%N >" <> fromAbsFile dateFile]
$ proc "feedback" ["--", "bash", "-c", "'date +%N >" <> fromAbsFile dateFile <> "'"]
withProcessKill cp $ \ph -> do
waitABit
@ -105,7 +105,7 @@ spec =
setStdout nullStream
. setStdin (useHandleOpen slaveHandle)
. setWorkingDir (fromAbsDir tdir)
$ proc "feedback" ["--no-clear", "--debug", "--", "bash", "-c", "date +%N >" <> fromAbsFile dateFile]
$ proc "feedback" ["--no-clear", "--debug", "--", "bash", "-c", "'date +%N >" <> fromAbsFile dateFile <> "'"]
withProcessKill cp $ \ph -> do
waitABit
@ -164,7 +164,7 @@ spec =
setStdout nullStream
. setStdin (useHandleOpen slaveHandle)
. setWorkingDir (fromAbsDir tdir)
$ proc "feedback" ["--no-clear", "--debug", "--", "bash", "-c", "date +%N >" <> fromAbsFile dateFile]
$ proc "feedback" ["--no-clear", "--debug", "--", "bash", "-c", "'date +%N >" <> fromAbsFile dateFile <> "'"]
withProcessKill cp $ \ph -> do
waitABit
@ -274,7 +274,7 @@ spec =
mExitCode `shouldBe` Nothing
withProcessKill :: ProcessConfig stdin stderr stdout -> (Process stdin stderr stdout -> IO a) -> IO a
withProcessKill cp func = withProcessWait cp $ \ph ->
withProcessKill cp func = withProcessWait cp $ \ph -> do
func ph `finally` killProcessHandle ph
killProcessHandle :: Process stdin stdout stderr -> IO ()

View File

@ -146,13 +146,13 @@ instance HasCodec LoopConfiguration where
"* Hooks configuration: What to around commands"
]
f = \case
Left s -> makeLoopConfiguration (CommandArgs s)
Left s -> makeLoopConfiguration (CommandScript s)
Right loopConfig -> loopConfig
g loopConfig =
let runConfig = loopConfigRunConfiguration loopConfig
c = runConfigCommand runConfig
in case c of
CommandArgs cmd | loopConfig == makeLoopConfiguration c -> Left cmd
CommandScript cmd | loopConfig == makeLoopConfiguration c -> Left cmd
_ -> Right loopConfig
loopConfigurationObjectCodec :: JSONObjectCodec LoopConfiguration
@ -204,12 +204,12 @@ instance HasCodec RunConfiguration where
(object "RunConfiguration" runConfigurationObjectCodec)
where
f = \case
Left s -> makeRunConfiguration (CommandArgs s)
Left s -> makeRunConfiguration (CommandScript s)
Right loopConfig -> loopConfig
g runConfig =
let c = runConfigCommand runConfig
in case c of
CommandArgs cmd | runConfig == makeRunConfiguration c -> Left cmd
CommandScript cmd | runConfig == makeRunConfiguration c -> Left cmd
_ -> Right runConfig
runConfigurationObjectCodec :: JSONObjectCodec RunConfiguration
@ -420,15 +420,7 @@ parseCommandFlags =
completer (listIOCompleter defaultConfigFileCompleter)
]
)
escapeChar = \case
'"' -> "\\\""
'\'' -> "\\\'"
c -> [c]
quote = ("\"" <>) . (<> "\"") . concatMap escapeChar
quoteIfNecessary "" = quote ""
quoteIfNecessary s = if ' ' `elem` s then quote s else s
pieceBackTogether = unwords . map quoteIfNecessary
in pieceBackTogether <$> many commandArg
in unwords <$> many commandArg
defaultConfigFileCompleter :: IO [String]
defaultConfigFileCompleter = do
@ -447,24 +439,17 @@ parseOutputFlags =
]
)
data Command
= CommandArgs !String
| CommandScript !String
newtype Command = CommandScript {unScript :: String}
deriving (Show, Eq, Generic)
instance HasCodec Command where
codec = dimapCodec CommandScript unScript codec
commandObjectCodec :: JSONObjectCodec Command
commandObjectCodec =
dimapCodec f g $
eitherCodec
(requiredField "command" "the command to run on change")
(requiredField "script" "the script to run on change")
where
f = \case
Left c -> CommandArgs c
Right s -> CommandScript s
g = \case
CommandArgs c -> Left c
CommandScript s -> Right s
parseAlternative
(requiredField "script" "the script to run on change")
(requiredField "command" "the command to run on change (alias for 'script' for backward compatibility)")
data Clear = ClearScreen | DoNotClearScreen
deriving (Show, Eq, Generic)

View File

@ -45,12 +45,6 @@ startingLines RunSettings {..} =
let RunSettings _ _ _ = undefined
in concat
[ case runSettingCommand of
CommandArgs command ->
[ [ indicatorChunk "starting",
" ",
commandChunk command
]
]
CommandScript script ->
[ [ indicatorChunk "starting script\n",
chunk $ T.pack script

View File

@ -42,7 +42,6 @@ makeProcessConfigFor RunSettings {..} = do
let envForProcess = M.toList $ M.union runSettingExtraEnv (M.fromList env)
-- Set up the command
commandString <- case runSettingCommand of
CommandArgs c -> pure c
CommandScript s -> do
-- Write the script to a file
systemTempDir <- getTempDir

View File

@ -32,7 +32,7 @@ combineToSettings flags@Flags {..} environment mConf = do
show flagCommand <> ",",
"interpreting it as a standalone command."
]
pure $ makeLoopConfiguration $ CommandArgs flagCommand
pure $ makeLoopConfiguration $ CommandScript flagCommand
Just config -> do
putStrLn $
unwords