Changeset 2214 for trunk


Ignore:
Timestamp:
02/21/19 22:12:58 (5 years ago)
Author:
nanardon
Message:

Merge la-query code into la-cli

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts/bin/la-query

    r1549 r2214  
    77use Pod::Usage; 
    88use LATMOS::Accounts::I18N; 
     9use LATMOS::Accounts::Cli; 
     10use LATMOS::Accounts::Cli::Context; 
    911 
    1012=head1 NAME 
     
    2729=cut 
    2830 
     31Getopt::Long::Configure("pass_through"); 
    2932GetOptions( 
    3033    'c|config=s'        => \my $config, 
    3134    'b|base=s'          => \my $base, 
    3235    'o|object=s'        => \my $otype, 
    33     'e|empty'           => \my $empty_attr, 
    34     'fmt=s'             => \my $fmt, 
    35     'filefmt=s'         => \my $filefmt, 
    36     'ro'                => \my $with_ro, 
    3736    'no-unexp|wo-unexp' => \my $nounexp, 
    3837    'with-unexp'        => \my $unexp, 
     
    120119$labase->unexported($nounexp ? 0 : 1); 
    121120 
    122 unless ($labase->is_supported_object($otype)) { 
    123     die "Unsupported object type `$otype'\n"; 
    124 } 
    125  
    126 if ($filefmt){ 
    127         open(my $hfmt, '<', $filefmt) or die "Cannot open $filefmt\n"; 
    128         $fmt ||= ''; # avoid undef warning 
    129         while (<$hfmt>) { 
    130                 chomp($fmt .= $_); 
    131         } 
    132         close $hfmt; 
    133 } 
     121my $Env = LATMOS::Accounts::Cli->new( 
     122    Context => LATMOS::Accounts::Cli::Context->new( 
     123        base => $labase, 
     124    ), 
     125); 
    134126 
    135127if (@ARGV) { 
    136     foreach my $ouid (@ARGV) { 
    137         my $obj = $labase->get_object($otype, $ouid) or do { 
    138             die "Object $otype $ouid not found\n"; 
    139         }; 
    140         if ($fmt) { 
    141             print $obj->queryformat($fmt); 
    142         } else { 
    143             $obj->text_dump(*STDOUT, 
    144                 { 
    145                     empty_attr => $empty_attr, 
    146                     only_rw => !$with_ro, 
    147                 } 
    148             ); 
    149         } 
    150     } 
     128    $Env->run('query', '-o', $otype, @ARGV); 
    151129} else { 
    152     foreach (sort $labase->list_objects($otype)) { 
    153         if ($fmt) { 
    154             my $o = $labase->get_object($otype, $_) or next; 
    155             print $o->queryformat($fmt); 
    156         } else { 
    157             print "$_\n"; 
    158         } 
    159     } 
     130    $Env->run('ls', $otype, @ARGV); 
    160131} 
Note: See TracChangeset for help on using the changeset viewer.