Changeset 893
- Timestamp:
- Jun 26, 2010, 2:13:20 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
dasscm/trunk/usr/bin/dasscm
r892 r893 41 41 42 42 my %COMMANDS = ( 43 '--help' => 'help',44 43 'help' => 'help', 45 44 'login' => 'login', … … 105 104 'desc' => [], 106 105 'params' => ["PATH_PROD"], 106 'options' => [ 'verbose', 'message=s' ], 107 107 'require' => ["WRITE"], 108 108 'function' => \&add … … 111 111 'desc' => [], 112 112 'params' => ["PATH_REPO"], 113 'options' => [ 'verbose', 'message=s' ], 113 114 'require' => ["WRITE"], 114 115 'function' => \&commit … … 432 433 } 433 434 435 sub get_command_possible_options( $ ) 436 { 437 my $command = get_command_uniform_name( $_[0] ); 438 my @params = (); 439 if ( $command && defined( $COMMAND_DEFINITIONS{$command}{'options'} ) ) { 440 @params = @{ $COMMAND_DEFINITIONS{$command}{'options'} }; 441 } 442 return @params; 443 } 444 434 445 sub get_command_requirements( $ ) 435 446 { … … 994 1005 sub help(;@) 995 1006 { 996 if ( @_ == 0) {1007 if ( not @_ ) { 997 1008 usage(); 998 1009 } else { 999 print "help for @_: ...\n";1010 print "help for ", join( " ", @_ ), ": ...\n"; 1000 1011 usage(); 1001 1012 } … … 1562 1573 my @input = @_; 1563 1574 1575 # TODO: check global options 1576 1564 1577 if ( $number_arguments <= 1 ) { 1565 1578 1566 1579 # complete dasscm commands 1567 1580 my $input = $input[0] || ""; 1568 foreach my $i ( keys %COMMANDS ) { 1569 $_ = $i; 1570 if (m/^$input/) { 1571 1572 #my $command = get_command_uniform_name($i); 1573 #print $command, "\n"; 1574 print $i, "\n"; 1575 } 1576 } 1581 map { m/^$input/ && print $_, "\n" } ( keys %COMMANDS ); 1577 1582 } else { 1578 1583 … … 1659 1664 my $number_arguments = @ARGV; 1660 1665 1666 # global options 1667 # stops at first non-option 1668 Getopt::Long::Configure( 'require_order' ); 1669 if( not GetOptions( \%options, 'help', 'verbose' ) ) { 1670 usage(); 1671 exit $RETURN_NOK; 1672 } 1673 1674 # set verbose to command line option 1675 $verbose = $options{'verbose'}; 1676 1677 if( $options{'help'} ) { 1678 help(@ARGV); 1679 exit; 1680 } 1681 1661 1682 # get subcommand and remove it from @ARGV 1662 1683 if( defined( $ARGV[0] ) ) { … … 1664 1685 shift @ARGV; 1665 1686 } 1687 1666 1688 if( not defined($command) ) { 1667 1689 usage(); 1668 $return_code = $RETURN_NOK; 1669 } else { 1670 $DASSCM_LOCAL_REPOSITORY_BASE = $config->{'DASSCM_LOCAL_REPOSITORY_BASE'}; 1671 $DASSCM_REPOSITORY_NAME = $config->{'DASSCM_REPOSITORY_NAME'}; 1672 1673 # TODO: check variables 1674 $DASSCM_SVN_REPOSITORY = 1675 $config->{'DASSCM_SVN_REPOSITORY_BASE'} . "/" . $DASSCM_REPOSITORY_NAME; 1676 1677 $DASSCM_CHECKOUT_USERNAME = $config->{'DASSCM_CHECKOUT_USERNAME'}; 1678 $DASSCM_CHECKOUT_PASSWORD = $config->{'DASSCM_CHECKOUT_PASSWORD'}; 1679 1680 # 1681 # if a user is given by dasscm configuration file, we use it. 1682 # Otherwise we expect that read-only account is configured 1683 # as local subversion configuration. 1684 # If this is also not the case, 1685 # user is required to type username and password. 1686 # This will be stored as local subversion configuration thereafter. 1687 # 1688 if ( $DASSCM_CHECKOUT_USERNAME && $DASSCM_CHECKOUT_PASSWORD ) { 1689 $svnCheckoutCredentials = 1690 " --username $DASSCM_CHECKOUT_USERNAME --password $DASSCM_CHECKOUT_PASSWORD "; 1691 } 1692 1693 $DASSCM_PERMISSION_FILE = $config->{'DASSCM_PERMISSION_FILE'} 1694 || "/etc/permissions.d/dasscm.permission_backup"; 1695 1690 exit $RETURN_NOK; 1691 } 1692 1693 $DASSCM_LOCAL_REPOSITORY_BASE = $config->{'DASSCM_LOCAL_REPOSITORY_BASE'}; 1694 $DASSCM_REPOSITORY_NAME = $config->{'DASSCM_REPOSITORY_NAME'}; 1695 1696 # TODO: check variables 1697 $DASSCM_SVN_REPOSITORY = 1698 $config->{'DASSCM_SVN_REPOSITORY_BASE'} . "/" . $DASSCM_REPOSITORY_NAME; 1699 1700 $DASSCM_CHECKOUT_USERNAME = $config->{'DASSCM_CHECKOUT_USERNAME'}; 1701 $DASSCM_CHECKOUT_PASSWORD = $config->{'DASSCM_CHECKOUT_PASSWORD'}; 1702 1703 # 1704 # if a user is given by dasscm configuration file, we use it. 1705 # Otherwise we expect that read-only account is configured 1706 # as local subversion configuration. 1707 # If this is also not the case, 1708 # user is required to type username and password. 1709 # This will be stored as local subversion configuration thereafter. 1710 # 1711 if ( $DASSCM_CHECKOUT_USERNAME && $DASSCM_CHECKOUT_PASSWORD ) { 1712 $svnCheckoutCredentials = 1713 " --username $DASSCM_CHECKOUT_USERNAME --password $DASSCM_CHECKOUT_PASSWORD "; 1714 } 1715 1716 $DASSCM_PERMISSION_FILE = $config->{'DASSCM_PERMISSION_FILE'} 1717 || "/etc/permissions.d/dasscm.permission_backup"; 1718 1719 # check for command options 1720 my @cmd_options = get_command_possible_options( $command ); 1721 if( @cmd_options ) { 1696 1722 # get command line options and store them in options hash 1697 my $result = GetOptions( \%options, 'verbose', 'message=s');1723 my $result = GetOptions( \%options, @cmd_options ); 1698 1724 1699 1725 # print options … … 1701 1727 print "${option}: $options{$option}\n"; 1702 1728 } 1703 1704 # set verbose to command line option 1705 $verbose = $options{'verbose'}; 1706 1707 # 1708 # action accordinly to command are taken 1709 # 1710 &{ get_command_function($command) }(@ARGV); 1711 } 1729 } 1730 1731 # 1732 # action accordinly to command are taken 1733 # 1734 &{ get_command_function($command) }(@ARGV); 1712 1735 1713 1736 exit $return_code;
Note:
See TracChangeset
for help on using the changeset viewer.