%Copyright(C)2003DavidRoundy%%Thisprogramisfreesoftware;youcanredistributeitand/ormodify%itunderthetermsoftheGNUGeneralPublicLicenseaspublishedby%theFreeSoftwareFoundation;eitherversion2,or(atyouroption)%anylaterversion.%%Thisprogramisdistributedinthehopethatitwillbeuseful,%butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof%MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe%GNUGeneralPublicLicenseformoredetails.%%YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense%alongwiththisprogram;seethefileCOPYING.Ifnot,writeto%theFreeSoftwareFoundation,Inc.,51FranklinStreet,FifthFloor,%Boston,MA02110-1301,USA.\subsection{darcssetpref}\begin{code}{-# OPTIONS_GHC -cpp #-}{-# LANGUAGE CPP #-}moduleDarcs.Commands.SetPref(setpref)whereimportSystem.Exit(exitWith,ExitCode(..))importControl.Monad(when)importDarcs.Commands(DarcsCommand(..),nodefaults)importDarcs.Arguments(DarcsFlag,working_repo_dir,umask_option)importDarcs.Repository(amInRepository,add_to_pending,withRepoLock,($-))importDarcs.Patch(changepref)importDarcs.Ordered(FL(..))importDarcs.Repository.Prefs(get_prefval,change_prefval,)#include "impossible.h"-- | A list of all valid preferences for @_darcs/prefs/prefs@.valid_pref_data::[(String,String)]-- ^ (name, one line description)valid_pref_data=[("test","a shell command that runs regression tests"),("predist","a shell command to run before `darcs dist'"),("boringfile","the path to a version-controlled boring file"),("binariesfile","the path to a version-controlled binaries file")]valid_prefs::[String]valid_prefs=mapfstvalid_pref_data\end{code}\options{setpref}\haskell{setpref_description}\begin{code}setpref_description::Stringsetpref_description="Set the value of a preference ("++ps++")."whereps=itervalid_prefsiter[x]=xiter[x,y]=x++" or "++yiter(x:xs)=x++", "++(iterxs)iter[]=""-- impossible, but keeps -Wall happysetpref_help::Stringsetpref_help="When working on project with multiple repositories and contributors,\n"++"it is sometimes desirable for a preference to be set consistently\n"++"project-wide. This is achieved by treating a preference set with\n"++"`darcs setpref' as an unrecorded change, which can then be recorded\n"++"and then treated like any other patch.\n"++"\n"++"Valid preferences are:\n"++"\n"++(unlines$mapunwords$map(\(x,y)->[" ",x,"--",y])valid_pref_data)++"\n"++"For example, a project using GNU autotools, with a `make test' target\n"++"to perform regression tests, might enable Darcs' integrated regression\n"++"testing with the following command:\n"++"\n"++" darcs setpref test 'autoconf && ./configure && make && make test'\n"++"\n"++"Note that merging is not currently implemented for preferences: if two\n"++"patches attempt to set the same preference, the last patch applied to\n"++"the repository will always take precedence. This is considered a\n"++"low-priority bug, because preferences are seldom set.\n"setpref::DarcsCommandsetpref=DarcsCommand{command_name="setpref",command_help=setpref_help,command_description=setpref_description,command_extra_args=2,command_extra_arg_help=["<PREF>","<VALUE>"],command_command=setpref_cmd,command_prereq=amInRepository,command_get_arg_possibilities=returnvalid_prefs,command_argdefaults=nodefaults,command_advanced_options=[umask_option],command_basic_options=[working_repo_dir]}setpref_cmd::[DarcsFlag]->[String]->IO()setpref_cmdopts[pref,val]=withRepoLockopts$-\repository->dowhen(' '`elem`pref)$doputStrLn$"'"++pref++"' is not a valid preference name: no spaces allowed!"exitWith$ExitFailure1when(not$pref`elem`valid_prefs)$doputStrLn$"'"++pref++"' is not a valid preference name!"putStrLn$"Try one of: "++unwordsvalid_prefsexitWith$ExitFailure1oval<-get_prefvalprefold<-caseovalofJustv->returnvNothing->return""change_prefvalprefoldvalputStrLn$"Changing value of "++pref++" from '"++old++"' to '"++val++"'"add_to_pendingrepository(changeprefprefoldval:>:NilFL)setpref_cmd__=impossible\end{code}