Changeset 884 for dasscm/trunk/usr/bin
- Timestamp:
- Jun 15, 2010, 11:21:02 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
dasscm/trunk/usr/bin/dasscm
r882 r884 37 37 my $doc_file = "/usr/share/doc/packages/dasscm/dasscm_howto.txt"; 38 38 39 # commands that require write access (and therefore a login)40 # to the repository server41 my @COMMANDS_REQUIRE_WRITE = ( "add", "commit" );42 43 # configuration file44 39 my $config_file = "/etc/dasscm.conf"; 45 40 my $config = get_config($config_file); 41 42 43 44 my %COMMANDS = ( 45 '--help' => 'help', 46 'help' => 'help', 47 'login' => 'login', 48 'init' => 'init', 49 'ls' => 'ls', 50 'update' => 'update', 51 'up' => 'update', 52 'add' => 'add', 53 'commit' => 'commit', 54 'checkin' => 'commit', 55 'ci' => 'commit', 56 'revert' => 'revert', 57 'blame' => 'blame', 58 'diff' => 'diff', 59 'status' => 'status', 60 'st' => 'status', 61 'check' => 'check', 62 'permissions' => 'permissions', 63 'cleanup' => 'cleanup', 64 'complete' => 'complete' 65 ); 66 67 # desc: description (eg. for usage) 68 # params: parameters 69 # CMD 70 # USER 71 # PATH 72 # REPOPATH 73 # require: 74 # WRITE commands that require write access (and therefore a login) 75 my %COMMAND_DEFINITIONS = ( 76 'help' => { 77 'desc' => [], 78 'params' => [ "CMD" ], 79 'function' => \&help, 80 }, 81 'login' => { 82 'desc' => [], 83 'params' => [ "USER" ], 84 'function' => \&login 85 }, 86 'init' => { 87 'desc' => [ "initialize local subversion checkout.", "This is the first thing to do (after configuring $config_file)" ], 88 'params' => [], 89 'function' => \&init 90 }, 91 'ls' => { 92 'desc' => [], 93 'params' => [ "PATH" ], 94 'function' => \&ls 95 }, 96 'update' => { 97 'desc' => [], 98 'params' => [ "PATH" ], 99 'function' => \&update 100 }, 101 'add' => { 102 'desc' => [], 103 'params' => [ "PATH" ], 104 'require' => [ "WRITE" ], 105 'function' => \&add 106 }, 107 'commit' => { 108 'desc' => [], 109 'params' => [ "PATH" ], 110 'require' => [ "WRITE" ], 111 'function' => \&commit 112 }, 113 'revert' => { 114 'desc' => [ "revert local changes back to version from repository" ], 115 'params' => [ "REPOPATH" ], 116 'function' => \&revert 117 }, 118 'blame' => { 119 'desc' => [], 120 'params' => [ "PATH" ], 121 'function' => \&blame 122 }, 123 'diff' => { 124 'desc' => [], 125 'params' => [ "PATH" ], 126 'function' => \&diff 127 }, 128 'status' => { 129 'desc' => [], 130 'params' => [ "PATH" ], 131 'function' => \&status 132 }, 133 'check' => { 134 'desc' => [ "perform Nagios NRPE conform check" ], 135 'params' => [], 136 'function' => \&check 137 }, 138 'permissions' => { 139 'desc' => [], 140 'params' => [], 141 'function' => \&permissions 142 }, 143 'cleanup' => { 144 'desc' => [], 145 'params' => [], 146 'function' => \&cleanup 147 }, 148 'complete' => { 149 'desc' => [ "internally, used for bash completion" ], 150 'params' => [ "CMD" ], 151 'function' => \&complete 152 }, 153 ); 154 155 156 # configuration file 46 157 my $DASSCM_LOCAL_REPOSITORY_BASE; 47 158 my $DASSCM_REPOSITORY_NAME; … … 85 196 print "\n"; 86 197 print "Available subcommands:\n"; 87 print " help <subcommand>\n"; 88 print " init\n"; 89 print " login <username>\n"; 90 print " up <path>\n"; 91 print " ls <path>\n"; 92 print " add <path>\n"; 93 print " commit <path>\n"; 94 print " revert <path>\n"; 95 print " diff <path>\n"; 96 print " status <path>\n"; 97 print " check\n"; 98 print " cleanup\n"; 99 print " permissions\n"; 198 # print " help <subcommand>\n"; 199 # print " init\n"; 200 # print " login <username>\n"; 201 # print " up <path>\n"; 202 # print " ls <path>\n"; 203 # print " add <path>\n"; 204 # print " commit <path>\n"; 205 # print " revert <path>\n"; 206 # print " diff <path>\n"; 207 # print " status <path>\n"; 208 # print " check\n"; 209 # print " cleanup\n"; 210 # print " permissions\n"; 211 foreach my $i (sort keys(%COMMAND_DEFINITIONS)) { 212 print " ", $i, " ", join( " ", get_command_possible_params($i) ), "\n"; 213 foreach my $line ( get_command_desc($i) ) { 214 print " "x20, $line, "\n"; 215 } 216 } 100 217 print "\n"; 101 218 print "If dasscm is not yet configured, read $doc_file\n"; … … 239 356 if ( "$USER" eq "root" ) { 240 357 if ( ( not $DASSCM_USERNAME ) 241 and ( g rep { m|^$command$| } @COMMANDS_REQUIRE_WRITE) )358 and ( get_command_requires_write( $command ) ) ) 242 359 { 243 360 … … 273 390 { 274 391 } 392 393 sub get_command_uniform_name( $ ) 394 { 395 my $command_abbrivation = $_[0]; 396 if( defined($COMMANDS{$command_abbrivation}) ) { 397 return $COMMANDS{$command_abbrivation}; 398 } 399 return; 400 } 401 402 sub get_command_desc( $ ) 403 { 404 my $command = get_command_uniform_name($_[0]); 405 my @desc = (); 406 if( $command && defined($COMMAND_DEFINITIONS{$command}{'desc'}) ) { 407 @desc = @{$COMMAND_DEFINITIONS{$command}{'desc'}}; 408 } 409 return @desc; 410 } 411 412 sub get_command_function( $ ) 413 { 414 my $command = get_command_uniform_name($_[0]); 415 my $func; 416 if( $command && defined($COMMAND_DEFINITIONS{$command}{'function'}) ) { 417 $func = $COMMAND_DEFINITIONS{$command}{'function'}; 418 } 419 return $func; 420 } 421 422 sub get_command_possible_params( $ ) 423 { 424 my $command = get_command_uniform_name($_[0]); 425 my @params = (); 426 if( $command && defined($COMMAND_DEFINITIONS{$command}{'params'}) ) { 427 @params = @{$COMMAND_DEFINITIONS{$command}{'params'}}; 428 } 429 return @params; 430 } 431 432 sub get_command_requirements( $ ) 433 { 434 my $command = get_command_uniform_name($_[0]); 435 my @requirements = (); 436 if( $command && defined($COMMAND_DEFINITIONS{$command}{'require'}) ) { 437 @requirements = @{$COMMAND_DEFINITIONS{$command}{'require'}}; 438 } 439 return @requirements; 440 } 441 442 sub get_command_requires_write( $ ) 443 { 444 return grep( /^WRITE$/, get_command_requirements($_[0]) ); 445 } 446 275 447 276 448 # … … 780 952 # 781 953 # functions 782 783 954 sub help(;@) 784 955 { … … 1339 1510 } 1340 1511 1512 # 1513 # used for bash completion 1514 # prints the next possible command line parameters 1515 # 1516 sub complete(@) 1517 { 1518 use Data::Dumper; 1519 1520 my $number_arguments = @_; 1521 my $input_command = $_[0] || ""; 1522 1523 print "args: $number_arguments\n"; 1524 if ( $number_arguments <= 1 ) { 1525 1526 foreach my $i ( keys %COMMANDS ) { 1527 #print "$i: "; 1528 #print get_command_requires_write( $i ), " "; 1529 $_ = $i; 1530 if( m/^$input_command/ ) { 1531 my $command = get_command_uniform_name($i); 1532 print $command, " "; 1533 print join( ",", get_command_possible_params($i) ) ; 1534 #print " (", get_command_desc( $i ), ") "; 1535 print "\n"; 1536 } 1537 #print "\n"; 1538 } 1539 } else { 1540 my $command = get_command_uniform_name($input_command); 1541 my @params = get_command_possible_params($input_command); 1542 print "params: ", Dumper(@params); 1543 if( defined($params[$number_arguments-2]) && $params[$number_arguments-2] ) { 1544 my $param = $params[$number_arguments-2]; 1545 print "param: $param\n"; 1546 print Dumper($param); 1547 } 1548 } 1549 } 1550 1551 1552 1341 1553 ##################################################################### 1342 1554 # … … 1350 1562 1351 1563 # get subcommand and remove it from @ARGV 1352 $command = $ARGV[0];1564 $command = get_command_uniform_name($ARGV[0]); 1353 1565 shift @ARGV; 1354 1566 … … 1395 1607 # so we can test for it later on more simply 1396 1608 # 1397 $_ = $command; 1398 if (m/^help$/i) { 1399 help(@ARGV); 1400 } elsif (m/^login$/i) { 1401 $command = "login"; 1402 login(@ARGV); 1403 } elsif (m/^init$/i) { 1404 $command = "init"; 1405 init(@ARGV); 1406 } elsif (m/^ls$/i) { 1407 $command = "ls"; 1408 ls(@ARGV); 1409 } elsif ( (m/^update$/i) || (m/^up$/i) ) { 1410 $command = "update"; 1411 update(@ARGV); 1412 } elsif (m/^add$/i) { 1413 $command = "add"; 1414 add(@ARGV); 1415 } elsif ( (m/^commit$/i) || (m/^checkin$/i) || (m/^ci$/i) ) { 1416 $command = "commit"; 1417 commit(@ARGV); 1418 } elsif (m/^revert$/i) { 1419 $command = "revert"; 1420 $return_code = revert(@ARGV); 1421 } elsif (m/^blame$/i) { 1422 $command = "blame"; 1423 blame(@ARGV); 1424 } elsif (m/^diff$/i) { 1425 $command = "diff"; 1426 diff(@ARGV); 1427 } elsif ( (m/^status$/i) || (m/^st$/i) ) { 1428 $command = "status"; 1429 $return_code = status(@ARGV); 1430 } elsif (m/^check$/i) { 1431 $command = "check"; 1432 $return_code = check(); 1433 } elsif (m/^permissions$/i) { 1434 $command = "permissions"; 1435 $return_code = permissions(); 1436 } elsif (m/^cleanup$/i) { 1437 $command = "cleanup"; 1438 cleanup(); 1609 1610 # $_ = $command; 1611 # if (m/^help$/i) { 1612 # help(@ARGV); 1613 # } elsif (m/^login$/i) { 1614 # $command = "login"; 1615 # login(@ARGV); 1616 # } elsif (m/^init$/i) { 1617 # $command = "init"; 1618 # init(@ARGV); 1619 # } elsif (m/^ls$/i) { 1620 # $command = "ls"; 1621 # ls(@ARGV); 1622 # } elsif ( (m/^update$/i) || (m/^up$/i) ) { 1623 # $command = "update"; 1624 # update(@ARGV); 1625 # } elsif (m/^add$/i) { 1626 # $command = "add"; 1627 # add(@ARGV); 1628 # } elsif ( (m/^commit$/i) || (m/^checkin$/i) || (m/^ci$/i) ) { 1629 # $command = "commit"; 1630 # commit(@ARGV); 1631 # } elsif (m/^revert$/i) { 1632 # $command = "revert"; 1633 # $return_code = revert(@ARGV); 1634 # } elsif (m/^blame$/i) { 1635 # $command = "blame"; 1636 # blame(@ARGV); 1637 # } elsif (m/^diff$/i) { 1638 # $command = "diff"; 1639 # diff(@ARGV); 1640 # } elsif ( (m/^status$/i) || (m/^st$/i) ) { 1641 # $command = "status"; 1642 # $return_code = status(@ARGV); 1643 # } elsif (m/^check$/i) { 1644 # $command = "check"; 1645 # $return_code = check(); 1646 # } elsif (m/^permissions$/i) { 1647 # $command = "permissions"; 1648 # $return_code = permissions(); 1649 # } elsif (m/^cleanup$/i) { 1650 # $command = "cleanup"; 1651 # cleanup(); 1652 # } elsif (m/^complete$/i) { 1653 # $command = "complete"; 1654 # $return_code = complete(@ARGV); 1655 1656 if( get_command_function( $command ) ) { 1657 &{get_command_function( $command )}( @ARGV ); 1439 1658 } else { 1440 1659 print "unknown command: $command\n\n";
Note:
See TracChangeset
for help on using the changeset viewer.