-- | Parsing options for the Convert report from the command line.modulePenny.Cabin.Balance.Convert.Parser(Opts(..),Target(..),SortBy(..),allOptSpecs)whereimportqualifiedControl.Monad.Exception.SynchronousasEximportqualifiedData.TextasXimportqualifiedPenny.Cabin.OptionsasCOimportqualifiedPenny.Cabin.ParsersasPimportqualifiedPenny.LincolnasLimportqualifiedPenny.Copper.ParsecasPcimportqualifiedSystem.Console.MultiArg.CombinatorasCimportqualifiedText.ParsecasParsec-- | Is the target commodity determined by the user or automatically?dataTarget=AutoTarget|ManualTargetL.TodataSortBy=SortByQty|SortByNamederiving(Eq,Show,Ord)-- | Default starting options for the Convert report. After-- considering what is parsed in from the command line and price data,-- a Convert.Opts will be generated.dataOpts=Opts{showZeroBalances::CO.ShowZeroBalances,target::Target,dateTime::L.DateTime,sortOrder::P.SortOrder,sortBy::SortBy}-- | Do not be tempted to change the setup in this module so that the-- individual functions such as parseColor and parseBackground return-- parsers rather than OptSpec. Such an arrangement breaks the correct-- parsing of abbreviated long options.allOptSpecs::[C.OptSpec(Opts->Ex.ExceptionalStringOpts)]allOptSpecs=[fmaptoExcparseZeroBalances,parseCommodity,fmaptoExcparseAuto,parseDate,fmaptoExcparseSort,fmaptoExcparseOrder]wheretoExcf=return.fparseZeroBalances::C.OptSpec(Opts->Opts)parseZeroBalances=fmapfP.zeroBalanceswherefxo=o{showZeroBalances=x}parseCommodity::C.OptSpec(Opts->Ex.ExceptionalStringOpts)parseCommodity=C.OptSpec["commodity"]"c"(C.OneArgf)wherefa1os=caseParsec.parsePc.lvl1Cmdty""(X.packa1)ofLeft_->Ex.throw$"invalid commodity: "++a1Rightg->return$os{target=ManualTarget.L.To$g}parseAuto::C.OptSpec(Opts->Opts)parseAuto=C.OptSpec["auto-commodity"]""(C.NoArgf)wherefos=os{target=AutoTarget}parseDate::C.OptSpec(Opts->Ex.ExceptionalStringOpts)parseDate=C.OptSpec["date"]"d"(C.OneArgf)wherefa1os=caseParsec.parsePc.dateTime""(X.packa1)ofLeft_->Ex.throw$"invalid date: "++a1Rightg->return$os{dateTime=g}parseSort::C.OptSpec(Opts->Opts)parseSort=C.OptSpec["sort"]"s"(C.ChoiceArgls)wherels=[("qty",(\os->os{sortBy=SortByQty})),("name",(\os->os{sortBy=SortByName}))]parseOrder::C.OptSpec(Opts->Opts)parseOrder=fmapfP.orderwherefxo=o{sortOrder=x}