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 = processArgs uimode >>= return >>= rawOptsToUIOpts
|
||||||
getHledgerUIOpts = do
|
getHledgerUIOpts = do
|
||||||
args <- getArgs >>= expandArgsAt
|
args <- getArgs >>= expandArgsAt
|
||||||
let args' = replaceNumericFlags args
|
let args' = ensureDebugFlagHasVal $ replaceNumericFlags args
|
||||||
let cmdargopts = either usageError id $ process uimode args'
|
let cmdargopts = either usageError id $ process uimode args'
|
||||||
rawOptsToUIOpts cmdargopts
|
rawOptsToUIOpts cmdargopts
|
||||||
|
|
||||||
|
|||||||
@ -186,7 +186,7 @@ checkWebOpts = id
|
|||||||
|
|
||||||
getHledgerWebOpts :: IO WebOpts
|
getHledgerWebOpts :: IO WebOpts
|
||||||
getHledgerWebOpts = do
|
getHledgerWebOpts = do
|
||||||
args <- fmap replaceNumericFlags . expandArgsAt =<< getArgs
|
args <- fmap (ensureDebugFlagHasVal . replaceNumericFlags) . expandArgsAt =<< getArgs
|
||||||
rawOptsToWebOpts . either usageError id $ process webmode args
|
rawOptsToWebOpts . either usageError id $ process webmode args
|
||||||
|
|
||||||
data Permission
|
data Permission
|
||||||
|
|||||||
@ -112,7 +112,6 @@ import Data.Bifunctor (second)
|
|||||||
import Data.Function ((&))
|
import Data.Function ((&))
|
||||||
import Data.Functor ((<&>))
|
import Data.Functor ((<&>))
|
||||||
import Data.List.Extra (nubSort)
|
import Data.List.Extra (nubSort)
|
||||||
import Data.Char (isDigit)
|
|
||||||
|
|
||||||
|
|
||||||
-- | The overall cmdargs mode describing hledger's command-line options and subcommands.
|
-- | The overall cmdargs mode describing hledger's command-line options and subcommands.
|
||||||
@ -381,15 +380,7 @@ cmdargsParse args0 addons =
|
|||||||
,show args
|
,show args
|
||||||
])
|
])
|
||||||
id
|
id
|
||||||
where args = ensureDebugHasVal args0
|
where args = ensureDebugFlagHasVal 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
|
|
||||||
|
|
||||||
-- | cmdargs does not allow flags (options) to appear before the subcommand name.
|
-- | 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.
|
-- We prefer to hide this restriction from the user, making the CLI more forgiving.
|
||||||
|
|||||||
@ -71,6 +71,7 @@ module Hledger.Cli.CliOptions (
|
|||||||
defaultWidth,
|
defaultWidth,
|
||||||
-- widthFromOpts,
|
-- widthFromOpts,
|
||||||
replaceNumericFlags,
|
replaceNumericFlags,
|
||||||
|
ensureDebugFlagHasVal,
|
||||||
-- | For register:
|
-- | For register:
|
||||||
registerWidthsFromOpts,
|
registerWidthsFromOpts,
|
||||||
|
|
||||||
@ -571,6 +572,15 @@ replaceNumericFlags = map replace
|
|||||||
replace ('-':ds) | not (null ds) && all isDigit ds = "--depth="++ds
|
replace ('-':ds) | not (null ds) && all isDigit ds = "--depth="++ds
|
||||||
replace s = s
|
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.
|
-- | Parse raw option string values to the desired final data types.
|
||||||
-- Any relative smart dates will be converted to fixed dates based on
|
-- Any relative smart dates will be converted to fixed dates based on
|
||||||
-- today's date. Parsing failures will raise an error.
|
-- today's date. Parsing failures will raise an error.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user