----------------------------------------------------------------------------
-- | Command

grepCommand :: Int -> FilePath -> Word -> CachedIO ([Text], [ErrMsg])
grepCommand limit wdir w = do
  result <- executeWithCache "git" ["grep", "-n", "-w", w] (Just wdir)
  case result of
    Left err -> return ([], [err])
    Right result' -> do
      let limit_err = if (limit < length result') then ["git grep result of " `mappend` w `mappend` " is more than "
                                                        `mappend` (show limit) `mappend` ": "
                                                        `mappend` (show $ length result')
                                                        ]
                                                  else []
      return (take limit result', limit_err)
grepCommand :: Int -> FilePath -> Word -> CachedIO ([Text], [ErrMsg])
grepCommand limit wdir w = do
  result <- executeWithCache "git" ["grep", "-n", "-w", w] (Just wdir)
  case result of
    Left err -> return ([], [err])
    Right result' -> do
      let limit_err = if (limit < length result') then ["git grep result of " `mappend` w `mappend` " is more than "
                                                        `mappend` (show limit) `mappend` ": "
                                                        `mappend` (show $ length result')
                                                        ]
                                                  else []
      return (take limit result', limit_err)
grepCommand limit wdir w = do
  result <- executeWithCache "git" ["grep", "-n", "-w", w] (Just wdir)
  case result of
    Left err -> return ([], [err])
    Right result' -> do
      let limit_err = if (limit < length result') then ["git grep result of " `mappend` w `mappend` " is more than "
                                                        `mappend` (show limit) `mappend` ": "
                                                        `mappend` (show $ length result')
                                                        ]
                                                  else []
      return (take limit result', limit_err)