Change optInputFiles to a Maybe [FilePath]
.
`Nothing` means: nothing specified. `Just []` means: an empty list specified (e.g. in defaults). Potentially these could lead to different behavior: see #5888.
This commit is contained in:
parent
871bfaf794
commit
81fae63a54
5 changed files with 22 additions and 16 deletions
|
@ -75,7 +75,7 @@ convertWithOpts opts = do
|
|||
|
||||
when (optDumpArgs opts) $
|
||||
do UTF8.hPutStrLn stdout outputFile
|
||||
mapM_ (UTF8.hPutStrLn stdout) (optInputFiles opts)
|
||||
mapM_ (UTF8.hPutStrLn stdout) (fromMaybe ["-"] $ optInputFiles opts)
|
||||
exitSuccess
|
||||
|
||||
let isPandocCiteproc (JSONFilter f) = takeBaseName f == "pandoc-citeproc"
|
||||
|
@ -88,9 +88,9 @@ convertWithOpts opts = do
|
|||
let filters' = filters ++ [ JSONFilter "pandoc-citeproc" | needsCiteproc ]
|
||||
|
||||
let sources = case optInputFiles opts of
|
||||
[] -> ["-"]
|
||||
xs | optIgnoreArgs opts -> ["-"]
|
||||
| otherwise -> xs
|
||||
Nothing -> ["-"]
|
||||
Just xs | optIgnoreArgs opts -> ["-"]
|
||||
| otherwise -> xs
|
||||
|
||||
datadir <- case optDataDir opts of
|
||||
Nothing -> do
|
||||
|
@ -132,7 +132,7 @@ convertWithOpts opts = do
|
|||
|
||||
runIO' $ do
|
||||
setUserDataDir datadir
|
||||
setInputFiles (optInputFiles opts)
|
||||
setInputFiles (fromMaybe ["-"] (optInputFiles opts))
|
||||
setOutputFile (optOutputFile opts)
|
||||
|
||||
-- assign reader and writer based on options and filenames
|
||||
|
@ -151,7 +151,7 @@ convertWithOpts opts = do
|
|||
|
||||
when (pdfOutput && readerName == "latex") $
|
||||
case (optInputFiles opts) of
|
||||
(inputFile:_) -> report $ UnusualConversion $ T.pack $
|
||||
Just (inputFile:_) -> report $ UnusualConversion $ T.pack $
|
||||
"to convert a .tex file to PDF, you get better results by using pdflatex "
|
||||
<> "(or lualatex or xelatex) directly, try `pdflatex " <> inputFile
|
||||
<> "` instead of `pandoc " <> inputFile <> " -o " <> outputFile <> "`."
|
||||
|
|
|
@ -85,7 +85,11 @@ parseOptions options' defaults = do
|
|||
|
||||
-- thread option data structure through all supplied option actions
|
||||
opts <- foldl (>>=) (return defaults) actions
|
||||
return (opts{ optInputFiles = map normalizePath $ optInputFiles opts ++ args })
|
||||
let mbArgs = case args of
|
||||
[] -> Nothing
|
||||
xs -> Just xs
|
||||
return $ opts{ optInputFiles =
|
||||
map normalizePath <$> (optInputFiles opts <> mbArgs) }
|
||||
|
||||
latexEngines :: [String]
|
||||
latexEngines = ["pdflatex", "lualatex", "xelatex", "latexmk", "tectonic"]
|
||||
|
|
|
@ -85,7 +85,7 @@ data Opt = Opt
|
|||
, optMetadata :: Meta -- ^ Metadata fields to set
|
||||
, optMetadataFiles :: [FilePath] -- ^ Name of YAML metadata files
|
||||
, optOutputFile :: Maybe FilePath -- ^ Name of output file
|
||||
, optInputFiles :: [FilePath] -- ^ Names of input files
|
||||
, optInputFiles :: Maybe [FilePath] -- ^ Names of input files
|
||||
, optNumberSections :: Bool -- ^ Number sections in LaTeX
|
||||
, optNumberOffset :: [Int] -- ^ Starting number for sections
|
||||
, optSectionDivs :: Bool -- ^ Put sections in div tags in HTML
|
||||
|
@ -200,16 +200,17 @@ doOpt (k',v) = do
|
|||
"output-file" ->
|
||||
parseYAML v >>= \x -> return (\o -> o{ optOutputFile = unpack <$> x })
|
||||
"input-files" ->
|
||||
parseYAML v >>= \x -> return (\o -> o{ optInputFiles = optInputFiles o <>
|
||||
map unpack x })
|
||||
parseYAML v >>= \x -> return (\o -> o{ optInputFiles =
|
||||
optInputFiles o <>
|
||||
Just (map unpack x) })
|
||||
"input-file" -> -- allow either a list or a single value
|
||||
(parseYAML v >>= \x -> return (\o -> o{ optInputFiles =
|
||||
optInputFiles o <>
|
||||
map unpack x }))
|
||||
Just (map unpack x) }))
|
||||
<|>
|
||||
(parseYAML v >>= \x -> return (\o -> o{ optInputFiles =
|
||||
optInputFiles o <>
|
||||
[unpack x] }))
|
||||
Just [unpack x] }))
|
||||
"number-sections" ->
|
||||
parseYAML v >>= \x -> return (\o -> o{ optNumberSections = x })
|
||||
"number-offset" ->
|
||||
|
@ -390,7 +391,7 @@ defaultOpts = Opt
|
|||
, optMetadata = mempty
|
||||
, optMetadataFiles = []
|
||||
, optOutputFile = Nothing
|
||||
, optInputFiles = []
|
||||
, optInputFiles = Nothing
|
||||
, optNumberSections = False
|
||||
, optNumberOffset = [0,0,0,0,0,0]
|
||||
, optSectionDivs = False
|
||||
|
|
|
@ -63,7 +63,7 @@ optToOutputSettings opts = do
|
|||
|
||||
when (optDumpArgs opts) . liftIO $ do
|
||||
UTF8.hPutStrLn stdout outputFile
|
||||
mapM_ (UTF8.hPutStrLn stdout) (optInputFiles opts)
|
||||
mapM_ (UTF8.hPutStrLn stdout) (fromMaybe [] $ optInputFiles opts)
|
||||
exitSuccess
|
||||
|
||||
epubMetadata <- case optEpubMetadata opts of
|
||||
|
@ -140,7 +140,8 @@ optToOutputSettings opts = do
|
|||
variables <-
|
||||
return (optVariables opts)
|
||||
>>=
|
||||
setListVariableM "sourcefile" (T.pack <$> optInputFiles opts)
|
||||
setListVariableM "sourcefile"
|
||||
(maybe ["-"] (fmap T.pack) (optInputFiles opts))
|
||||
>>=
|
||||
setVariableM "outputfile" outputFile
|
||||
>>=
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
% pandoc --lua-filter=command/lua-pandoc-state.lua --data-dir=foo
|
||||
Hello
|
||||
^D
|
||||
# input files: 0
|
||||
# input files: 1
|
||||
output file: nil
|
||||
# request header: 0
|
||||
resource path: .
|
||||
|
|
Loading…
Reference in a new issue