{-
  This module is part of Chatty.
  Copyleft (c) 2014 Marvin Cohrs

  All wrongs reversed. Sharing is an act of love, not crime.
  Please share Antisplice with everyone you like.

  Chatty is free software: you can redistribute it and/or modify
  it under the terms of the GNU Affero General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  Chatty is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  GNU Affero General Public License for more details.

  You should have received a copy of the GNU Affero General Public License
  along with Chatty. If not, see <http://www.gnu.org/licenses/>.
-}

-- | Provides builtins for some common commands.
module System.Chatty.Spawn.Builtins (withBuiltins) where

import System.Chatty.Spawn
import System.Chatty.Spawn.Overlay

-- | Use builtins if possible.
withBuiltins :: (Functor m, ChSpawn m) => SpawnOverlayT m a -> m a
withBuiltins m = fmap fst $ runSpawnOverlayT m builtins

builtins :: ChSpawn m => [(String,[String] -> String -> m (Int,String))]
builtins =
  ("cat", \_ si -> return (0,si)):
  []