diff options
| author | Sam S. Almahri <saud.amahri@gmail.com> | 2023-06-28 09:03:19 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-28 09:03:19 -0700 |
| commit | 6c4980d819cb3b62a0443617df09a2765589bd34 (patch) | |
| tree | f4f4b521fae71d91ea65254f2e5e9ac4a6ff9bb8 /src/Text | |
| parent | 16f4386f40f07b9af9dbad8e5f6af0bf87c21dd8 (diff) | |
Allow all boolean flags to take an optional 'true' or 'false' value
Default is true if no value is specified, so this is fully backwards-compatible.
Closes #8788.
Diffstat (limited to 'src/Text')
| -rw-r--r-- | src/Text/Pandoc/App/CommandLineOptions.hs | 154 |
1 files changed, 109 insertions, 45 deletions
diff --git a/src/Text/Pandoc/App/CommandLineOptions.hs b/src/Text/Pandoc/App/CommandLineOptions.hs index 8c96be58d..2ee304e76 100644 --- a/src/Text/Pandoc/App/CommandLineOptions.hs +++ b/src/Text/Pandoc/App/CommandLineOptions.hs @@ -293,18 +293,27 @@ options = "" , Option "" ["file-scope"] - (NoArg - (\opt -> return opt { optFileScope = True })) + (OptArg + (\arg opt -> do + boolValue <- readBoolFromOptArg arg + return opt { optFileScope = boolValue }) + "true|false") "" -- "Parse input files before combining" , Option "" ["sandbox"] - (NoArg - (\opt -> return opt { optSandbox = True })) + (OptArg + (\arg opt -> do + boolValue <- readBoolFromOptArg arg + return opt { optSandbox = boolValue }) + "true|false") "" , Option "s" ["standalone"] - (NoArg - (\opt -> return opt { optStandalone = True })) + (OptArg + (\arg opt -> do + boolValue <- readBoolFromOptArg arg + return opt { optStandalone = boolValue }) + "true|false") "" -- "Include needed header and footer on output" , Option "" ["template"] @@ -337,13 +346,19 @@ options = "" -- "Option for wrapping text in output" , Option "" ["ascii"] - (NoArg - (\opt -> return opt { optAscii = True })) + (OptArg + (\arg opt -> do + boolValue <- readBoolFromOptArg arg + return opt { optAscii = boolValue }) + "true|false") "" -- "Prefer ASCII output" , Option "" ["toc", "table-of-contents"] - (NoArg - (\opt -> return opt { optTableOfContents = True })) + (OptArg + (\arg opt -> do + boolValue <- readBoolFromOptArg arg + return opt { optTableOfContents = boolValue }) + "true|false") "" -- "Include table of contents" , Option "" ["toc-depth"] @@ -486,8 +501,11 @@ options = "" -- "Length of line in characters" , Option "p" ["preserve-tabs"] - (NoArg - (\opt -> return opt { optPreserveTabs = True })) + (OptArg + (\arg opt -> do + boolValue <- readBoolFromOptArg arg + return opt { optPreserveTabs = boolValue }) + "true|false") "" -- "Preserve tabs instead of converting to spaces" , Option "" ["tab-stop"] @@ -529,15 +547,20 @@ options = "" -- "Path of custom reference doc" , Option "" ["self-contained"] - (NoArg - (\opt -> do - deprecatedOption "--self-contained" "use --embed-resources --standalone" - return opt { optSelfContained = True })) + (OptArg + (\arg opt -> do + deprecatedOption "--self-contained" "use --embed-resources --standalone" + boolValue <- readBoolFromOptArg arg + return opt { optSelfContained = boolValue }) + "true|false") "" -- "Make slide shows include all the needed js and css (deprecated)" - , Option "" ["embed-resources"] - (NoArg - (\opt -> return opt { optEmbedResources = True })) + , Option "" ["embed-resources"] -- maybe True (\argStr -> argStr == "true") arg + (OptArg + (\arg opt -> do + boolValue <- readBoolFromOptArg arg + return opt { optEmbedResources = boolValue }) + "true|false") "" -- "Make slide shows include all the needed js and css" , Option "" ["request-header"] @@ -550,8 +573,11 @@ options = "" , Option "" ["no-check-certificate"] - (NoArg - (\opt -> return opt { optNoCheckCertificate = True })) + (OptArg + (\arg opt -> do + boolValue <- readBoolFromOptArg arg + return opt { optNoCheckCertificate = boolValue }) + "true|false") "" -- "Disable certificate validation" , Option "" ["abbreviations"] @@ -627,13 +653,19 @@ options = "" -- "Accepting or reject MS Word track-changes."" , Option "" ["strip-comments"] - (NoArg - (\opt -> return opt { optStripComments = True })) + (OptArg + (\arg opt -> do + boolValue <- readBoolFromOptArg arg + return opt { optStripComments = boolValue }) + "true|false") "" -- "Strip HTML comments" , Option "" ["reference-links"] - (NoArg - (\opt -> return opt { optReferenceLinks = True } )) + (OptArg + (\arg opt -> do + boolValue <- readBoolFromOptArg arg + return opt { optReferenceLinks = boolValue }) + "true|false") "" -- "Use reference links in parsing HTML" , Option "" ["reference-location"] @@ -664,19 +696,27 @@ options = "" , Option "" ["list-tables"] - (NoArg - (\opt -> do - return opt { optListTables = True } )) + (OptArg + (\arg opt -> do + boolValue <- readBoolFromOptArg arg + return opt { optListTables = boolValue }) + "true|false") "" -- "Use list tables for RST" , Option "" ["listings"] - (NoArg - (\opt -> return opt { optListings = True })) + (OptArg + (\arg opt -> do + boolValue <- readBoolFromOptArg arg + return opt { optListings = boolValue }) + "true|false") "" -- "Use listings package for LaTeX code blocks" , Option "i" ["incremental"] - (NoArg - (\opt -> return opt { optIncremental = True })) + (OptArg + (\arg opt -> do + boolValue <- readBoolFromOptArg arg + return opt { optIncremental = boolValue }) + "true|false") "" -- "Make list items display incrementally in Slidy/Slideous/S5" , Option "" ["slide-level"] @@ -691,14 +731,19 @@ options = "" -- "Force header level for slides" , Option "" ["section-divs"] - (NoArg - (\opt -> return opt { optSectionDivs = True })) + (OptArg + (\arg opt -> do + boolValue <- readBoolFromOptArg arg + return opt { optSectionDivs = boolValue }) + "true|false") "" -- "Put sections in div tags in HTML" , Option "" ["html-q-tags"] - (NoArg - (\opt -> - return opt { optHtmlQTags = True })) + (OptArg + (\arg opt -> do + boolValue <- readBoolFromOptArg arg + return opt { optHtmlQTags = boolValue }) + "true|false") "" -- "Use <q> tags for quotes in HTML" , Option "" ["email-obfuscation"] @@ -908,18 +953,27 @@ options = "" -- "Use gladtex for HTML math" , Option "" ["trace"] - (NoArg - (\opt -> return opt { optTrace = True })) + (OptArg + (\arg opt -> do + boolValue <- readBoolFromOptArg arg + return opt { optTrace = boolValue }) + "true|false") "" -- "Turn on diagnostic tracing in readers." , Option "" ["dump-args"] - (NoArg - (\opt -> return opt { optDumpArgs = True })) + (OptArg + (\arg opt -> do + boolValue <- readBoolFromOptArg arg + return opt { optDumpArgs = boolValue }) + "true|false") "" -- "Print output filename and arguments to stdout." , Option "" ["ignore-args"] - (NoArg - (\opt -> return opt { optIgnoreArgs = True })) + (OptArg + (\arg opt -> do + boolValue <- readBoolFromOptArg arg + return opt { optIgnoreArgs = boolValue }) + "true|false") "" -- "Ignore command-line arguments." , Option "" ["verbose"] @@ -933,8 +987,11 @@ options = "" -- "Suppress warnings." , Option "" ["fail-if-warnings"] - (NoArg - (\opt -> return opt { optFailIfWarnings = True })) + (OptArg + (\arg opt -> do + boolValue <- readBoolFromOptArg arg + return opt { optFailIfWarnings = boolValue }) + "true|false") "" -- "Exit with error status if there were warnings." , Option "" ["log"] @@ -1098,6 +1155,13 @@ readMetaValue s | s == "FALSE" = MetaBool False | otherwise = MetaString $ T.pack s +readBoolFromOptArg :: Maybe String -> ExceptT OptInfo IO Bool +readBoolFromOptArg = maybe (return True) readBoolFromArg + where readBoolFromArg arg = case toLower <$> arg of + "true" -> return True + "false" -> return False + _ -> optError $ PandocOptionError "value must be either true or false" + -- On Windows with ghc 8.6+, we need to rewrite paths -- beginning with \\ to \\?\UNC\. -- See #5127. normalizePath :: FilePath -> FilePath |
