mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 12:49:34 +00:00
contrib/98_help.pm: added for evaluation
git-svn-id: https://svn.fhem.de/fhem/trunk@8022 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
6a5543ff71
commit
c73d44eb3c
109
fhem/contrib/98_help.pm
Normal file
109
fhem/contrib/98_help.pm
Normal file
@ -0,0 +1,109 @@
|
||||
# $Id$
|
||||
#
|
||||
package main;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub CommandHelp;
|
||||
|
||||
sub help_Initialize($$) {
|
||||
my %hash = ( Fn => "CommandHelp",
|
||||
Hlp => "[<moduleName>],get help (this screen or module dependent docu)" );
|
||||
$cmds{help} = \%hash;
|
||||
}
|
||||
|
||||
sub CommandHelp {
|
||||
my ($cl, $mod) = @_;
|
||||
|
||||
if($mod) {
|
||||
$mod = lc($mod);
|
||||
my %mods;
|
||||
my @modDir = ("FHEM");
|
||||
foreach my $modDir (@modDir) {
|
||||
opendir(DH, $modDir) || die "Cant open $modDir: $!\n";
|
||||
while(my $l = readdir DH) {
|
||||
next if($l !~ m/^\d\d_.*\.pm$/);
|
||||
my $of = $l;
|
||||
$l =~ s/.pm$//;
|
||||
$l =~ s/^[0-9][0-9]_//;
|
||||
$mods{lc($l)} = "$modDir/$of";
|
||||
}
|
||||
}
|
||||
|
||||
return "Module $mod not found" unless defined($mods{$mod});
|
||||
|
||||
my $output = "";
|
||||
my $skip = 1;
|
||||
my ($err,@text) = FileRead({FileName => $mods{$mod}, ForceType => 'file'});
|
||||
return $err if $err;
|
||||
foreach my $l (@text) {
|
||||
if($l =~ m/^=begin html$/) {
|
||||
$skip = 0;
|
||||
} elsif($l =~ m/^=end html$/) {
|
||||
$skip = 1;
|
||||
} elsif(!$skip) {
|
||||
$output .= $l;
|
||||
}
|
||||
}
|
||||
|
||||
if( $cl && $cl->{TYPE} eq 'telnet' ) {
|
||||
$output =~ s/<br>/\n/g;
|
||||
$output =~ s/<br\/>/\n/g;
|
||||
$output =~ s/<\/a>//g;
|
||||
$output =~ s/<a.*>//g;
|
||||
$output =~ s/<ul>/\n/g;
|
||||
$output =~ s/<\/ul>/\n/g;
|
||||
$output =~ s/<li>/-/g;
|
||||
$output =~ s/<\/li>/\n/g;
|
||||
$output =~ s/<code>//g;
|
||||
$output =~ s/<\/code>//g;
|
||||
$output =~ s/</</g;
|
||||
$output =~ s/>/>/g;
|
||||
$output =~ s/<[bui]>/\ /g;
|
||||
$output =~ s/<\/[bui]>/\ /g;
|
||||
$output =~ s/\ \ +/\ /g;
|
||||
$output =~ s/\t+/ /g;
|
||||
$output =~ s/\n\n/\n/g;
|
||||
return $output;
|
||||
}
|
||||
|
||||
return "<html>$output</html>";
|
||||
|
||||
} else {
|
||||
|
||||
my $str = "\n" .
|
||||
"Possible commands:\n\n" .
|
||||
"Command Parameter Description\n" .
|
||||
"-----------------------------------------------\n";
|
||||
|
||||
for my $cmd (sort keys %cmds) {
|
||||
next if(!$cmds{$cmd}{Hlp});
|
||||
next if($cl && $cmds{$cmd}{ClientFilter} &&
|
||||
$cl->{TYPE} !~ m/$cmds{$cmd}{ClientFilter}/);
|
||||
my @a = split(",", $cmds{$cmd}{Hlp}, 2);
|
||||
$str .= sprintf("%-9s %-25s %s\n", $cmd, $a[0], $a[1]);
|
||||
}
|
||||
|
||||
return $str;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
=begin html
|
||||
|
||||
<a name="help"></a>
|
||||
<h3>help</h3>
|
||||
<ul>
|
||||
<code>help [<moduleName>]</code><br/>
|
||||
<br/>
|
||||
<ul>
|
||||
<li>returns a list of available commands, when called without a moduleName</li>
|
||||
<li>returns a module dependent helptext, same as in commandref</li>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
=end html
|
||||
=cut
|
Loading…
Reference in New Issue
Block a user