mirror of
https://github.com/simonmichael/hledger.git
synced 2024-10-06 10:57:30 +03:00
fix: ui, web: accept valueless --debug flag again
This commit is contained in:
parent
0c9b704bcc
commit
6c294e91d6
@ -123,7 +123,7 @@ getHledgerUIOpts :: IO UIOpts
|
||||
--getHledgerUIOpts = processArgs uimode >>= return >>= rawOptsToUIOpts
|
||||
getHledgerUIOpts = do
|
||||
args <- getArgs >>= expandArgsAt
|
||||
let args' = replaceNumericFlags args
|
||||
let args' = ensureDebugFlagHasVal $ replaceNumericFlags args
|
||||
let cmdargopts = either usageError id $ process uimode args'
|
||||
rawOptsToUIOpts cmdargopts
|
||||
|
||||
|
@ -186,7 +186,7 @@ checkWebOpts = id
|
||||
|
||||
getHledgerWebOpts :: IO WebOpts
|
||||
getHledgerWebOpts = do
|
||||
args <- fmap replaceNumericFlags . expandArgsAt =<< getArgs
|
||||
args <- fmap (ensureDebugFlagHasVal . replaceNumericFlags) . expandArgsAt =<< getArgs
|
||||
rawOptsToWebOpts . either usageError id $ process webmode args
|
||||
|
||||
data Permission
|
||||
|
@ -112,7 +112,6 @@ import Data.Bifunctor (second)
|
||||
import Data.Function ((&))
|
||||
import Data.Functor ((<&>))
|
||||
import Data.List.Extra (nubSort)
|
||||
import Data.Char (isDigit)
|
||||
|
||||
|
||||
-- | The overall cmdargs mode describing hledger's command-line options and subcommands.
|
||||
@ -381,15 +380,7 @@ cmdargsParse args0 addons =
|
||||
,show args
|
||||
])
|
||||
id
|
||||
where args = ensureDebugHasVal args0
|
||||
|
||||
-- Convert a valueless --debug flag to one with a value.
|
||||
-- See also the --debug flag definition in CliOptions.hs.
|
||||
-- This makes an equals sign unnecessary with this optional-value flag.
|
||||
ensureDebugHasVal as = case break (=="--debug") as of
|
||||
(bs,"--debug":c:cs) | null c || not (all isDigit c) -> bs++"--debug=1":c:cs
|
||||
(bs,["--debug"]) -> bs++["--debug=1"]
|
||||
_ -> as
|
||||
where args = ensureDebugFlagHasVal args0
|
||||
|
||||
-- | cmdargs does not allow flags (options) to appear before the subcommand name.
|
||||
-- We prefer to hide this restriction from the user, making the CLI more forgiving.
|
||||
|
@ -71,6 +71,7 @@ module Hledger.Cli.CliOptions (
|
||||
defaultWidth,
|
||||
-- widthFromOpts,
|
||||
replaceNumericFlags,
|
||||
ensureDebugFlagHasVal,
|
||||
-- | For register:
|
||||
registerWidthsFromOpts,
|
||||
|
||||
@ -571,6 +572,15 @@ replaceNumericFlags = map replace
|
||||
replace ('-':ds) | not (null ds) && all isDigit ds = "--depth="++ds
|
||||
replace s = s
|
||||
|
||||
-- Convert a valueless --debug flag to one with a value.
|
||||
-- See also the --debug flag definition in CliOptions.hs.
|
||||
-- This makes an equals sign unnecessary with this optional-value flag.
|
||||
ensureDebugFlagHasVal :: [String] -> [String]
|
||||
ensureDebugFlagHasVal as = case break (=="--debug") as of
|
||||
(bs,"--debug":c:cs) | null c || not (all isDigit c) -> bs++"--debug=1":c:cs
|
||||
(bs,["--debug"]) -> bs++["--debug=1"]
|
||||
_ -> as
|
||||
|
||||
-- | Parse raw option string values to the desired final data types.
|
||||
-- Any relative smart dates will be converted to fixed dates based on
|
||||
-- today's date. Parsing failures will raise an error.
|
||||
|
Loading…
Reference in New Issue
Block a user