Changeset 388


Ignore:
Timestamp:
10/02/11 14:02:46 (13 years ago)
Author:
nanardon
Message:
  • return an error on unknown options
File:
1 edited

Legend:

Unmodified
Added
Removed
  • server/trunk/web/lib/Sophie/Controller/Chat/Cmd.pm

    r386 r388  
    7777    local @ARGV = @args; 
    7878 
    79     GetOptions(%{ $options || {} }); 
    80  
    81     return \@ARGV; 
     79    eval { 
     80        # Getopt::Long don't return the error but use warn 
     81        local $SIG{__WARN__} = sub {  
     82            my ($message) = @_; 
     83            chomp($message); 
     84            $c->stash->{xmlrpc} = { 
     85                message => [ $message ] 
     86            }; 
     87        }; 
     88 
     89        GetOptions(%{ $options || {} }) or do { 
     90            $c->stash->{getopt_error} = 1; 
     91        }; 
     92    }; 
     93    if ($@) { 
     94        $c->stash->{getopt_error} = 1; 
     95    } 
     96 
     97    return [ @ARGV ]; 
    8298} 
    8399 
     
    354370        }, @args ]) }; 
    355371 
     372    if ($c->stash->{getopt_error}) { 
     373        return $c->stash->{xmlrpc}; 
     374    } 
     375 
    356376    my $res = $c->forward('/search/tags/name_regexp', $reqspec, $args[0]); 
    357     warn join(' ', @{ $res }); 
    358377    if (!@{ $res }) { 
    359378        return $c->stash->{xmlrpc} = { 
     
    398417            's'   => sub { $reqspec->{src} = 1 }, 
    399418        }, @args ]) }; 
     419    if ($c->stash->{getopt_error}) { 
     420        return $c->stash->{xmlrpc}; 
     421    } 
     422 
    400423    my $res = $c->forward('/search/rpm/description', [ $reqspec, @args ]); 
    401424 
     
    455478            's'   => sub { $reqspec->{src} = 1 }, 
    456479        }, @args ]) }; 
     480    if ($c->stash->{getopt_error}) { 
     481        return $c->stash->{xmlrpc}; 
     482    } 
    457483 
    458484    if (!$c->forward('/distrib/exists', [ $reqspec ])) { 
     
    830856            's'   => sub { $reqspec->{src} = 1 }, 
    831857        }, @args ]) }; 
     858    if ($c->stash->{getopt_error}) { 
     859        return $c->stash->{xmlrpc}; 
     860    } 
    832861 
    833862    @args == 2 or do { 
     
    890919            's'   => sub { $reqspec->{src} = 1 }, 
    891920        }, @args ]) }; 
     921    if ($c->stash->{getopt_error}) { 
     922        return $c->stash->{xmlrpc}; 
     923    } 
    892924 
    893925    if (!$c->forward('/distrib/exists', [ $reqspec ])) { 
     
    942974            'a=s' => \$reqspec->{arch}, 
    943975        }, @args ]) }; 
     976    if ($c->stash->{getopt_error}) { 
     977        return $c->stash->{xmlrpc}; 
     978    } 
     979 
    944980    if (!$c->forward('/distrib/exists', [ $reqspec ])) { 
    945981        return $c->stash->{xmlrpc} = { 
     
    10001036            's'   => \$reqspec->{src}, 
    10011037        }, @args ]) }; 
     1038    if ($c->stash->{getopt_error}) { 
     1039        return $c->stash->{xmlrpc}; 
     1040    } 
    10021041 
    10031042    if (!$c->forward('/distrib/exists', [ $reqspec ])) { 
     
    10581097            's'   => \$reqspec->{src}, 
    10591098        }, @args ]) }; 
     1099    if ($c->stash->{getopt_error}) { 
     1100        return $c->stash->{xmlrpc}; 
     1101    } 
    10601102 
    10611103    my ($type, $depname, $sense, $evr) = @args; 
     
    11071149            's'   => \$reqspec->{src}, 
    11081150        }, @args ]) }; 
     1151    if ($c->stash->{getopt_error}) { 
     1152        return $c->stash->{xmlrpc}; 
     1153    } 
     1154 
    11091155    if (!$c->forward('/distrib/exists', [ $reqspec ])) { 
    11101156        return $c->stash->{xmlrpc} = { 
     
    11581204            'd=s' => \$dist->{distribution}, 
    11591205        }, @args ]) }; 
     1206    if ($c->stash->{getopt_error}) { 
     1207        return $c->stash->{xmlrpc}; 
     1208    } 
     1209 
    11601210    if (!$c->forward('/distrib/exists', [ $dist ])) { 
    11611211        return $c->stash->{xmlrpc} = { 
Note: See TracChangeset for help on using the changeset viewer.