Implement orphan instance for shell (#14)

This commit is contained in:
Dmitrii Kovanikov 2019-02-05 14:50:30 +08:00 committed by Veronika Romashkina
parent 77ba7dd540
commit e50d05300c
2 changed files with 25 additions and 0 deletions

View File

@ -25,6 +25,7 @@ library
exposed-modules: Hit
Hit.Cli
Hit.ColorTerminal
Hit.Shell
autogen-modules: Paths_hit_on
other-modules: Paths_hit_on
@ -35,6 +36,7 @@ library
, gitrev ^>= 1.3
, optparse-applicative ^>= 0.14
, relude ^>= 0.4
, process ^>= 1.6.3
ghc-options: -Wall
-Wincomplete-uni-patterns

23
src/Hit/Shell.hs Normal file
View File

@ -0,0 +1,23 @@
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
{- | This module contains neat orphan instance for function to be able to call
commands using just strings.
-}
module Hit.Shell
(
) where
import System.Process (callCommand, showCommandForUser)
-- | This is needed to be able to call commands by writing strings.
instance (a ~ Text, b ~ ()) => IsString ([a] -> IO b) where
fromString :: String -> [Text] -> IO ()
fromString cmd args = do
let cmdStr = showCommandForUser cmd (map toString args)
putStrLn $ "" ++ cmdStr
callCommand cmdStr