diff options
author | John MacFarlane <jgm@berkeley.edu> | 2017-02-04 09:41:08 +0100 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2017-02-04 09:41:08 +0100 |
commit | 3a332fa07674d27644c67a5c0259b40c5838fb24 (patch) | |
tree | 7ed041a43ec72cac28ce8b116dee8937150ca73e | |
parent | b8f4512534f2ce81743bc5a0b7c12775e54fde88 (diff) | |
download | pandoc-3a332fa07674d27644c67a5c0259b40c5838fb24.tar.gz |
Better error messages for removed options.
See #3416.
-rw-r--r-- | pandoc.hs | 34 |
1 files changed, 25 insertions, 9 deletions
@@ -82,16 +82,37 @@ main = do rawArgs <- map UTF8.decodeArg <$> getArgs prg <- getProgName - let (actions, args, errors) = getOpt Permute options rawArgs + let (actions, args, unrecognizedOpts, errors) = + getOpt' Permute options rawArgs - unless (null errors) $ - err 2 $ concat $ errors ++ - ["Try " ++ prg ++ " --help for more information."] + let unknownOptionErrors = foldr addDeprecationNote [] unrecognizedOpts + + unless (null errors && null unknownOptionErrors) $ + err 2 $ concat errors ++ unlines unknownOptionErrors ++ + ("Try " ++ prg ++ " --help for more information.") -- thread option data structure through all supplied option actions opts <- foldl (>>=) (return defaultOpts) actions convertWithOpts opts args +addDeprecationNote :: String -> [String] -> [String] +addDeprecationNote "--smart" = + (("--smart has been removed. Use +smart or -smart extension instead.\n" ++ + "For example: pandoc -f markdown+smart -t markdown-smart.") :) +addDeprecationNote "-S" = addDeprecationNote "--smart" +addDeprecationNote "--old-dashes" = + ("--old-dashes has been removed." :) +addDeprecationNote "--no-wrap" = + ("--no-wrap has been removed. Use --wrap=none instead." :) +addDeprecationNote "--chapters" = + ("--chapters has been removed. Use --top-level-division=chapter instead." :) +addDeprecationNote "--reference-docx" = + ("--reference-docx has been removed. Use --reference-doc instead." :) +addDeprecationNote "--reference-odt" = + ("--reference-odt has been removed. Use --reference-doc instead." :) +addDeprecationNote x = + (("Unknown option " ++ x ++ ".") :) + convertWithOpts :: Opt -> [FilePath] -> IO () convertWithOpts opts args = do let Opt { optTabStop = tabStop @@ -1283,11 +1304,6 @@ options = ] --- TODO: possibly add code to give a more informative message --- if people try to use options that have been removed in 2.0, --- e.g. --smart/-S, --old-dashes, --no-wrap, --chapters, --- --reference-docx, --reference-odt - addMetadata :: String -> MetaValue -> M.Map String MetaValue -> M.Map String MetaValue addMetadata k v m = case M.lookup k m of |