Darcs.Utils
Contents
- ortryrunning :: IO ExitCode -> IO ExitCode -> IO ExitCode
- nubsort :: Ord a => [a] -> [a]
- breakCommand :: String -> (String, [String])
- showHexLen :: Integral a => Int -> a -> String
- maybeGetEnv :: String -> IO (Maybe String)
- formatPath :: String -> String
- firstJustIO :: [IO (Maybe a)] -> IO (Maybe a)
- askUser :: String -> IO String
- askUserListItem :: String -> [String] -> IO String
- data PromptConfig = PromptConfig {}
- promptYorn :: [Char] -> IO Bool
- promptChar :: PromptConfig -> IO Char
- getViewer :: IO String
- editFile :: FilePathLike p => p -> IO (ExitCode, Bool)
- runEditor :: FilePath -> IO ExitCode
- stripCr :: String -> String
- environmentHelpEditor :: ([String], [String])
- environmentHelpPager :: ([String], [String])
- catchall :: IO a -> IO a -> IO a
- clarifyErrors :: IO a -> String -> IO a
- prettyException :: SomeException -> String
- prettyError :: IOError -> String
- addToErrorLoc :: IOException -> String -> IOException
- getFileStatus :: FilePath -> IO (Maybe FileStatus)
- withCurrentDirectory :: FilePathLike p => p -> IO a -> IO a
- withUMask :: String -> IO a -> IO a
- filterFilePaths :: [FilePath] -> AnchoredPath -> t -> Bool
- filterPaths :: [AnchoredPath] -> AnchoredPath -> t -> Bool
- treeHas :: (MonadError e m, Functor m, Monad m) => Tree m -> FilePath -> m Bool
- treeHasDir :: (MonadError e m, Functor m, Monad m) => Tree m -> FilePath -> m Bool
- treeHasFile :: (MonadError e m, Functor m, Monad m) => Tree m -> FilePath -> m Bool
- treeHasAnycase :: (MonadError e m, Functor m, Monad m) => Tree m -> FilePath -> m Bool
Documentation
ortryrunning :: IO ExitCode -> IO ExitCode -> IO ExitCode
Given two shell commands as arguments, execute the former. The latter is then executed if the former failed because the executable wasn't found (code 127), wasn't executable (code 126) or some other exception occurred. Other failures (such as the user holding ^C) do not cause the second command to be tried.
breakCommand :: String -> (String, [String])
showHexLen :: Integral a => Int -> a -> String
maybeGetEnv :: String -> IO (Maybe String)
formatPath :: String -> String
Monads
firstJustIO :: [IO (Maybe a)] -> IO (Maybe a)
The firstJustIO is a slight modification to firstJustM: the entries in the list must be IO monad operations and the firstJustIO will silently turn any monad call that throws an exception into Nothing, basically causing it to be ignored.
User prompts
Ask the user for a line of input.
askUserListItem :: String -> [String] -> IO String
askUserListItem prompt xs enumerates xs on the screen, allowing
the user to choose one of the items
data PromptConfig
Constructors
| PromptConfig | |
promptYorn :: [Char] -> IO Bool
Prompt the user for a yes or no
promptChar :: PromptConfig -> IO Char
Text
editFile :: FilePathLike p => p -> IO (ExitCode, Bool)
editFile f lets the user edit a file which could but does not need
to already exist. This function returns the exit code from the text
editor and a flag indicating if the user made any changes.
Help
environmentHelpEditor :: ([String], [String])
environmentHelpPager :: ([String], [String])
Errors and exceptions
clarifyErrors :: IO a -> String -> IO a
prettyError :: IOError -> String
addToErrorLoc :: IOException -> String -> IOException
Files and directories
getFileStatus :: FilePath -> IO (Maybe FileStatus)
withCurrentDirectory :: FilePathLike p => p -> IO a -> IO a
Tree filtering.
filterFilePaths :: [FilePath] -> AnchoredPath -> t -> Bool
Same as filterPath, but for ordinary FilePaths (as opposed to
AnchoredPath).
filterPaths :: [AnchoredPath] -> AnchoredPath -> t -> Bool
Construct a filter from a list of AnchoredPaths, that will accept any path that is either a parent or a child of any of the listed paths, and discard everything else.
Tree lookup.
treeHasDir :: (MonadError e m, Functor m, Monad m) => Tree m -> FilePath -> m Bool
treeHasFile :: (MonadError e m, Functor m, Monad m) => Tree m -> FilePath -> m Bool
treeHasAnycase :: (MonadError e m, Functor m, Monad m) => Tree m -> FilePath -> m Bool