| | 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 | |
| | 443 | sub 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 | } |