-- Copyright (C) 2003 David Roundy---- This program is free software; you can redistribute it and/or modify-- it under the terms of the GNU General Public License as published by-- the Free Software Foundation; either version 2, or (at your option)-- any later version.---- This program is distributed in the hope that it will be useful,-- but WITHOUT ANY WARRANTY; without even the implied warranty of-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-- GNU General Public License for more details.---- You should have received a copy of the GNU General Public License-- along with this program; see the file COPYING. If not, write to-- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,-- Boston, MA 02110-1301, USA.moduleDarcs.ArgumentDefaults(getDefaultFlags)whereimportData.Maybe(listToMaybe,mapMaybe)importDarcs.Arguments(DarcsFlag,atomicOptions,DarcsAtomicOption(..),DarcsOption(..),applyDefaults,arein)importDarcs.Commands(CommandControl(CommandData),commandAlloptions)importDarcs.Commands.Help(commandControlList)importDarcs.Repository.Prefs(getGlobal,getPreflist)getDefaultFlags::String->[DarcsOption]->[DarcsFlag]->IO[DarcsFlag]getDefaultFlagscomcom_optsalready=dorepo_defs<-defaultContent$getPreflist"defaults"global_defs<-defaultContent$getGlobal"defaults"letrepo_flags=getFlagsFromcomcom_optsalreadyrepo_defsglobal_flags=getFlagsFromcomcom_opts(already++repo_flags)global_defsreturn$applyDefaultscom_opts-- hard-coded defaults (respects user preferences)$repo_flags++global_flags-- user preferencesgetFlagsFrom::String->[DarcsOption]->[DarcsFlag]->[(String,String,String)]->[DarcsFlag]getFlagsFromcomcom_optsalreadydefs=options_forcom_defscom_optscom_opts++options_forall_defscom_optsall_optswherecom_defs=filter(\(c,_,_)->c==com)defsall_defs=filter(\(c,_,_)->c=="ALL")defsoptions_fordoao=concatMap(findOptionoaoalready)dall_opts=concatMapget_optscommandControlListget_opts(CommandDatac)=let(o1,o2)=commandAlloptionscino1++o2get_opts_=[]findOption::[DarcsOption]->[DarcsOption]->[DarcsFlag]->(String,String,String)->[DarcsFlag]findOptionoptsall_optsalready(c,f,d)=ifnull$mapMaybechoose_optionall_optsthenerror$"Bad default option: command '"++c++"' has no option '"++f++"'."elseconcat$mapMaybechoose_optionoptswherechoose_atomic_option(DarcsNoArgOption_flso_)|f`elem`fls=ifnulldthenJust[o]elseerror$"Bad default option: '"++f++"' takes no argument, but '"++d++"' argument given."choose_atomic_option(DarcsArgOption_flso__)|f`elem`fls=ifnulldthenerror$"Bad default option: '"++f++"' requires an argument, but no "++"argument given."elseJust[od]choose_atomic_option_=Nothingchoose_optiono|o`arein`already=Just[]|otherwise=listToMaybe$mapMaybechoose_atomic_option$atomicOptionsodefaultContent::IO[String]->IO[(String,String,String)]defaultContent=fmap(mapMaybe(doline.words))wheredoline(c:a:r)=Just(c,drop_dashdasha,unwordsr)doline_=Nothingdrop_dashdash('-':'-':a)=adrop_dashdasha=a