don't fail if PATH is not defined

This commit is contained in:
Simon Michael 2011-08-25 23:50:34 +00:00
parent ec9e06e33e
commit e67c63dc54

View File

@ -341,12 +341,13 @@ getHledgerAddonCommands = map (drop (length progname + 1)) `fmap` getHledgerProg
-- user's PATH, or the empty list if there is any problem. -- user's PATH, or the empty list if there is any problem.
getHledgerProgramsInPath :: IO [String] getHledgerProgramsInPath :: IO [String]
getHledgerProgramsInPath = do getHledgerProgramsInPath = do
pathdirs <- splitOn ":" `fmap` getEnv "PATH" pathdirs <- splitOn ":" `fmap` getEnvSafe "PATH"
pathexes <- concat `fmap` mapM getDirectoryContentsSafe pathdirs pathexes <- concat `fmap` mapM getDirectoryContentsSafe pathdirs
return $ nub $ sort $ filter (isRight . parsewith hledgerprog) pathexes return $ nub $ sort $ filter (isRight . parsewith hledgerprog) pathexes
where where
hledgerprog = string progname >> char '-' >> many1 (letter <|> char '-') >> eof hledgerprog = string progname >> char '-' >> many1 (letter <|> char '-') >> eof
getEnvSafe v = getEnv v `catch` (\_ -> return "")
getDirectoryContentsSafe d = getDirectoryContents d `catch` (\_ -> return []) getDirectoryContentsSafe d = getDirectoryContents d `catch` (\_ -> return [])
-- | Convert possibly encoded option values to regular unicode strings. -- | Convert possibly encoded option values to regular unicode strings.