Skip to content

Commit

Permalink
Better error messages for removed options.
Browse files Browse the repository at this point in the history
See #3416.
  • Loading branch information
jgm committed Feb 4, 2017
1 parent b8f4512 commit 3a332fa
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions pandoc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3a332fa

Please sign in to comment.