Ignore:
Timestamp:
02/21/19 13:55:28 (5 years ago)
Author:
nanardon
Message:

Add options query like la-query

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli/Base.pm

    r2211 r2212  
    2626 
    2727=head1 FUNCTIONS 
     28 
     29=cut 
     30 
     31=head1 CLI FUNCTIONS 
    2832 
    2933=cut 
     
    162166    }); 
    163167 
    164     $self->add_func( 
    165         'query' => { 
     168    $self->add_func( 'query' => { 
    166169            proxy => '*', 
    167170            help  => 'show attribute', 
     
    169172            code => sub { 
    170173                my $env = shift; 
    171                 my @args = $self->getoption({ 'o|object=s' => \my $otype }, @_); 
     174                my @args = $self->getoption( 
     175                    { 
     176                        'o|object=s' => \my $otype, 
     177                        'e|empty'    => \my $empty_attr, 
     178                        'ro'         => \my $with_ro, 
     179                        'fmt=s'      => \my $fmt, 
     180                        'filefmt=s'  => \my $filefmt, 
     181                    }, @_ 
     182                ); 
    172183                $otype ||= 'user'; 
    173184 
     
    177188                    foreach my $name (@args) { 
    178189                        my $obj = $self->base->get_object( $otype, $name) or do { 
     190                            $self->print("Cannot get object $otype/$name\n"); 
    179191                            next; 
    180192                        }; 
     
    183195                } 
    184196 
     197                if ($filefmt){ 
     198                    open(my $hfmt, '<', $filefmt) or die "Cannot open $filefmt\n"; 
     199                    $fmt ||= ''; # avoid undef warning 
     200                    while (<$hfmt>) { 
     201                        chomp($fmt .= $_); 
     202                    } 
     203                    close $hfmt; 
     204                } 
     205 
    185206                foreach (@{ $objs }) { 
    186                     $self->print($_->dump); 
     207                    if ($fmt) { 
     208                        $self->print($_->queryformat($fmt)); 
     209                    } else { 
     210                        $_->text_dump( $self->Context->Out, { 
     211                            empty_attr => $empty_attr, 
     212                            only_rw => !$with_ro, 
     213                        } ); 
     214                    } 
    187215                } 
    188216            }, 
    189         } 
    190     ); 
     217    } ); 
    191218} 
    192219 
Note: See TracChangeset for help on using the changeset viewer.