diff --git a/hledger-ui/Hledger/UI/UIOptions.hs b/hledger-ui/Hledger/UI/UIOptions.hs index 79ba7a4a7..7266c371b 100644 --- a/hledger-ui/Hledger/UI/UIOptions.hs +++ b/hledger-ui/Hledger/UI/UIOptions.hs @@ -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 diff --git a/hledger-web/Hledger/Web/WebOptions.hs b/hledger-web/Hledger/Web/WebOptions.hs index 328984acd..a3ea1617b 100644 --- a/hledger-web/Hledger/Web/WebOptions.hs +++ b/hledger-web/Hledger/Web/WebOptions.hs @@ -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 diff --git a/hledger/Hledger/Cli.hs b/hledger/Hledger/Cli.hs index 1758ae556..1431ac8ed 100644 --- a/hledger/Hledger/Cli.hs +++ b/hledger/Hledger/Cli.hs @@ -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. diff --git a/hledger/Hledger/Cli/CliOptions.hs b/hledger/Hledger/Cli/CliOptions.hs index e26448722..ac7c9cf93 100644 --- a/hledger/Hledger/Cli/CliOptions.hs +++ b/hledger/Hledger/Cli/CliOptions.hs @@ -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.