cli: omit source addons from list when compiled version is present, again

Source and compiled versions of all addons in bin are cluttering up
the commands list. I think this was reasonably well behaved, so I'm
re-enabling it, possibly with a slight fix (.c shadowing .exe).
Some notes:

- when there's only one addon with its base filename, its extension is not displayed (as before)
- addons with (case insensitive) .exe extension or no extension are considered compiled
- when there's exactly two addons with the same base filename, and one of them looks compiled, only that one is kept
- modification time is not checked; an old compiled addon overrides a newer source version
- when there's more than two addons with same base filename, all are kept
This commit is contained in:
Simon Michael 2017-01-24 19:31:57 -08:00
parent 4b3d3fc2fa
commit 6859b94f4b

View File

@ -552,34 +552,34 @@ defaultBalanceLineFormat = BottomAligned [
-- Other utils -- Other utils
-- | Get the sorted unique precise names and display names of hledger -- | Get the sorted unique precise names and display names of hledger
-- add-ons found in the current user's PATH. The precise names are the -- add-on executables found in the current user's PATH.
-- add-on's filename with the "hledger-" prefix removed. The display -- Precise names are the file names with the "hledger-" prefix removed.
-- names have the file extension removed also, except when it's needed -- Display names also have the file extension removed, except when it's
-- for disambiguation. -- needed to disambiguate multiple add-ons with similar filenames.
-- -- When there are exactly two similar names that look like a source
-- -- Also when there are exactly two similar names, one with the .hs or -- and compiled version (.exe, .com, or no extension), the source
-- -- .lhs extension and the other with the .exe extension or no -- version is excluded (even if it happens to be newer).
-- -- extension - presumably source and compiled versions of a haskell -- Add-on names matching built-in command names could be returned
-- -- script - we exclude the source version. -- by this function, though hledger will ignore them.
--
-- This function can return add-on names which shadow built-in command
-- names, but hledger will ignore these.
-- --
hledgerAddons :: IO ([String],[String]) hledgerAddons :: IO ([String],[String])
hledgerAddons = do hledgerAddons = do
exes <- hledgerExecutablesInPath exes <- hledgerExecutablesInPath
let precisenames = -- concatMap dropRedundant $ let precisenames = concatMap dropRedundant $
-- groupBy (\a b -> dropExtension a == dropExtension b) $ groupBy (\a b -> dropExtension a == dropExtension b) $
map stripprefix exes map stripprefix exes
let displaynames = concatMap stripext $ let displaynames = concatMap stripext $
groupBy (\a b -> dropExtension a == dropExtension b) precisenames groupBy (\a b -> dropExtension a == dropExtension b) precisenames
return (precisenames, displaynames) return (precisenames, displaynames)
where where
stripprefix = drop (length progname + 1) stripprefix = drop (length progname + 1)
-- dropRedundant [f,f2] | takeExtension f `elem` ["",".exe"] && takeExtension f2 `elem` [".hs",".lhs"] = [f]
-- dropRedundant fs = fs
stripext [f] = [dropExtension f] stripext [f] = [dropExtension f]
stripext fs = fs stripext fs = fs
compiledExts = ["",".com",".exe"]
dropRedundant [f,g]
| takeExtension f `elem` compiledExts = [f]
| takeExtension g `elem` compiledExts = [g]
dropRedundant fs = fs
-- | Get the sorted unique filenames of all hledger-* executables in -- | Get the sorted unique filenames of all hledger-* executables in
-- the current user's PATH. Currently these are: files in any of the -- the current user's PATH. Currently these are: files in any of the