Changeset 2399


Ignore:
Timestamp:
06/13/20 18:55:42 (4 years ago)
Author:
nanardon
Message:

la-cli: add | and > feature (act like in shell)

Location:
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli
Files:
2 edited

Legend:

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

    r2397 r2399  
    482482sub term         { $_[0]->Context->Term } 
    483483sub Interractive { $_[0]->Context->Interactive } 
    484 sub print        { shift->Context->print(@_) } 
     484sub print        { shift->Context->print (@_) } 
     485sub printf       { shift->Context->printf(@_) } 
    485486 
    486487sub Top { 
     
    494495} 
    495496 
     497sub _parse_cmd_line { 
     498    my ( $self, $cmdLine ) = @_; 
     499 
     500    my ($op, $shellLine, $internalLine); 
     501 
     502    if ($cmdLine =~ /^(.*?)(?<![\\|])([\|\>])\s*([^\|].*)?$/) { 
     503        $internalLine = $1; 
     504        $op = $2; 
     505        $shellLine = $3; 
     506    } else { 
     507        $internalLine = $cmdLine; 
     508    } 
     509 
     510    return ( $op, $shellLine, shellwords($internalLine) ); 
     511 
     512} 
     513 
    496514=head2 cli 
    497515 
     
    507525    while (1) { 
    508526        $term->Attribs->{completion_function} = sub { 
    509             $self->complete($_[0], shellwords(substr($_[1], 0, $_[2]))); 
     527            my ($Op, $Shell, @args) = $self->_parse_cmd_line(substr($_[1], 0, $_[2])); 
     528            $Op ||= ''; 
     529            my $attribs = $self->Context->Term->Attribs; 
     530            if ($Op eq '>') { 
     531                $term->completion_matches($Shell, $attribs->{'filename_completion_function'}); 
     532            } elsif ($Op eq '|') { 
     533                $term->completion_matches($Shell, $attribs->{'filename_completion_function'}); 
     534            } else  { 
     535                $self->complete($_[0], @args); 
     536            } 
    510537        }; 
    511538        defined (my $line = $term->readline($self->prompt)) or do { 
     
    515542        $_[0]->Context->{_line} = $line; 
    516543        $term->addhistory($line) if ($line =~ /\S/); 
    517         my $res = $self->run(shellwords($line)); 
     544        my ($Op, $Shell, @args) = $self->_parse_cmd_line($line); 
     545        my $Handle; 
     546        if ($Op) { 
     547            open($Handle, "$Op $Shell") or next; 
     548            $self->Context->TempOut($Handle); 
     549        } 
     550        my $res = $self->run(@args); 
     551        if ($Handle) { 
     552            $self->Context->TempOut(undef); 
     553            close($Handle); 
     554        } 
    518555        $self->rollback if (!$self->Context->TransMode); 
    519556        if ($res && $res eq 'EXIT') { $self->print("\n"); return } 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli/Context.pm

    r2397 r2399  
    3737has La => ( is => 'ro' ); 
    3838has Out => ( is => 'ro' ); 
     39has TempOut => ( is => 'rw' ); 
    3940has Interractive => ( is => 'rw', isa => 'Bool', default => 1 ); 
    4041 
     
    6970sub print { 
    7071    my ( $self, @args ) = @_; 
    71     my $out = $self->Out; 
     72    my $out = $self->TempOut || $self->Out; 
    7273 
    7374    print $out @args; 
     
    8081sub printf { 
    8182    my ( $self, $str, @args ) = @_; 
    82     my $out = $self->Out; 
     83    my $out = $self->TempOut || $self->Out; 
    8384 
    8485    printf $out $str, @args; 
Note: See TracChangeset for help on using the changeset viewer.