Changeset 894 for dasscm/trunk/usr


Ignore:
Timestamp:
Jun 26, 2010, 2:40:09 PM (15 years ago)
Author:
joergs
Message:

complete handles global options

File:
1 edited

Legend:

Unmodified
Added
Removed
  • dasscm/trunk/usr/bin/dasscm

    r893 r894  
    88  qw($DASSCM_PROD $DASSCM_REPO $USER $DASSCM_USERNAME $DASSCM_USER $DASSCM_PASSWORD $SHELL);
    99use Cwd;
    10 use Getopt::Long;
     10use Getopt::Long qw(GetOptionsFromArray);
    1111use File::Basename;
    1212use File::Compare;
     
    1818use Term::ReadKey;
    1919
    20 #use Data::Dumper;
     20use Data::Dumper;
    2121
    2222#####################################################################
     
    3939my $config_file = "/etc/dasscm.conf";
    4040my $config      = get_config($config_file);
     41
     42my @OPTIONS_GLOBAL = ( 'help', 'verbose' );
    4143
    4244my %COMMANDS = (
     
    15681570sub complete(@)
    15691571{
    1570     use Data::Dumper;
    1571 
    1572     my $number_arguments = @_;
    15731572    my @input            = @_;
    1574 
    1575     # TODO: check global options
    1576 
    1577     if ( $number_arguments <= 1 ) {
    1578 
    1579         # complete dasscm commands
    1580         my $input = $input[0] || "";
    1581         map { m/^$input/ && print $_, "\n" } ( keys %COMMANDS );
    1582     } else {
    1583 
    1584         # complete dasscm parameter
    1585         my $command = get_command_uniform_name( $input[0] );
    1586         my @params  = get_command_possible_params( $input[0] );
    1587         if ($verbose) { print "params: ", Dumper(@params); }
    1588 
    1589         # arg 1:    dasscm
    1590         # arg 2:    command
    1591         # arg 3-x:  parameter, therefore parameter_number = $number_arguments - 2
    1592         my $parameter_number = $number_arguments - 2;
    1593         if ( defined( $params[$parameter_number] )
    1594             && $params[$parameter_number] )
    1595         {
    1596             my $param = $params[$parameter_number];
    1597             if ($verbose) { print "param used: ", $param, "\n"; }
    1598             if ( $param eq "PATH_PROD" ) {
    1599                 complete_path( $input[ $number_arguments - 1 ] );
    1600             } elsif ( $param eq "PATH_REPO" ) {
    1601                 complete_repopath( $input[ $number_arguments - 1 ] );
     1573    my %options_complete = ();
     1574
     1575    # check and remove global options. if options are wrong, nothing to do
     1576    if( GetOptionsFromArray( \@input, \%options_complete, @OPTIONS_GLOBAL ) ) {
     1577        my $number_arguments = @input;
     1578        if ( $number_arguments <= 1 ) {
     1579
     1580            # complete dasscm commands
     1581            my $input = $input[0] || "";
     1582            map { m/^$input/ && print $_, "\n" } ( keys %COMMANDS );
     1583        } else {
     1584
     1585            # complete dasscm parameter
     1586            my $command = get_command_uniform_name( $input[0] );
     1587            my @params  = get_command_possible_params( $input[0] );
     1588            if ($verbose) { print "params: ", Dumper(@params); }
     1589
     1590            # arg 1:    dasscm
     1591            # arg 2:    command
     1592            # arg 3-x:  parameter, therefore parameter_number = $number_arguments - 2
     1593            my $parameter_number = $number_arguments - 2;
     1594            if ( defined( $params[$parameter_number] )
     1595                && $params[$parameter_number] )
     1596            {
     1597                my $param = $params[$parameter_number];
     1598                if ($verbose) { print "param used: ", $param, "\n"; }
     1599                if ( $param eq "PATH_PROD" ) {
     1600                    complete_path( $input[ $number_arguments - 1 ] );
     1601                } elsif ( $param eq "PATH_REPO" ) {
     1602                    complete_repopath( $input[ $number_arguments - 1 ] );
     1603                }
    16021604            }
    16031605        }
     
    16671669# stops at first non-option
    16681670Getopt::Long::Configure( 'require_order' );
    1669 if( not GetOptions( \%options, 'help', 'verbose' ) ) {
     1671if( not GetOptions( \%options, @OPTIONS_GLOBAL ) ) {
    16701672    usage();
    16711673    exit $RETURN_NOK;
Note: See TracChangeset for help on using the changeset viewer.