Changeset 2241


Ignore:
Timestamp:
05/10/19 18:24:47 (5 years ago)
Author:
nanardon
Message:

Add --fmt option to list

Location:
trunk/LATMOS-Accounts
Files:
3 edited

Legend:

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

    r2214 r2241  
    128128    $Env->run('query', '-o', $otype, @ARGV); 
    129129} else { 
    130     $Env->run('ls', $otype, @ARGV); 
     130    $Env->run('ls', $otype); 
    131131} 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli.pm

    r2226 r2241  
    4949            }, 
    5050            code => sub { 
    51                 if ($_[1]) { 
    52                     print $OUT map { "$_\n" } $_[0]->base->list_objects($_[1]); 
    53                 } else { 
     51                my $env = shift; 
     52                warn @_; 
     53                my @args = $self->getoption( 
     54                    { 
     55                        'fmt=s'      => \my $fmt, 
     56                        'filefmt=s'  => \my $filefmt, 
     57                    }, @_ 
     58                ); 
     59 
     60                my $otype = $args[0] or do { 
    5461                    print $OUT "Object type missing\n"; 
     62                    return 1; 
     63                }; 
     64 
     65                if ($filefmt){ 
     66                    open(my $hfmt, '<', $filefmt) or die "Cannot open $filefmt\n"; 
     67                    $fmt ||= ''; # avoid undef warning 
     68                    while (<$hfmt>) { 
     69                        chomp($fmt .= $_); 
     70                    } 
     71                    close $hfmt; 
     72                } 
     73 
     74                if ($fmt) { 
     75                    foreach ($env->base->list_objects($otype)) { 
     76                        my $obj = $env->base->get_object($otype, $_) or next; 
     77                        print $OUT $obj->queryformat($fmt); 
     78                    } 
     79                    print $OUT "\n"; 
     80                } else { 
     81                    print $OUT map { "$_\n" } $env->base->list_objects($otype); 
    5582                } 
    5683            }, 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli/Object.pm

    r2226 r2241  
    275275        help => 'list current selected objects', 
    276276        code => sub { 
    277             printf $OUT "%s: %s\n", $_[0]->{_otype}, join(', ', map { $_->id } 
    278             @{$_[0]->{_objects}}); 
     277 
     278            my $env = shift; 
     279            my @args = $self->getoption( 
     280                { 
     281                    'fmt=s'      => \my $fmt, 
     282                    'filefmt=s'  => \my $filefmt, 
     283                }, @_ 
     284            ); 
     285 
     286            if ($filefmt){ 
     287                open(my $hfmt, '<', $filefmt) or die "Cannot open $filefmt\n"; 
     288                $fmt ||= ''; # avoid undef warning 
     289                while (<$hfmt>) { 
     290                    chomp($fmt .= $_); 
     291                } 
     292                close $hfmt; 
     293            } 
     294 
     295            if ($fmt) { 
     296                foreach (@{$env->{_objects}}) { 
     297                    print $OUT $_->queryformat($fmt); 
     298                } 
     299                print $OUT "\n"; 
     300            } else { 
     301                printf $OUT "%s: %s\n", $env->{_otype}, join(', ', map { $_->id } @{$env->{_objects}}); 
     302            } 
    279303        } 
    280304    }); 
Note: See TracChangeset for help on using the changeset viewer.