Changeset 2464


Ignore:
Timestamp:
03/24/21 11:55:24 (3 years ago)
Author:
nanardon
Message:

Allow to pipe command to la-cli

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

Legend:

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

    r2459 r2464  
    181181        }, 
    182182    }) if ($self->base->can('find_expired_users')); 
     183 
    183184    $self->add_func('expires', { 
    184185        help => 'expires [delay] - list account expiring before delay (default is 1 month)', 
     
    191192        }, 
    192193    }) if ($self->base->can('find_next_expire_users')); 
    193     $self->add_func('select', { 
     194 
     195    $self->add_func( 
     196        'select', 
     197        { 
    194198            help => 'select object_type - select objects to perform action on it', 
    195199            completion => sub { 
     
    231235                )->cli(); 
    232236            }, 
    233         }); 
     237        } 
     238    ); 
    234239 
    235240=head2 testpass 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli/Base.pm

    r2443 r2464  
    156156=cut 
    157157 
    158     $self->add_func('quit', { 
    159             code => sub { $self->print("\n"); exit(0) }, }); 
     158    $self->add_func( 
     159        'quit',  
     160        { 
     161            code => sub { 
     162                $self->print("\n"); 
     163                $self->_exit(); 
     164                exit(0)  
     165            }, 
     166        } 
     167    ); 
    160168 
    161169=head3 exit 
     
    165173=cut 
    166174 
    167     $self->add_func('exit', { 
    168             code => sub { return "EXIT" }, }); 
     175    $self->add_func( 
     176        'exit', 
     177        { 
     178            code => sub { return "EXIT" }, 
     179        } 
     180    ); 
     181 
     182=head3 top 
     183 
     184Exit from any selection context 
     185 
     186=cut 
     187 
     188    $self->add_func( 
     189        'top', 
     190        { 
     191            code => sub { return "TOP" }, 
     192        } 
     193    ); 
    169194 
    170195=head3 ! 
     
    723748    $self->Context->ReadHistory(); 
    724749    $self->cli(); 
    725     if (! $self->Context->WriteHistory() ) { 
    726         warn "Cannot write history:  $!\n"; 
     750    $self->_exit(); 
     751} 
     752 
     753sub _exit { 
     754    my ( $self ) = @_; 
     755  
     756    if ( -t ) { 
     757        if (! $self->Context->WriteHistory() ) { 
     758            warn "Cannot write history:  $!\n"; 
     759        } 
    727760    } 
    728761    $self->Context->WritePreferences(); 
     
    741774 
    742775    while (1) { 
    743         $term->Attribs->{completion_function} = sub { 
    744             my ($Op, $Shell, @args) = $self->_parse_cmd_line(substr($_[1], 0, $_[2])); 
    745             $Op ||= ''; 
    746             my $attribs = $self->Context->Term->Attribs; 
    747             if ($Op eq '>') { 
    748                 $term->completion_matches($Shell, $attribs->{'filename_completion_function'}); 
    749             } elsif ($Op eq '|') { 
    750                 $term->completion_matches($Shell, $attribs->{'filename_completion_function'}); 
    751             } else  { 
    752                 $self->complete($_[0], @args); 
    753             } 
    754         }; 
     776        if ( -t ) { 
     777            $term->Attribs->{completion_function} = sub { 
     778                my ($Op, $Shell, @args) = $self->_parse_cmd_line(substr($_[1], 0, $_[2])); 
     779                $Op ||= ''; 
     780                my $attribs = $self->Context->Term->Attribs; 
     781                if ($Op eq '>') { 
     782                    $term->completion_matches($Shell, $attribs->{'filename_completion_function'}); 
     783                } elsif ($Op eq '|') { 
     784                    $term->completion_matches($Shell, $attribs->{'filename_completion_function'}); 
     785                } else  { 
     786                    $self->complete($_[0], @args); 
     787                } 
     788            }; 
     789        } 
    755790        defined (my $line = $term->readline($self->prompt)) or do { 
    756791            $self->print("\n"); 
     
    771806        } 
    772807        $self->rollback if (!$self->Context->TransMode); 
    773         if ($res && $res eq 'EXIT') { $self->print("\n"); return } 
     808        if ($res) { 
     809            if ( $res eq 'EXIT' ) { 
     810                $self->print("\n"); 
     811                return 
     812            } elsif ( $res eq 'TOP' ) { 
     813                if ( $self->isa('LATMOS::Accounts::Cli::Object') ) { 
     814                    return 'TOP' 
     815                } else { 
     816                    $self->print("\n"); 
     817                } 
     818            } 
     819        } 
    774820    } 
    775821} 
     
    788834sub prompt { 
    789835    my ($self) = @_; 
     836    if (! -t ) { return '> ' } 
    790837    my $pr = $self->promptPrefix; 
    791838    return sprintf( 
Note: See TracChangeset for help on using the changeset viewer.