From 61bec588d2246ad3f1326a39e4ac957f77f8369c Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sat, 23 May 2020 13:54:41 -0700 Subject: [PATCH] print,reg,balcmds: list output formats accurately in --help (#689) Also: - tweak the unsupported output format message - Hledger.Cli.CliOptions no longer exports outputflags --- hledger/Hledger/Cli/CliOptions.hs | 17 +++++++++++++---- hledger/Hledger/Cli/Commands/Balance.hs | 3 ++- hledger/Hledger/Cli/Commands/Print.hs | 4 +++- hledger/Hledger/Cli/Commands/Register.hs | 4 +++- hledger/Hledger/Cli/CompoundBalanceCommand.hs | 2 +- hledger/Hledger/Cli/Utils.hs | 2 +- 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/hledger/Hledger/Cli/CliOptions.hs b/hledger/Hledger/Cli/CliOptions.hs index 0cdb4ec8e..65f93e14a 100644 --- a/hledger/Hledger/Cli/CliOptions.hs +++ b/hledger/Hledger/Cli/CliOptions.hs @@ -15,7 +15,7 @@ module Hledger.Cli.CliOptions ( hiddenflags, inputflags, reportflags, - outputflags, + -- outputflags, outputFormatFlag, outputFileFlag, generalflagsgroup1, @@ -192,9 +192,18 @@ hiddenflags = [ ] -- | Common output-related flags: --output-file, --output-format... -outputflags = [outputFormatFlag, outputFileFlag] -outputFormatFlag = flagReq ["output-format","O"] (\s opts -> Right $ setopt "output-format" s opts) "FMT" "select the output format. Supported formats:\ntxt, csv, html." -outputFileFlag = flagReq ["output-file","o"] (\s opts -> Right $ setopt "output-file" s opts) "FILE" "write output to FILE. A file extension matching one of the above formats selects that format." + +-- outputflags = [outputFormatFlag, outputFileFlag] + +outputFormatFlag :: [String] -> Flag RawOpts +outputFormatFlag fmts = flagReq + ["output-format","O"] (\s opts -> Right $ setopt "output-format" s opts) "FMT" + ("select the output format. Supported formats:\n" ++ intercalate ", " fmts ++ ".") + +outputFileFlag :: Flag RawOpts +outputFileFlag = flagReq + ["output-file","o"] (\s opts -> Right $ setopt "output-file" s opts) "FILE" + "write output to FILE. A file extension matching one of the above formats selects that format." argsFlag :: FlagHelp -> Arg RawOpts argsFlag desc = flagArg (\s opts -> Right $ setopt "args" s opts) desc diff --git a/hledger/Hledger/Cli/Commands/Balance.hs b/hledger/Hledger/Cli/Commands/Balance.hs index a4dfa2444..821647a46 100644 --- a/hledger/Hledger/Cli/Commands/Balance.hs +++ b/hledger/Hledger/Cli/Commands/Balance.hs @@ -295,8 +295,9 @@ balancemode = hledgerCommandMode ,flagNone ["invert"] (setboolopt "invert") "display all amounts with reversed sign" ,flagNone ["transpose"] (setboolopt "transpose") "transpose rows and columns" ,flagNone ["percent", "%"] (setboolopt "percent") "express values in percentage of each column's total" + ,outputFormatFlag ["txt","html","csv","json"] + ,outputFileFlag ] - ++ outputflags ) [generalflagsgroup1] hiddenflags diff --git a/hledger/Hledger/Cli/Commands/Print.hs b/hledger/Hledger/Cli/Commands/Print.hs index ff329455d..ba8698333 100644 --- a/hledger/Hledger/Cli/Commands/Print.hs +++ b/hledger/Hledger/Cli/Commands/Print.hs @@ -39,7 +39,9 @@ printmode = hledgerCommandMode "show all amounts explicitly" ,flagNone ["new"] (setboolopt "new") "show only newer-dated transactions added in each file since last run" - ] ++ outputflags) + ,outputFormatFlag ["txt","csv","json"] + ,outputFileFlag + ]) [generalflagsgroup1] hiddenflags ([], Just $ argsFlag "[QUERY]") diff --git a/hledger/Hledger/Cli/Commands/Register.hs b/hledger/Hledger/Cli/Commands/Register.hs index 897bf0bd9..e8ad2b685 100644 --- a/hledger/Hledger/Cli/Commands/Register.hs +++ b/hledger/Hledger/Cli/Commands/Register.hs @@ -51,7 +51,9 @@ registermode = hledgerCommandMode #endif ++ " or $COLUMNS). -wN,M sets description width as well." ) - ] ++ outputflags) + ,outputFormatFlag ["txt","csv","json"] + ,outputFileFlag + ]) [generalflagsgroup1] hiddenflags ([], Just $ argsFlag "[QUERY]") diff --git a/hledger/Hledger/Cli/CompoundBalanceCommand.hs b/hledger/Hledger/Cli/CompoundBalanceCommand.hs index 2cfd1b620..6f93e3a1d 100644 --- a/hledger/Hledger/Cli/CompoundBalanceCommand.hs +++ b/hledger/Hledger/Cli/CompoundBalanceCommand.hs @@ -108,7 +108,7 @@ compoundBalanceCommandMode CompoundBalanceCommandSpec{..} = ,flagNone ["pretty-tables"] (setboolopt "pretty-tables") "use unicode when displaying tables" ,flagNone ["sort-amount","S"] (setboolopt "sort-amount") "sort by amount instead of account code/name" ,flagNone ["percent", "%"] (setboolopt "percent") "express values in percentage of each column's total" - ,outputFormatFlag + ,outputFormatFlag ["txt","html","csv","json"] ,outputFileFlag ] [generalflagsgroup1] diff --git a/hledger/Hledger/Cli/Utils.hs b/hledger/Hledger/Cli/Utils.hs index 9c48b8184..3185c307e 100644 --- a/hledger/Hledger/Cli/Utils.hs +++ b/hledger/Hledger/Cli/Utils.hs @@ -60,7 +60,7 @@ import Hledger.Utils -- | Standard error message for a bad output format specified with -O/-o. unsupportedOutputFormatError :: String -> String -unsupportedOutputFormatError fmt = "Sorry, output format \""++fmt++"\" is unrecognised or not yet implemented for this report." +unsupportedOutputFormatError fmt = "Sorry, output format \""++fmt++"\" is unrecognised or not yet implemented for this report or report mode." -- | Parse the user's specified journal file(s) as a Journal, maybe apply some -- transformations according to options, and run a hledger command with it.