Hello
Is it possible to construct selectors that can take into account two
or more variables or conditions, by ANDing or ORing them together?
Eg, I am trying to write a cvsserve component which can optionally
take a username (or connect anonymously) and can also optionally take
a cvs tag name to export. So there would be four different
combinations of cvs command to exec, eg:
cvs -d foohost.com:/cvsroot checkout barproject
cvs -d puppet@foohost.com:/cvsroot checkout barproject
cvs -d foohost.com:/cvsroot export -r REV1.1 barproject
cvs -d puppet@foohost.com:/cvsroot export -r REV1.1 barproject
The component definition would begin something like:
define cvsserve($source, $path, $user = undef, $rev = undef) {
And in psudo-code the component would do something like (being very
simplistic here):
if (($user == undef) and ($rev == undef)) {
$cvscmd = "cvs -d $source checkout $name"
}
if (($user != undef) and ($rev == undef) {
$cvscmd = "cvs -d $user@$source checkout $name"
}
if (($user == undef) and ($rev != undef) {
$cvscmd = "cvs -d $source export -r $rev $name"
}
if (($user != undef) and ($rev != undef) {
$cvscmd = "cvs -d $user@$source export -r $rev $name"
}
Or are there other ways of achieving this? Perhaps:
$cvsroot = $user ? {
undef => "$source",
default => "$user@$source"
}
$cvsaction = $rev ? {
undef => "checkout $name",
default => "export -r $rev $name"
}
$cvscmd = "/usr/bin/cvs -d $cvsroot $cvsaction"
Actually, I think that may just work. Is this a sensible way to go? I
guess it would still be useful to use AND and OR ...
Nb, I came up with this idea after looking at the svnserve example
given in the Components section on the Language Structures page:
http://reductivelabs.com/trac/puppet/wiki/LanguageStructures#Components
Cheers
Jesse