Changeset 191

Show
Ignore:
Timestamp:
02/07/05 22:21:51 (4 years ago)
Author:
athomas
Message:

Fixed all issues that I could find with the new grouping feature. Subsequently
cleaned up the interface to grouping, it now uses the following format:

Files:

Legend:

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

    r190 r191  
    1313use CLI::Context; 
    1414 
    15 $VERSION = 0.1
     15$VERSION = 0.2
    1616my $BREAK = 0; 
    1717 
     
    124124        my $command = shift; 
    125125        my $type = ref($help); 
    126         my $group = shift() || 'DEFAULT'; 
     126        my $group = shift() || '100'; 
    127127 
    128128                if ($type eq 'ARRAY') { 
    129                         $commands->{$command} = [ $help->[1], $group ]; 
     129                        $commands->{$help->[0]} = [ $help->[1], $group ]; 
    130130                } elsif ($type eq 'HASH') { 
    131131                        for my $k (keys(%$help)) { 
     
    167167 
    168168                        if (ref($cmd->{$key}) eq 'HASH' and $cmd->{$key}->{HELP}) { 
    169                         my $group = "DEFAULT"; 
     169                        my $group = "0"; 
    170170 
    171171                                $group = $1 if $key =~ /(?:\d+\))?(?:{(.*?)})(?:\$(\*)?)?/; 
    172172                                $process_help->($cmd->{$key}->{HELP}, \%commands, $text, $group); 
    173173                        } else { 
    174                                 $commands{$text} = [ '', 'DEFAULT' ]; 
     174                                $commands{$text} = [ '', '100' ]; 
    175175                        } 
    176176                } 
     
    187187                                $process_help->($cmd->{ACTION}->{HELP}, \%commands, '<eol>'); 
    188188                        } elsif ($cmd->{ACTIONHELP}) { 
    189                                 $commands{'<eol>'} = [ $cmd->{ACTIONHELP}, 'DEFAULT' ]; 
     189                                $commands{'<eol>'} = [ $cmd->{ACTIONHELP}, '100' ]; 
    190190                        } elsif ($cmd->{HELP}) { 
    191191                                $process_help->($cmd->{HELP}, \%commands, '<eol>'); 
    192192                        } else { 
    193                                 $commands{'<eol>'} = [ "\e[31m\e[1m(need ACTIONHELP, ACTION->HELP or HELP entry)\e[0m", 'DEFAULT' ]; 
    194                         } 
    195                 } 
    196  
    197                 $commands{'<eol>'} = [ 'Execute command.', 'DEFAULT' ] if $checkpoint and not defined($commands{'<eol>'}) and defined($cmd->{ACTION}); 
     193                                $commands{'<eol>'} = [ "\e[31m\e[1m(need ACTIONHELP, ACTION->HELP or HELP entry)\e[0m", '100' ]; 
     194                        } 
     195                } 
     196 
     197                $commands{'<eol>'} = [ 'Execute command.', '100' ] if $checkpoint and not defined($commands{'<eol>'}) and defined($cmd->{ACTION}); 
    198198 
    199199        my $keywidth = 0; 
     
    204204                $format->leftMargin($keywidth + 2); 
    205205                for my $name (sort { 
     206                        # Same group, do a normal compare 
    206207                        if ($commands{$a}->[1] eq $commands{$b}->[1]) { 
    207208                                if ($a =~ /^\d+$/ and $b =~ /^\d+$/) { 
     
    211212                                } 
    212213                        } else { 
    213                                 $commands{$a}->[1] cmp $commands{$b}->[1]; 
    214                         } 
    215                         } keys(%commands)) { 
    216                         $help .= "\n" if defined($last_group) and $last_group ne $commands{$name}->[1]; 
     214                                if ($commands{$a}->[1] =~ /^\d+\)/ and $commands{$b}->[1] =~ /^\d+\)/) { 
     215                                my ($lhs, $rhs); 
     216                                        $commands{$a}->[1] =~ /^(\d+)\)/; $lhs = $1; 
     217                                        $commands{$b}->[1] =~ /^(\d+)\)/; $rhs = $1; 
     218                                        $lhs <=> $rhs; 
     219                                } else { 
     220                                        $commands{$a}->[1] cmp $commands{$b}->[1]; 
     221                                } 
     222                        } 
     223                } keys(%commands)) { 
     224                        if ((defined($last_group) and $last_group ne $commands{$name}->[1]) or not defined($last_group)) { 
     225                        my $title = $commands{$name}->[1]; 
     226 
     227                                $title =~ s/^\d+(?:\)|$)//; 
     228                                if ($title) { 
     229                                        $help .= "\e[36m$title\e[0m\n" ; 
     230                                } elsif (defined($last_group)) { 
     231                                        $help .= "\n"; 
     232                                } 
     233                        } 
    217234                        if ($commands{$name}) { 
    218235                                $help .= sprintf("  \e[1m%-${keywidth}s\e[0m ", $name) . substr($format->format($commands{$name}->[0]), $keywidth + 2); 
  • manage/trunk/manage

    r189 r191  
    297297entered exactly as shown. Words enclosed in $C{bold}< >$C{normal} are user defined. 
    298298", 
    299         '{zMANAGE}set' => { 
     299        '{9999}set' => { 
    300300                HELP => 'Query/modify settings.', 
    301301                '$[\w.-]+' => { 
     
    368368                }, 
    369369        }, 
    370         '{zMANAGE}history' => { 
     370        '{9999}history' => { 
    371371                clear => { 
    372372                        ACTION => sub { 
     
    385385                HELP => "Display command line history.", 
    386386        }, 
    387         '{zMANAGE}quit|exit' => { 
     387        '{9999}quit|exit' => { 
    388388                HELP => [ 'exit', 'Exit.' ], 
    389389                ACTION => sub { exit; },