Changeset 164

Show
Ignore:
Timestamp:
06/22/04 03:54:43 (4 years ago)
Author:
athomas
Message:

Wildcard arguments are almost working.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • manage/trunk/CLI/CLI.pm

    r163 r164  
    101101# node, or undef if not found. 
    102102# 
    103 # parse_node(\@tokens [, $node, \@args]) 
     103# parse_node(\@tokens [, $node, \@args, $trackall]) 
    104104sub parse_node { 
    105105my $self = shift; 
     
    210210                my $key = $rx; 
    211211                my $trackvar = 0; 
     212                my $trackall = 0; 
    212213 
    213214                        # Skip if help 
     
    216217                        # Find out if this candidate is a unique minimum match 
    217218                my $unique = 0; 
    218  
    219                         if (defined($token)) { 
    220                         my @candidates = grep(/^(?:\d+\)(?:\$))?$token/, keys(%cmd)); 
    221  
    222                                 $unique = 1 if @candidates == 1 and $candidates[0] eq $key; 
    223                         } 
    224219 
    225220                        # Remove ordering token 
     
    230225                                $trackvar = 1; 
    231226                                $rx =~ s/^\$//; 
     227                                # Remove wildcard 
     228                                if ($rx =~ /^\*/) { 
     229                                        $trackall = 1; 
     230                                        $rx =~ s/^\*//; 
     231                                } 
     232                        } 
     233 
     234                        if (defined($token)) { 
     235                        my @candidates = grep(/^(?:\d+\)(?:\$))?$token/, keys(%cmd)); 
     236 
     237                                $unique = 1 if @candidates == 1 and $candidates[0] eq $key; 
    232238                        } 
    233239 
     
    239245                                if ($type eq 'HASH') { 
    240246                                        push(@tokens, $token) if $rx eq 'ACTION'; 
    241                                         return $self->parse_node(\@tokens, $cmd{$key}, \@args); 
     247                                        return $self->parse_node(\@tokens, $cmd{$key}, \@args) 
    242248                                } elsif ($type eq 'CODE') { 
    243249                                        # Tokens are still remaining 
     
    245251                                                return ('HELP', "\e[32m\e[1mOK Command is complete.\e[0m\n") 
    246252                                                        if "@tokens" eq '?'; 
    247                                                 return ('ERROR', 'Trailing tokens (possibly missing help?).'); 
     253                                                return ('ERROR', "Trailing tokens: '@tokens' (possibly missing help?).") 
    248254                                        } 
    249255                                        return ('ACTION', $cmd{$key}, \@args); 
  • manage/trunk/manage

    r158 r164  
    1818 
    1919  
     20my $SELF = $0; $SELF =~ s/.*\///; 
    2021my $DEBUG = 0; 
    2122my $BREAK = 0; $SIG{INT} = sub { $BREAK = 1; }; 
     
    2324my @ALTCOLOURS = ("\e[36m", "\e[36m\e[1m"); 
    2425# Global variables 
    25 my $PROMPT = 'manage> '
     26my $PROMPT = "$SELF> "
    2627my $BANNER = ''; 
     28# Plugin path 
    2729my $PLUGINS = './plugins'; 
    2830our %CONF = ( 
     
    237239 
    238240# Initialise terminal and readline 
    239 my $term = new Term::ReadLine('manage'); $term->ornaments(0); 
     241my $term = new Term::ReadLine($SELF); $term->ornaments(0); 
    240242my $termattribs = $term->Attribs; 
    241243# Do command completion 
     
    259261}; 
    260262# Map the ? key to auto-magic help 
    261 $term->add_defun('dns-help', sub { 
     263$term->add_defun('manage-help', sub { 
    262264my ($type, $action, $args) = $CLI->parse($termattribs->{line_buffer} . ' ?'); 
    263265        if ($type eq 'HELP') { 
     
    267269}, ord('?')); 
    268270 
    269 load_config("/etc/manage.conf"); 
    270 load_config("$ENV{HOME}/.managerc"); 
     271load_config("/etc/$SELF.conf"); 
     272load_config("$ENV{HOME}/.{$SELF}rc"); 
    271273 
    272274for my $key (keys %CONF) { 
     
    275277 
    276278END { 
    277         Term::ReadLine::Gnu->WriteHistory("$ENV{HOME}/.managehistory"); 
     279        Term::ReadLine::Gnu->WriteHistory("$ENV{HOME}/.{$SELF}history"); 
    278280        if (!$FATAL) { 
    279281                # Compare original config to current config 
     
    284286                return; 
    285287        COMMIT: info("Committing modified config."); 
    286                 if (open(CONF, ">$ENV{HOME}/.managerc")) { 
     288                if (open(CONF, ">$ENV{HOME}/.{$SELF}rc")) { 
    287289                        foreach my $key (keys %CONF) { 
    288290                                print(CONF "# $CONF{$key}->{help}\n"); 
     
    294296} 
    295297 
    296 Term::ReadLine::Gnu->ReadHistory("$ENV{HOME}/.managehistory"); 
     298Term::ReadLine::Gnu->ReadHistory("$ENV{HOME}/.{$SELF}history"); 
    297299 
    298300