Changeset 825

Show
Ignore:
Timestamp:
02/08/02 20:22:09 (11 years ago)
Author:
bradfitz
Message:

From <lj user=mart>:
Admin Console 'help' command, plus little fixes
http://www.livejournal.com/talkread.bml?journal=lj_dev&itemid=313472

Location:
trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/cgi-bin/console.pl

    r789 r825  
    55# lib: cgi-bin/conban.pl. cgi-bin/conshared.pl 
    66# lib: cgi-bin/consuspend.pl, cgi-bin/confaq.pl 
    7 # lib: cgi-bin/console-local.pl 
     7# lib: cgi-bin/console-local.pl, Text::Wrap 
    88# </LJDEP> 
    99 
     
    1111use strict; 
    1212use vars qw(%cmd); 
     13use Text::Wrap; 
    1314 
    1415sub parse_line 
     
    273274               'command' => "Either 'list' to list friend, 'add' to add a friend, or 'remove' to remove a friend.", 
    274275               'username' => "The username of the person to add or remove when using the add or remove command.", 
    275                'group' => "When using command 'add', tihs 3rd parameter can list the name of a friend group to add the friend to.  The group must already exist.", 
     276               'group' => "When using command 'add', this 3rd parameter can list the name of a friend group to add the friend to.  The group must already exist.", 
    276277               ], 
    277278    }; 
     
    431432    }; 
    432433 
     434$cmd{'help'} = { 
     435    'des' => 'Get help on admin console commands', 
     436    'handler' => \&conhelp, 
     437    'argsummary' => '[<command>]', 
     438    'args' => [ 
     439      'command' => "The command to get help on.  If ommitted, prints a list of commands." 
     440    ], 
     441  }; 
     442 
     443sub conhelp  
     444{ 
     445    my ($dbh, $remote, $args, $out) = @_; 
     446 
     447    $Text::Wrap::columns = 72; 
     448 
     449    my $pr  = sub { foreach (split(/\n/,$_[0])) { 
     450                      push @$out, [ "",      $_ ]; 
     451                    } 1; }; 
     452    my $err = sub { push @$out, [ "error", $_[0] ]; 0; }; 
     453 
     454    my $which = $args->[1]; 
     455    return $err->("Invalid Arguments") if ($#{$args} > 1); 
     456 
     457    unless ($which)  
     458    { 
     459        # Make a command list. 
     460        foreach my $cmdname (sort keys %LJ::Con::cmd) { 
     461            next if ($LJ::Con::cmd{$cmdname}->{'hidden'}); 
     462            my $des = $LJ::Con::cmd{$cmdname}->{'des'}; 
     463            my $indent = length($cmdname)+2; 
     464            my $helptext = Text::Wrap::wrap('',' 'x$indent,"$cmdname: $des"); 
     465            $pr->($helptext); 
     466        } 
     467        return 1; 
     468    }  
     469 
     470    # Help for a specific command 
     471    return $err->("Command '$which' does not exist here.") 
     472        unless defined $LJ::Con::cmd{$which}; 
     473    my $cmd = $LJ::Con::cmd{$which}; 
     474     
     475    $pr->("$which ".$cmd->{'argsummary'}); 
     476    $pr->(wrap('  ','  ',$cmd->{'des'})); 
     477    if ($cmd->{'args'}) { 
     478        $pr->("  --------"); 
     479        my @des = @{$cmd->{'args'}}; 
     480        while (my ($arg, $des) = splice(@des, 0, 2)) { 
     481            $pr->("  $arg"); 
     482            $pr->(wrap('    ','    ',$des)); 
     483        } 
     484    } 
     485    return 1; 
     486} 
    433487 
    434488sub delete_talk 
  • trunk/htdocs/admin/console/index.bml

    r444 r825  
    5555                 }  
    5656                  
    57                  $ret .= "<FONT COLOR=$color>$line->[1]</FONT>\n"; 
     57                 $ret .= "<FONT COLOR=$color>".LJ::eall($line->[1])."</FONT>\n"; 
    5858                  
    5959             }