git.iko.soy/typeable/pandoc
on master help sign in
Better error messages for removed options.

See #3416.

commit3a332fa07674d27644c67a5c0259b40c5838fb24 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 4 Feb 2017, 09:41 (10 years ago) parentb8f4512
1 file changed+25−9
pandoc.hs+25−9
pandoc.hs+25−9
@@ -82,16 +82,37 @@ main = do
8282 rawArgs <- map UTF8.decodeArg <$> getArgs
8383 prg <- getProgName
8484
85− let (actions, args, errors) = getOpt Permute options rawArgs
85+ let (actions, args, unrecognizedOpts, errors) =
86+ getOpt' Permute options rawArgs
8687
87− unless (null errors) $
88− err 2 $ concat $ errors ++
89− ["Try " ++ prg ++ " --help for more information."]
88+ let unknownOptionErrors = foldr addDeprecationNote [] unrecognizedOpts
89+
90+ unless (null errors && null unknownOptionErrors) $
91+ err 2 $ concat errors ++ unlines unknownOptionErrors ++
92+ ("Try " ++ prg ++ " --help for more information.")
9093
9194 -- thread option data structure through all supplied option actions
9295 opts <- foldl (>>=) (return defaultOpts) actions
9396 convertWithOpts opts args
9497
98+addDeprecationNote :: String -> [String] -> [String]
99+addDeprecationNote "--smart" =
100+ (("--smart has been removed. Use +smart or -smart extension instead.\n" ++
101+ "For example: pandoc -f markdown+smart -t markdown-smart.") :)
102+addDeprecationNote "-S" = addDeprecationNote "--smart"
103+addDeprecationNote "--old-dashes" =
104+ ("--old-dashes has been removed." :)
105+addDeprecationNote "--no-wrap" =
106+ ("--no-wrap has been removed. Use --wrap=none instead." :)
107+addDeprecationNote "--chapters" =
108+ ("--chapters has been removed. Use --top-level-division=chapter instead." :)
109+addDeprecationNote "--reference-docx" =
110+ ("--reference-docx has been removed. Use --reference-doc instead." :)
111+addDeprecationNote "--reference-odt" =
112+ ("--reference-odt has been removed. Use --reference-doc instead." :)
113+addDeprecationNote x =
114+ (("Unknown option " ++ x ++ ".") :)
115+
95116convertWithOpts :: Opt -> [FilePath] -> IO ()
96117convertWithOpts opts args = do
97118 let Opt { optTabStop = tabStop
@@ -1283,11 +1304,6 @@ options =
12831304
12841305 ]
12851306
1286−-- TODO: possibly add code to give a more informative message
1287−-- if people try to use options that have been removed in 2.0,
1288−-- e.g. --smart/-S, --old-dashes, --no-wrap, --chapters,
1289−-- --reference-docx, --reference-odt
1290−
12911307addMetadata :: String -> MetaValue -> M.Map String MetaValue
12921308 -> M.Map String MetaValue
12931309addMetadata k v m = case M.lookup k m of