ctquery 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/perl
  2. # acceptable forms:
  3. # ctquery - list all attached projects and flavors
  4. # ctquery project - list the attached flavor of the named project
  5. # ctquery - flavor - list all attached projects who are attached with a
  6. # given flavor
  7. $projs = $ENV{"CTPROJS"} ;
  8. @projlist = split( / +/, $projs ) ;
  9. if ( $#ARGV == -1 ) {
  10. # list all projects and flavors
  11. print "Currently attached projects (and flavors):\n" ;
  12. foreach $pair ( @projlist ) {
  13. @pairlist = split( /:/, $pair ) ;
  14. ( $pairtmp = $pairlist[0] ) =~ tr/A-Z/a-z/ ;
  15. print " $pairtmp ($pairlist[1])\n" ;
  16. }
  17. } elsif (( $#ARGV == 0 ) && !($ARGV[0] =~ /^\-/)) {
  18. # list the attached flavor of the named project
  19. foreach $pair ( @projlist ) {
  20. @pairlist = split( /:/, $pair ) ;
  21. ( $pairtmp = $pairlist[0] ) =~ tr/A-Z/a-z/ ;
  22. if ( $pairtmp eq $ARGV[0] ) {
  23. print "$pairlist[1]\n" ;
  24. }
  25. }
  26. } elsif (( $#ARGV == 1 ) && ( $ARGV[0] eq "-" )){
  27. # list all attached projects who are attached with a given flavor
  28. foreach $pair ( @projlist ) {
  29. @pairlist = split( /:/, $pair ) ;
  30. if ( $pairlist[1] eq $ARGV[1] ) {
  31. $pairlist[0] =~ tr/A-Z/a-z/ ;
  32. print "$pairlist[0]\n" ;
  33. }
  34. }
  35. } else {
  36. print "Usage: ctquery [project] -or-\n" ;
  37. print " ctquery - flavor\n" ;
  38. exit ;
  39. }