Changeset 843


Ignore:
Timestamp:
03/27/10 19:11:20 (14 years ago)
Author:
nanardon
Message:
  • fix readline completion
  • add a global quit function
File:
1 edited

Legend:

Unmodified
Added
Removed
  • LATMOS-Accounts/bin/la-cli

    r842 r843  
    7676    help => 'ls object_type - list object of type object_type',  
    7777    completion => sub { 
    78         if(!$_[2]) { 
     78        if(!$_[3]) { 
    7979            return grep { /^\Q$_[1]\E/ } $labase->list_supported_objects 
    8080        } else { () } 
     
    136136        code => sub { 
    137137            my ($env, $attr) = @_; 
    138             foreach (@{$env->{_objects}}) { 
    139                 print $OUT sort map { ($_ || '') . "\n" } $_->get_attributes($attr); 
     138            if (!$attr) { 
     139                foreach (@{$env->{_objects}}) { 
     140                    print $OUT $_->dump; 
     141                } 
     142            } else { 
     143                foreach (@{$env->{_objects}}) { 
     144                    print $OUT sort map { ($_ || '') . "\n" } $_->get_attributes($attr); 
     145                } 
    140146            } 
    141147        }, 
     
    155161    my $prompt = $env->prompt; 
    156162     
    157     $attribs->{completion_function} = sub { 
    158         $env->complete($_[0], shellwords(substr($_[1], 0, $_[2]))); 
    159     }; 
    160     while (defined (my $line = $term->readline($prompt))) { 
     163    while (1) { 
     164        $attribs->{completion_function} = sub { 
     165            $env->complete($_[0], shellwords(substr($_[1], 0, $_[2]))); 
     166        }; 
     167        defined (my $line = $term->readline($prompt)) or return; 
    161168        $env->run(shellwords($line)); 
    162169        $labase->rollback; 
     
    174181    my ($class, $env) = @_; 
    175182    bless($env, $class); 
     183    $env->add_func('quit', { help => 'quit - exit the tool', 
     184            code => sub { print "\n"; exit(0) }, }); 
     185    $env; 
    176186} 
    177187 
Note: See TracChangeset for help on using the changeset viewer.