<commit_before>-----------------------------------------------------------------------------
-- |
-- Module      :  Distribution.Simple.Program.Script
-- Copyright   :  <NAME> 2009
--
-- Maintainer  :  <EMAIL>
-- Portability :  portable
--
-- This module provides an library interface to the @hc-pkg@ program.
-- Currently only GHC and LHC have hc-pkg programs.

module Distribution.Simple.Program.Script (

    invocationAsSystemScript,
    invocationAsShellScript,
    invocationAsBatchFile,
  ) where

import Distribution.Simple.Program.Run
         ( ProgramInvocation(..) )
import Distribution.System
         ( OS(..) )

import Data.Maybe
         ( maybeToList )

-- | Generate a system script, either POSIX shell script or Windows batch file
-- as appropriate for the given system.
--
invocationAsSystemScript :: OS -> ProgramInvocation -> String
invocationAsSystemScript Windows = invocationAsBatchFile
invocationAsSystemScript _       = invocationAsShellScript


-- | Generate a POSIX shell script that invokes a program.
--
invocationAsShellScript :: ProgramInvocation -> String
invocationAsShellScript
  ProgramInvocation {
    progInvokePath  = path,
    progInvokeArgs  = args,
    progInvokeEnv   = envExtra,
    progInvokeCwd   = mcwd,
    progInvokeInput = minput
  } = unlines $
          [ "#!/bin/sh" ]
       ++ [ "export " ++ var ++ "=" ++ quote val
          | (var,val) <- envExtra ]
       ++ [ "cd " ++ quote cwd | cwd <- maybeToList mcwd ]
       ++ [ (case minput of
              Nothing    -> ""
              Just input -> "echo " ++ quote input ++ " | ")
         ++ quote path ++ concatMap (\arg -> ' ':quote arg) args ]

  where
    quote :: String -> String
    quote s = "'" ++ escape s ++ "'"

    escape []        = []<commit_msg>Pass additional parameters in generated shell scripts While here, simplify the argument list construction in invocationAsShellScript a little bit.<commit_after>-----------------------------------------------------------------------------
-- |
-- Module      :  Distribution.Simple.Program.Script
-- Copyright   :  <NAME> 2009
--
-- Maintainer  :  <EMAIL>
-- Portability :  portable
--
-- This module provides an library interface to the @hc-pkg@ program.
-- Currently only GHC and LHC have hc-pkg programs.

module Distribution.Simple.Program.Script (

    invocationAsSystemScript,
    invocationAsShellScript,
    invocationAsBatchFile,
  ) where

import Distribution.Simple.Program.Run
         ( ProgramInvocation(..) )
import Distribution.System
         ( OS(..) )

import Data.Maybe
         ( maybeToList )

-- | Generate a system script, either POSIX shell script or Windows batch file
-- as appropriate for the given system.
--
invocationAsSystemScript :: OS -> ProgramInvocation -> String
invocationAsSystemScript Windows = invocationAsBatchFile
invocationAsSystemScript _       = invocationAsShellScript


-- | Generate a POSIX shell script that invokes a program.
--
invocationAsShellScript :: ProgramInvocation -> String
invocationAsShellScript
  ProgramInvocation {
    progInvokePath  = path,
    progInvokeArgs  = args,
    progInvokeEnv   = envExtra,
    progInvokeCwd   = mcwd,
    progInvokeInput = minput
  } = unlines $
          [ "#!/bin/sh" ]
       ++ [ "export " ++ var ++ "=" ++ quote val
          | (var,val) <- envExtra ]
       ++ [ "cd " ++ quote cwd | cwd <- maybeToList mcwd ]
       ++ [ (case minput of
              Nothing    -> ""
              Just input -> "echo " ++ quote input ++ " | ")
         ++ unwords (map quote $ path : args) ++ " \"$@\""]

  where
    quote :: String -> String
    quote s = "'" ++ escape s ++ "'"

    escape []        = []
{'fraction_non_alphanumeric': 0.1523757509557619, 'fraction_numerical': 0.002184598580010923, 'mean_word_length': 2.21034180543383, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '654781', 'n_tokens_mistral': 1025, 'n_tokens_neox': 979, 'n_words': 282}